@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support rendering WebP images

Summary: Closes T16161

Test Plan:
* Go to http://phorge.localhost/file/, upload a WebP image file, see that image is rendered on resulting http://phorge.localhost/F1
* Go to http://phorge.localhost/people/picture/1/, select "Upload New Picture", see that "Supported image formats" text lists webp, upload a WebP image file, see that image is rendered as user avatar on resulting http://phorge.localhost/p/username/
** See that small avatar image in timeline is rendered correctly which means that thumbnailers work
** Inspect the file format of the small avatar image, realize it is also in WebP format and no potential file format conversion took place
* Go to http://phorge.localhost/macro/create/, upload WebP image file, see that it is rendered on resulting http://phorge.localhost/macro/view/1/
** Insert macroname in a comment on a separate line, see the WebP image is rendered in the comment preview
* Insert a new meme in a comment using that WebP macro and setting text, created new meme image is also in WebP file format
* WebP animation and transparency were also tested by patch author

Reviewers: O1 Blessed Committers, aklapper

Reviewed By: O1 Blessed Committers, aklapper

Subscribers: aklapper, mainframe98, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16161

Differential Revision: https://we.phorge.it/D26167

xtex e16a03d2 40aa5162

+43 -1
+31
src/applications/files/PhabricatorImageTransformer.php
··· 34 34 case 'image/png': 35 35 $preferred = self::saveImageDataAsPNG($data); 36 36 break; 37 + case 'image/webp': 38 + $preferred = self::saveImageDataAsWEBP($data); 39 + break; 37 40 } 38 41 39 42 if ($preferred !== null) { ··· 51 54 } 52 55 53 56 $data = self::saveImageDataAsGIF($data); 57 + if ($data !== null) { 58 + return $data; 59 + } 60 + 61 + $data = self::saveImageDataAsWEBP($data); 54 62 if ($data !== null) { 55 63 return $data; 56 64 } ··· 125 133 126 134 ob_start(); 127 135 $result = imagejpeg($image); 136 + $output = ob_get_clean(); 137 + 138 + if (!$result) { 139 + return null; 140 + } 141 + 142 + return $output; 143 + } 144 + 145 + /** 146 + * Save an image in WEBP format, returning the file data as a string. 147 + * 148 + * @param resource $image GD image resource. 149 + * @return string|null WEBP file as a string, or null on failure. 150 + * @task save 151 + */ 152 + private static function saveImageDataAsWEBP($image) { 153 + if (!function_exists('imagewebp')) { 154 + return null; 155 + } 156 + 157 + ob_start(); 158 + $result = imagewebp($image); 128 159 $output = ob_get_clean(); 129 160 130 161 if (!$result) {
+2
src/applications/files/config/PhabricatorFilesConfigOptions.php
··· 25 25 'image/jpg' => 'image/jpg', 26 26 'image/png' => 'image/png', 27 27 'image/gif' => 'image/gif', 28 + 'image/webp' => 'image/webp', 28 29 'text/plain' => 'text/plain; charset=utf-8', 29 30 'text/x-diff' => 'text/plain; charset=utf-8', 30 31 ··· 54 55 'image/jpg' => true, 55 56 'image/png' => true, 56 57 'image/gif' => true, 58 + 'image/webp' => true, 57 59 'image/x-ico' => true, 58 60 'image/x-icon' => true, 59 61 'image/vnd.microsoft.icon' => true,
+2
src/applications/files/constants/FileTypeIcon.php
··· 20 20 break; 21 21 case 'm4v': 22 22 case 'mov': 23 + case 'webm': 23 24 $icon = 'fa-file-movie-o'; 24 25 break; 25 26 case 'sql': ··· 44 45 case 'jpg': 45 46 case 'bmp': 46 47 case 'gif': 48 + case 'webp': 47 49 $icon = 'fa-file-picture-o'; 48 50 break; 49 51 case 'txt':
+1
src/applications/files/document/PhabricatorJupyterDocumentEngine.php
··· 626 626 'image/jpeg', 627 627 'image/jpg', 628 628 'image/gif', 629 + 'image/webp', 629 630 ); 630 631 631 632 foreach ($image_formats as $image_format) {
+7 -1
src/applications/files/storage/PhabricatorFile.php
··· 1027 1027 $ok = false; 1028 1028 if ($this->getViewableMimeType() !== null) { 1029 1029 $ok = preg_match( 1030 - '@^image/(gif|png|jpe?g)@', 1030 + '@^image/(gif|png|jpe?g|webp)@', 1031 1031 $this->getViewableMimeType(), 1032 1032 $matches); 1033 1033 } ··· 1043 1043 return function_exists('imagepng'); 1044 1044 case 'gif': 1045 1045 return function_exists('imagegif'); 1046 + case 'webp': 1047 + return function_exists('imagewebp'); 1046 1048 default: 1047 1049 throw new Exception(pht('Unknown type matched as image MIME type.')); 1048 1050 } ··· 1061 1063 1062 1064 if (function_exists('imagegif')) { 1063 1065 $supported[] = 'gif'; 1066 + } 1067 + 1068 + if (function_exists('imagewebp')) { 1069 + $supported[] = 'webp'; 1064 1070 } 1065 1071 1066 1072 return $supported;