@@ -109,16 +109,41 @@ protected function _thumbnailImage(ImageWithImagineInterface $image, ImagePathIn
109
109
$ image ->deprecateBinaryContent ();
110
110
return true ;
111
111
}
112
-
112
+
113
+ $ formats = (array ) $ format ;
114
+
115
+ $ handlers = [
116
+ [$ this , 'handlerCrop ' ],
117
+ [$ this , 'handlerZoom ' ],
118
+ ];
119
+
120
+ foreach ($ formats as $ format ) {
121
+ $ done = false ;
122
+ foreach ($ handlers as $ handler ) {
123
+ if (call_user_func ($ handler , $ image , $ format )) {
124
+ $ done = true ;
125
+ break ;
126
+ }
127
+ }
128
+ if (!$ done ) {
129
+ throw new ThumbnailRuleException (sprintf ('Unsupported rule format: %s ' , (string )$ format ), ThumbnailRuleException::UNSUPPORTED_RULE_FORMAT );
130
+ }
131
+ }
132
+
133
+ return true ;
134
+ }
135
+
136
+ protected function handlerCrop (ImageWithImagineInterface $ image , $ format )
137
+ {
113
138
if (preg_match ('/^(\<)?([0-9]+)x([0-9]+)$/ ' , $ format , $ matches )) {
114
- $ size = new \Imagine \Image \Box ($ matches [2 ], $ matches [3 ]);
115
- $ mode = $ matches [1 ] == '< ' ? \Imagine \Image \ImageInterface::THUMBNAIL_INSET : \Imagine \Image \ImageInterface::THUMBNAIL_OUTBOUND ;
116
- } elseif (preg_match ('/^(\<)?([0-9]+)$/ ' , $ format , $ matches )) {
117
- $ size = new \Imagine \Image \Box ($ matches [2 ], $ matches [2 ]);
118
- $ mode = $ matches [1 ] == '< ' ? \Imagine \Image \ImageInterface::THUMBNAIL_INSET : \Imagine \Image \ImageInterface::THUMBNAIL_OUTBOUND ;
119
- } else {
120
- throw new ThumbnailRuleException ( sprintf ( ' Unsupported rule format: %s ' , ( string ) $ format ), ThumbnailRuleException:: UNSUPPORTED_RULE_FORMAT ) ;
121
- }
139
+ $ size = new \Imagine \Image \Box ($ matches [2 ], $ matches [3 ]);
140
+ $ mode = $ matches [1 ] == '< ' ? \Imagine \Image \ImageInterface::THUMBNAIL_INSET : \Imagine \Image \ImageInterface::THUMBNAIL_OUTBOUND ;
141
+ } elseif (preg_match ('/^(\<)?([0-9]+)$/ ' , $ format , $ matches )) {
142
+ $ size = new \Imagine \Image \Box ($ matches [2 ], $ matches [2 ]);
143
+ $ mode = $ matches [1 ] == '< ' ? \Imagine \Image \ImageInterface::THUMBNAIL_INSET : \Imagine \Image \ImageInterface::THUMBNAIL_OUTBOUND ;
144
+ } else {
145
+ return false ;
146
+ }
122
147
123
148
/** @var IImage $animated */
124
149
$ animated = null ;
@@ -146,7 +171,22 @@ protected function _thumbnailImage(ImageWithImagineInterface $image, ImagePathIn
146
171
return true ;
147
172
}
148
173
$ image ->setImagineImage ($ image ->getImagineImage ()->thumbnail ($ size , $ mode , $ this ->filter ));
149
- return true ;
174
+ return true ;
175
+ }
176
+
177
+ protected function handlerZoom (ImageWithImagineInterface $ image , $ format )
178
+ {
179
+ if (preg_match ('/^x([0-9]*\.?[0-9]+)$/ ' , $ format , $ matches )) {
180
+ $ scale = floatval ($ matches [1 ]);
181
+ $ size = $ image ->getImagineImage ()->getSize ();
182
+ $ newSize = $ size ->scale ($ scale );
183
+ $ image ->setImagineImage ($ image ->getImagineImage ()->resize ($ newSize )->crop (new \Imagine \Image \Point (
184
+ max (0 , ($ newSize ->getWidth () - $ size ->getWidth ()) / 2 ),
185
+ max (0 , ($ newSize ->getHeight () - $ size ->getHeight ()) / 2 )
186
+ ), $ size ));
187
+ return true ;
188
+ }
189
+ return false ;
150
190
}
151
191
152
192
/**
0 commit comments