Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803895
D489.id1255.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 9:00 AM
Size
3 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:00 AM (7 h, 35 m)
Engine
blob
Format
Raw Data
Handle
576618
Attached To
D489: INP-1878 - Add support for the WEBP format
D489.id1255.diff
View Options
Index: core/admin_templates/js/uploader/uploader.js
===================================================================
--- core/admin_templates/js/uploader/uploader.js
+++ core/admin_templates/js/uploader/uploader.js
@@ -290,7 +290,7 @@
var $ext = RegExp.$1.toLowerCase();
- return $ext.match(/^(bmp|gif|jpg|jpeg|png)$/);
+ return $ext.match(/^(bmp|gif|jpg|jpeg|png|webp)$/);
};
Uploader.prototype.getFileIcon = function($filename) {
Index: core/units/helpers/image_helper.php
===================================================================
--- core/units/helpers/image_helper.php
+++ core/units/helpers/image_helper.php
@@ -63,9 +63,9 @@
$res['quality'] = $quality;
}
elseif ( preg_match('/^output_format:(.*)$/', $format_part, $regs) ) {
- if ( !in_array($regs[1], array('jpg', 'png', 'gif', 'bmp', 'auto')) ) {
+ if ( !in_array($regs[1], array('jpg', 'png', 'gif', 'bmp', 'webp', 'auto')) ) {
throw new InvalidArgumentException(
- 'Output format value "' . $regs[1] . '" is out of [jpg,png,gif,bmp,auto] range.'
+ 'Output format value "' . $regs[1] . '" is out of [jpg,png,gif,bmp,webp,auto] range.'
);
}
@@ -258,6 +258,7 @@
'image/png' => 'imagecreatefrompng:imagepng:png',
'image/bmp' => 'imagecreatefrombmp:imagejpeg:bmp',
'image/x-ms-bmp' => 'imagecreatefrombmp:imagejpeg:bmp',
+ 'image/webp' => 'imagecreatefromwebp:imagewebp:webp',
);
$mime_type = $image_info['mime'];
@@ -272,6 +273,7 @@
'png' => 'imagepng:png',
'gif' => 'imagegif:gif',
'bmp' => 'imagejpeg:bmp',
+ 'webp' => 'imagewebp:webp',
);
$output_format = $params['output_format'];
@@ -613,9 +615,40 @@
return false;
}
+ // The WEBP polyfill for PHP < 7.1.0, where "getimagesize" function doesn't natively support it.
+ if ( PHP_VERSION_ID < 70100 && $this->isWEBP($src_image) && function_exists('imagecreatefromwebp') ) {
+ $image_rs = imagecreatefromwebp($src_image);
+
+ // Failed to read WEBP image (e.g. animated).
+ if ( $image_rs === false ) {
+ trigger_error(
+ 'Image <b>' . $src_image . '</b> <span class="debug_error"> is invalid</span>',
+ E_USER_WARNING
+ );
+
+ return false;
+ }
+
+ $width = imagesx($image_rs);
+ $height = imagesy($image_rs);
+
+ return array(
+ 0 => $width,
+ 1 => $height,
+ 2 => 18, // Value of "IMAGETYPE_WEBP" constant, that was added in PHP 7.1.
+ 3 => 'height="' . $height . '" width="' . $width . '"',
+ 'mime' => 'image/webp',
+ );
+ }
+
$image_info = @getimagesize($src_image);
- if (!$image_info) {
- trigger_error('Image <b>'.$src_image.'</b> <span class="debug_error">missing or invalid</span>', E_USER_WARNING);
+
+ if ( !$image_info ) {
+ trigger_error(
+ 'Image <b>' . $src_image . '</b> <span class="debug_error">missing or invalid</span>',
+ E_USER_WARNING
+ );
+
return false;
}
@@ -635,6 +668,18 @@
}
/**
+ * Checks if image is an WEBP file.
+ *
+ * @param string $src_image Full path to source image (already existing).
+ *
+ * @return boolean
+ */
+ protected function isWEBP($src_image)
+ {
+ return strtolower(pathinfo(kUtil::removeTempExtension($src_image), PATHINFO_EXTENSION)) == 'webp';
+ }
+
+ /**
* Determines when dimensions must be rotated
*
* @param string $src_image Source image path.
@@ -697,6 +742,7 @@
'image/png' => 'png',
'image/bmp' => 'bmp',
'image/x-ms-bmp' => 'bmp',
+ 'image/webp' => 'webp',
);
$current_mime = $image_info['mime'];
Event Timeline
Log In to Comment