Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14056497
D7610.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7610.diff
View Options
Index: src/applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php
===================================================================
--- src/applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php
+++ src/applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php
@@ -50,9 +50,11 @@
private function getFileOptions($option_string) {
$options = array(
- 'size' => 'thumb',
+ 'size' => null,
'layout' => 'left',
'float' => false,
+ 'width' => null,
+ 'height' => null,
);
if ($option_string) {
@@ -73,23 +75,40 @@
$attrs = array();
$image_class = null;
- switch ((string)$options['size']) {
- case 'full':
+
+ $use_size = true;
+ if (!$options['size']) {
+ $width = $this->parseDimension($options['width']);
+ $height = $this->parseDimension($options['height']);
+ if ($width || $height) {
+ $use_size = false;
$attrs += array(
'src' => $file->getBestURI(),
- 'width' => $file->getImageWidth(),
- 'height' => $file->getImageHeight(),
+ 'width' => $width,
+ 'height' => $height,
);
- break;
- case 'thumb':
- default:
- $attrs['src'] = $file->getPreview220URI();
- $dimensions =
- PhabricatorImageTransformer::getPreviewDimensions($file, 220);
- $attrs['width'] = $dimensions['sdx'];
- $attrs['height'] = $dimensions['sdy'];
- $image_class = 'phabricator-remarkup-embed-image';
- break;
+ }
+ }
+
+ if ($use_size) {
+ switch ((string)$options['size']) {
+ case 'full':
+ $attrs += array(
+ 'src' => $file->getBestURI(),
+ 'width' => $file->getImageWidth(),
+ 'height' => $file->getImageHeight(),
+ );
+ break;
+ case 'thumb':
+ default:
+ $attrs['src'] = $file->getPreview220URI();
+ $dimensions =
+ PhabricatorImageTransformer::getPreviewDimensions($file, 220);
+ $attrs['width'] = $dimensions['sdx'];
+ $attrs['height'] = $dimensions['sdy'];
+ $image_class = 'phabricator-remarkup-embed-image';
+ break;
+ }
}
$img = phutil_tag('img', $attrs);
@@ -186,4 +205,14 @@
->setFileViewable($options['viewable']);
}
+ private function parseDimension($string) {
+ $string = trim($string);
+
+ if (preg_match('/^(?:\d*\\.)?\d+%?$/', $string)) {
+ return $string;
+ }
+
+ return null;
+ }
+
}
Index: src/docs/user/userguide/remarkup.diviner
===================================================================
--- src/docs/user/userguide/remarkup.diviner
+++ src/docs/user/userguide/remarkup.diviner
@@ -345,6 +345,8 @@
- **size** thumb (default), full
- **name** with `layout=link` or for non-images, use this name for the link
text
+ - **width** Scale image to a specific width.
+ - **height** Scale image to a specific height.
== Embedding Countdowns
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 8:43 PM (2 d, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6711118
Default Alt Text
D7610.diff (2 KB)
Attached To
Mode
D7610: Add explicit width/height controls for embedded images in Remarkup
Attached
Detach File
Event Timeline
Log In to Comment