Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F847842
D268.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
Sat, Apr 19, 6:56 PM
Size
2 KB
Mime Type
text/x-diff
Expires
Sun, Apr 20, 6:56 PM (12 m, 18 s)
Engine
blob
Format
Raw Data
Handle
602629
Attached To
D268: INP-1656 - Emulate SVG file resize in "ImageHelper"
D268.diff
View Options
Index: branches/5.2.x/core/units/helpers/image_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/image_helper.php
+++ branches/5.2.x/core/units/helpers/image_helper.php
@@ -112,7 +112,7 @@
throw new RuntimeException(sprintf('Image "%s" doesn\'t exist', $src_image));
}
- if ($params['max_width'] > 0 || $params['max_height'] > 0) {
+ if ( !$this->isSVG($src_image) && ($params['max_width'] > 0 || $params['max_height'] > 0) ) {
list ($params['target_width'], $params['target_height'], $needs_resize) = $this->GetImageDimensions($src_image, $params['max_width'], $params['max_height'], $params);
if (!is_numeric($params['max_width'])) {
@@ -158,8 +158,12 @@
}
}
- if ($image_size) {
- // return only image size (resized or not)
+ if ( $image_size ) {
+ if ( $this->isSVG($src_image) ) {
+ return 'width="' . $params['max_width'] . '" height="' . $params['max_height'] . '"';
+ }
+
+ // Return only image size (resized or not).
$image_info = $this->getImageInfo($src_image);
return $image_info ? $image_info[3] : '';
}
@@ -443,6 +447,11 @@
*/
function GetImageDimensions($src_image, $dst_width, $dst_height, $params)
{
+ // The SVG file is in vector format and can scale to any size.
+ if ( $this->isSVG($src_image) ) {
+ return array($dst_width, $dst_height, false);
+ }
+
$image_info = $this->getImageInfo($src_image);
if (!$image_info) {
return false;
@@ -513,7 +522,7 @@
*/
function getImageInfo($src_image)
{
- if (!file_exists($src_image)) {
+ if ( !file_exists($src_image) || $this->isSVG($src_image) ) {
return false;
}
@@ -527,6 +536,18 @@
}
/**
+ * Checks if image is an SVG file.
+ *
+ * @param string $src_image Full path to source image (already existing).
+ *
+ * @return boolean
+ */
+ protected function isSVG($src_image)
+ {
+ return pathinfo($src_image, PATHINFO_EXTENSION) == 'svg';
+ }
+
+ /**
* Returns maximal image size (width & height) among fields specified
*
* @param kDBItem $object
Event Timeline
Log In to Comment