@@ -115,6 +115,7 @@ protected function _thumbnailImage(ImageWithImagineInterface $image, ImagePathIn
115
115
$ handlers = [
116
116
[$ this , 'handlerCrop ' ],
117
117
[$ this , 'handlerZoom ' ],
118
+ [$ this , 'handlerCropCanvas ' ],
118
119
];
119
120
120
121
foreach ($ formats as $ format ) {
@@ -188,6 +189,49 @@ protected function handlerZoom(ImageWithImagineInterface $image, $format)
188
189
}
189
190
return false ;
190
191
}
192
+
193
+ protected function handlerCropCanvas (ImageWithImagineInterface $ image , $ format )
194
+ {
195
+ $ size = null ;
196
+ $ width = $ height = 0 ;
197
+ $ pp = false ;
198
+ if (preg_match ('/^\=([0-9]+)([%]?)x([0-9]+)([%]?)$/ ' , $ format , $ matches )) {
199
+ $ width = $ matches [1 ];
200
+ $ height = $ matches [3 ];
201
+ if ($ matches [2 ] == '% ' ) {
202
+ $ width = $ image ->getImagineImage ()->getSize ()->getWidth () * $ width / 100 ;
203
+ }
204
+ if ($ matches [4 ] == '% ' ) {
205
+ $ height = $ image ->getImagineImage ()->getSize ()->getHeight () * $ height / 100 ;
206
+ }
207
+ } elseif (preg_match ('/^\=([0-9]+)([%]?)$/ ' , $ format , $ matches )) {
208
+ $ width = $ height = $ matches [1 ];
209
+ if ($ matches [2 ] == '% ' ) {
210
+ $ width = $ image ->getImagineImage ()->getSize ()->getWidth () * $ width / 100 ;
211
+ $ height = $ image ->getImagineImage ()->getSize ()->getHeight () * $ height / 100 ;
212
+ }
213
+ }
214
+
215
+ if ($ width > 0 && $ height > 0 ) {
216
+ $ size = new \Imagine \Image \Box ($ width , $ height );
217
+ // print_r([
218
+ // 'ori_width' => $image->getImagineImage()->getSize()->getWidth(),
219
+ // 'ori_height' => $image->getImagineImage()->getSize()->getHeight(),
220
+ // 'width' => $width,
221
+ // 'height' => $height,
222
+ // 'x' => ($image->getImagineImage()->getSize()->getWidth() - $size->getWidth()) / 2,
223
+ // 'y' => ($image->getImagineImage()->getSize()->getHeight() - $size->getHeight()) / 2,
224
+ // ]); die();
225
+ $ image ->setImagineImage ($ image ->getImagineImage ()->crop (new \Imagine \Image \Point (
226
+ ($ image ->getImagineImage ()->getSize ()->getWidth () - $ size ->getWidth ()) / 2 ,
227
+ ($ image ->getImagineImage ()->getSize ()->getHeight () - $ size ->getHeight ()) / 2
228
+ ), $ size ));
229
+ $ image ->deprecateBinaryContent ();
230
+ return true ;
231
+ }
232
+
233
+ return false ;
234
+ }
191
235
192
236
/**
193
237
* @throws ImageException
0 commit comments