@@ -50,9 +50,11 @@ protected function renderObjectEmbed($object, $handle, $options) {
50
50
51
51
private function getFileOptions ($ option_string ) {
52
52
$ options = array (
53
- 'size ' => ' thumb ' ,
53
+ 'size ' => null ,
54
54
'layout ' => 'left ' ,
55
55
'float ' => false ,
56
+ 'width ' => null ,
57
+ 'height ' => null ,
56
58
);
57
59
58
60
if ($ option_string ) {
@@ -73,23 +75,40 @@ private function renderImageFile(
73
75
74
76
$ attrs = array ();
75
77
$ 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 ;
78
85
$ attrs += array (
79
86
'src ' => $ file ->getBestURI (),
80
- 'width ' => $ file -> getImageWidth () ,
81
- 'height ' => $ file -> getImageHeight () ,
87
+ 'width ' => $ width ,
88
+ 'height ' => $ height ,
82
89
);
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
+ }
93
112
}
94
113
95
114
$ img = phutil_tag ('img ' , $ attrs );
@@ -186,4 +205,14 @@ private function renderFileLink(
186
205
->setFileViewable ($ options ['viewable ' ]);
187
206
}
188
207
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
+
189
218
}
0 commit comments