Skip to content

Commit ab64ad1

Browse files
author
epriestley
committed
Add explicit width/height controls for embedded images in Remarkup
Summary: User request. See screenshot. Test Plan: doge Reviewers: btrahan, bigo Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7610
1 parent ccfce7c commit ab64ad1

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

src/applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ protected function renderObjectEmbed($object, $handle, $options) {
5050

5151
private function getFileOptions($option_string) {
5252
$options = array(
53-
'size' => 'thumb',
53+
'size' => null,
5454
'layout' => 'left',
5555
'float' => false,
56+
'width' => null,
57+
'height' => null,
5658
);
5759

5860
if ($option_string) {
@@ -73,23 +75,40 @@ private function renderImageFile(
7375

7476
$attrs = array();
7577
$image_class = null;
76-
switch ((string)$options['size']) {
77-
case 'full':
78+
79+
$use_size = true;
80+
if (!$options['size']) {
81+
$width = $this->parseDimension($options['width']);
82+
$height = $this->parseDimension($options['height']);
83+
if ($width || $height) {
84+
$use_size = false;
7885
$attrs += array(
7986
'src' => $file->getBestURI(),
80-
'width' => $file->getImageWidth(),
81-
'height' => $file->getImageHeight(),
87+
'width' => $width,
88+
'height' => $height,
8289
);
83-
break;
84-
case 'thumb':
85-
default:
86-
$attrs['src'] = $file->getPreview220URI();
87-
$dimensions =
88-
PhabricatorImageTransformer::getPreviewDimensions($file, 220);
89-
$attrs['width'] = $dimensions['sdx'];
90-
$attrs['height'] = $dimensions['sdy'];
91-
$image_class = 'phabricator-remarkup-embed-image';
92-
break;
90+
}
91+
}
92+
93+
if ($use_size) {
94+
switch ((string)$options['size']) {
95+
case 'full':
96+
$attrs += array(
97+
'src' => $file->getBestURI(),
98+
'width' => $file->getImageWidth(),
99+
'height' => $file->getImageHeight(),
100+
);
101+
break;
102+
case 'thumb':
103+
default:
104+
$attrs['src'] = $file->getPreview220URI();
105+
$dimensions =
106+
PhabricatorImageTransformer::getPreviewDimensions($file, 220);
107+
$attrs['width'] = $dimensions['sdx'];
108+
$attrs['height'] = $dimensions['sdy'];
109+
$image_class = 'phabricator-remarkup-embed-image';
110+
break;
111+
}
93112
}
94113

95114
$img = phutil_tag('img', $attrs);
@@ -186,4 +205,14 @@ private function renderFileLink(
186205
->setFileViewable($options['viewable']);
187206
}
188207

208+
private function parseDimension($string) {
209+
$string = trim($string);
210+
211+
if (preg_match('/^(?:\d*\\.)?\d+%?$/', $string)) {
212+
return $string;
213+
}
214+
215+
return null;
216+
}
217+
189218
}

src/docs/user/userguide/remarkup.diviner

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ Valid options are:
345345
- **size** thumb (default), full
346346
- **name** with `layout=link` or for non-images, use this name for the link
347347
text
348+
- **width** Scale image to a specific width.
349+
- **height** Scale image to a specific height.
348350

349351
== Embedding Countdowns
350352

0 commit comments

Comments
 (0)