Page MenuHomeIn-Portal Phabricator

D489.id1255.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 9:00 AM

D489.id1255.diff

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