Browse Source

make_thumbnail: add basic webp support

Andrew Dolgov 5 months ago
parent
commit
7ee823c717
2 changed files with 13 additions and 3 deletions
  1. 1 1
      backend.php
  2. 12 2
      include/functions.php

+ 1 - 1
backend.php

@@ -1123,7 +1123,7 @@
 					if (defined('_FFMPEG_THUMBNAILS') && _FFMPEG_THUMBNAILS && $is_video)
 						$data = ffmpeg_thumbnail($data);
 
-					$data = make_thumbnail($data, $resize, $resize, $force_stamp || $is_video);
+					$data = make_thumbnail($data, $resize, $resize, $force_stamp || $is_video, $resp_ctype);
 				}
 
 				if (@file_put_contents($cache_key, $data)) {

+ 12 - 2
include/functions.php

@@ -2168,9 +2168,19 @@
 		}
 	}
 
-	function make_thumbnail($data, $dim_max_x = 600, $dim_max_y = 600, $force_stamp = false) {
+	function make_thumbnail($data, $dim_max_x = 600, $dim_max_y = 600, $force_stamp = false, $content_type = false) {
 
-		$o_im = @imagecreatefromstring($data);
+		if ($content_type == "image/webp") {
+			$tmpfname = tempnam("/tmp", "ttirc-thumb");
+			if ($tmpfname) {
+				if (file_put_contents($tmpfname, $data)) {
+					$o_im = @imagecreatefromwebp($tmpfname);
+				}
+				@unlink($tmpfname);
+			}
+		} else {
+			$o_im = @imagecreatefromstring($data);
+		}
 
 		if ($o_im) {
 			$imageinfo = @getimagesizefromstring($data);