Index: trunk/extensions/VipsScaler/VipsScaler.i18n.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | 'vipstest' => 'VIPS scaling test page', |
14 | 14 | |
15 | 15 | 'vipsscaler-desc' => 'Create thumbnails using VIPS', |
16 | | - 'vipsscaler-invalid-file' => 'Invalid file: Could not process requested file. Does it exist on this wiki?', |
| 16 | + 'vipsscaler-invalid-file' => 'Could not process requested file. Check that it exists on this wiki.', |
17 | 17 | 'vipsscaler-invalid-width' => 'You must specify a width (integer > 0).', |
18 | 18 | 'vipsscaler-thumb-error' => 'VIPS could not generate a thumbnail with given parameters.', |
19 | 19 | |
— | — | @@ -20,8 +20,12 @@ |
21 | 21 | 'vipsscaler-form-legend' => 'VIPS scaling', |
22 | 22 | 'vipsscaler-form-width' => 'Thumbnail width:', |
23 | 23 | 'vipsscaler-form-file' => 'File on this wiki:', |
24 | | - 'vipsscaler-form-params' => 'VIPS parameters:', |
| 24 | + 'vipsscaler-form-sharpen-radius' => 'Amount of sharpening:', |
| 25 | + 'vipsscaler-form-bilinear' => 'Bilinear scaling', |
25 | 26 | 'vipsscaler-form-submit' => 'Generate thumbnail', |
| 27 | + |
| 28 | + 'vipsscaler-default-thumb' => 'Thumbnail generated with default scaler', |
| 29 | + 'vipsscaler-vips-thumb' => 'Thumbnail generated with VIPS', |
26 | 30 | |
27 | 31 | # User rights |
28 | 32 | 'right-vipsscaler-test' => 'Use the VIPS scaling test interface [[Special:VipsTest]]', |
— | — | @@ -39,8 +43,11 @@ |
40 | 44 | 'vipsscaler-form-legend' => 'Special:VipsTest form: legend at top of the form', |
41 | 45 | 'vipsscaler-form-width' => 'Special:VipsTest form: label for the width input box', |
42 | 46 | 'vipsscaler-form-file' => 'Special:VipsTest form: label for the file input box', |
43 | | - 'vipsscaler-form-params' => 'Special:VipsTest form: label for the VIPS parameters box', |
44 | 47 | 'vipsscaler-form-submit' => 'Special:VipsTest form: submit button text. The page will then attempt to generate a thumbnail with the given parameters.', |
| 48 | + 'vipsscaler-form-bilinear' => 'Special:VipsTest form: Checkbox label to determine whether to enable bilinear scaling', |
| 49 | + 'vipsscaler-form-sharpen-radius' => 'Special:VipsTest form: label for the sharpening amount input box', |
| 50 | + 'vipsscaler-default-thumb' => 'Special:VipsTest: caption of the default thumbnail', |
| 51 | + 'vipsscaler-vips-thumb' => 'Special:VipsTest: caption of the vips thumbnail', |
45 | 52 | ); |
46 | 53 | |
47 | 54 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | | - if ( $request->getText( 'thumb' ) && $request->getText( 'file' ) ) { |
| 46 | + if ( $request->getText( 'thumb' ) ) { |
47 | 47 | $this->streamThumbnail(); |
48 | 48 | } elseif ( $par || $request->getText( 'file' ) ) { |
49 | 49 | $this->showForm(); |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | protected function showThumbnails() { |
59 | 59 | $request = $this->getRequest(); |
60 | 60 | |
| 61 | + # Check if valid file was provided |
61 | 62 | $title = Title::makeTitleSafe( NS_FILE, $request->getText( 'file' ) ); |
62 | 63 | if ( is_null( $title ) ) { |
63 | 64 | $this->getOutput()->addWikiMsg( 'vipsscaler-invalid-file' ); |
— | — | @@ -68,12 +69,22 @@ |
69 | 70 | return; |
70 | 71 | } |
71 | 72 | |
| 73 | + # Create options |
72 | 74 | $width = $request->getInt( 'width' ); |
73 | 75 | if ( !$width ) { |
74 | 76 | $this->getOutput()->addWikiMsg( 'vipsscaler-invalid-width' ); |
75 | 77 | return; |
76 | 78 | } |
77 | | - |
| 79 | + $vipsUrlOptions = array( 'thumb' => $file->getName(), 'width' => $width ); |
| 80 | + if ( $request->getBool( 'sharpen' ) ) { |
| 81 | + $vipsUrlOptions['sharpen'] = $request->getVal( 'sharpen' ); |
| 82 | + } |
| 83 | + if ( $request->getCheck( 'bilinear' ) ) { |
| 84 | + $vipsUrlOptions['bilinear'] = 1; |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | + # Generate normal thumbnail |
78 | 89 | $params = array( 'width' => $width ); |
79 | 90 | $thumb = $file->transform( $params ); |
80 | 91 | if ( !$thumb || $thumb->isError() ) { |
— | — | @@ -81,21 +92,29 @@ |
82 | 93 | return; |
83 | 94 | } |
84 | 95 | |
85 | | - $this->getOutput()->addHTML( |
86 | | - $thumb->toHtml( array( |
87 | | - # Options for the thumbnail. See ThumbnailImage::toHtml() |
88 | | - 'desc-link' => true, |
89 | | - ) ) |
| 96 | + # Check if we actually scaled the file |
| 97 | + $normalThumbUrl = $thumb->getUrl(); |
| 98 | + if ( wfExpandUrl( $normalThumbUrl ) == $file->getFullUrl() ) { |
| 99 | + // TODO: message |
| 100 | + } |
| 101 | + |
| 102 | + # Make url to the vips thumbnail |
| 103 | + $vipsThumbUrl = $this->getTitle()->getLocalUrl( $vipsUrlOptions ); |
| 104 | + |
| 105 | + # Add to output |
| 106 | + $html = Html::rawElement( 'div', array( 'id' => 'mw-vipstest-thumbnails' ), |
| 107 | + Html::rawElement( 'div', array( 'id' => 'mw-vipstest-default-thumb' ), |
| 108 | + Html::element( 'img', array( 'src' => $normalThumbUrl ) ) . ' ' . |
| 109 | + wfMessage( 'vipsscaler-default-thumb' )->parseAsBlock() |
| 110 | + ) |
| 111 | + . ' ' . |
| 112 | + Html::rawElement( 'div', array( 'id' => 'mw-vipstest-vips-thumb' ), |
| 113 | + Html::element( 'img', array( 'src' => $vipsThumbUrl ) ) . ' ' . |
| 114 | + wfMessage( 'vipsscaler-vips-thumb' )->parseAsBlock() |
| 115 | + ) |
90 | 116 | ); |
91 | 117 | |
92 | | - $vipsThumbUrl = $this->getTitle()->getLocalUrl( array( |
93 | | - 'file' => $file->getName(), |
94 | | - 'thumb' => $file->getHandler()->makeParamString( $params ) |
95 | | - ) ); |
96 | | - |
97 | | - $this->getOutput()->addHTML( |
98 | | - Html::element( 'img', array( 'src' => $vipsThumbUrl ) ) |
99 | | - ); |
| 118 | + $this->getOutput()->addHTML( $html ); |
100 | 119 | } |
101 | 120 | |
102 | 121 | /** |
— | — | @@ -135,14 +154,22 @@ |
136 | 155 | 'name' => 'file', |
137 | 156 | 'class' => 'HTMLTextField', |
138 | 157 | 'required' => true, |
| 158 | + 'size' => '80', |
139 | 159 | 'label-message' => 'vipsscaler-form-file', |
140 | 160 | 'validation-callback' => array( __CLASS__, 'validateFileInput' ), |
141 | 161 | ), |
142 | | - 'Params' => array( |
143 | | - 'name' => 'params', |
144 | | - 'class' => 'HTMLTextField', |
145 | | - 'label-message' => 'vipsscaler-form-params', |
| 162 | + 'SharpenRadius' => array( |
| 163 | + 'name' => 'sharpen', |
| 164 | + 'class' => 'HTMLFloatField', |
| 165 | + 'default' => '0.0', |
| 166 | + 'size' => '5', |
| 167 | + 'label-message' => 'vipsscaler-form-sharpen-radius', |
146 | 168 | ), |
| 169 | + 'Bilinear' => array( |
| 170 | + 'name' => 'bilinear', |
| 171 | + 'class' => 'HTMLCheckField', |
| 172 | + 'label-message' => 'vipsscaler-form-bilinear', |
| 173 | + ), |
147 | 174 | ); |
148 | 175 | return $fields; |
149 | 176 | } |
— | — | @@ -177,7 +204,7 @@ |
178 | 205 | $request = $this->getRequest(); |
179 | 206 | |
180 | 207 | # Validate title and file existance |
181 | | - $title = Title::makeTitleSafe( NS_FILE, $request->getText( 'file' ) ); |
| 208 | + $title = Title::makeTitleSafe( NS_FILE, $request->getText( 'thumb' ) ); |
182 | 209 | if ( is_null( $title ) ) { |
183 | 210 | return $this->streamError( 404 ); |
184 | 211 | } |
— | — | @@ -193,7 +220,7 @@ |
194 | 221 | |
195 | 222 | # Validate param string |
196 | 223 | $handler = $file->getHandler(); |
197 | | - $params = $handler->parseParamString( $request->getText( 'thumb' ) ); |
| 224 | + $params = array( 'width' => $request->getInt( 'width' ) ); |
198 | 225 | if ( !$handler->normaliseParams( $file, $params ) ) { |
199 | 226 | return $this->streamError( 500 ); |
200 | 227 | } |
— | — | @@ -227,11 +254,22 @@ |
228 | 255 | 'dstPath' => $dstPath, |
229 | 256 | 'dstUrl' => $dstUrl, |
230 | 257 | ); |
| 258 | + |
| 259 | + $options = array(); |
| 260 | + if ( $request->getBool( 'bilinear' ) ) { |
| 261 | + $options['bilinear'] = true; |
| 262 | + wfDebug( __METHOD__ . ": using bilinear scaling\n" ); |
| 263 | + } |
| 264 | + if ( $request->getBool( 'sharpen' ) && $request->getInt( 'sharpen' ) < 5 ) { |
| 265 | + # Limit sharpen sigma to 5, otherwise we have to write huge convolution matrices |
| 266 | + $options['sharpen'] = array( 'sigma' => floatval( $request->getVal( 'sharpen' ) ) ); |
| 267 | + wfDebug( __METHOD__ . ": sharpening with radius {$options['sharpen']}\n" ); |
| 268 | + } |
231 | 269 | |
232 | 270 | |
233 | 271 | # Call the hook |
234 | 272 | $mto = null; |
235 | | - VipsScaler::doTransform( $handler, $file, $scalerParams, array(), $mto ); |
| 273 | + VipsScaler::doTransform( $handler, $file, $scalerParams, $options, $mto ); |
236 | 274 | if ( $mto && !$mto->isError() ) { |
237 | 275 | wfDebug( __METHOD__ . ": streaming thumbnail...\n" ); |
238 | 276 | |
Index: trunk/extensions/VipsScaler/README |
— | — | @@ -23,5 +23,5 @@ |
24 | 24 | |
25 | 25 | $wgVipsCommand : path to the vips command (default: vips). |
26 | 26 | |
27 | | -By default everything is scalled using vips. To disable scaling, set |
| 27 | +By default everything is scaled using vips. To disable scaling, set |
28 | 28 | $wgVipsOptions = array(); |