From ad29c986109eed1fd1cf6d2f834044d9ffede7dd Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Sat, 26 Jan 2013 18:59:35 -0800 Subject: [PATCH] Remarkup - add as much image dimension hinting as possible Summary: this was done for conpherence so the auto-scroll actually works. NOTE we actually use the 220 preview UI for file attachments right now so this really only helps in the macro case. :/ Test Plan: sent some conpherences with macros and files. verified image width / height was set as expected. Reviewers: epriestley, chad Reviewed By: chad CC: aran, Korvin Maniphest Tasks: T2399 Differential Revision: https://secure.phabricator.com/D4678 --- .../rule/PhabricatorRemarkupRuleEmbedFile.php | 10 ++++++++++ .../rule/PhabricatorRemarkupRuleImageMacro.php | 17 ++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php index e5113f8240..2317fb5a72 100644 --- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php +++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php @@ -55,10 +55,20 @@ final class PhabricatorRemarkupRuleEmbedFile case 'full': $attrs['src'] = $file->getBestURI(); $options['image_class'] = null; + $file_data = $file->getMetadata(); + $height = $file_data[PhabricatorFile::METADATA_IMAGE_HEIGHT]; + if ($height) { + $attrs['height'] = $height; + } + $width = $file_data[PhabricatorFile::METADATA_IMAGE_WIDTH]; + if ($width) { + $attrs['width'] = $width; + } break; case 'thumb': default: $attrs['src'] = $file->getPreview220URI(); + $attrs['width'] = '220'; $options['image_class'] = 'phabricator-remarkup-embed-image'; break; } diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php index 19ff4b6bf0..66c9b66192 100644 --- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php +++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php @@ -29,10 +29,20 @@ final class PhabricatorRemarkupRuleImageMacro $phid = $this->images[$matches[1]]; $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid); + $style = null; + $src_uri = null; if ($file) { $src_uri = $file->getBestURI(); - } else { - $src_uri = null; + $file_data = $file->getMetadata(); + $height = $file_data[PhabricatorFile::METADATA_IMAGE_HEIGHT]; + $width = $file_data[PhabricatorFile::METADATA_IMAGE_WIDTH]; + if ($height && $width) { + $style = sprintf( + 'height: %dpx; width: %dpx;', + $height, + $width + ); + } } $img = phutil_render_tag( @@ -40,7 +50,8 @@ final class PhabricatorRemarkupRuleImageMacro array( 'src' => $src_uri, 'alt' => $matches[1], - 'title' => $matches[1]), + 'title' => $matches[1], + 'style' => $style), null); return $this->getEngine()->storeText($img); } else {