@@ -156,22 +156,22 @@ public function output($image_type = null, $quality = null)
156
156
$ this ->save (null , $ image_type , $ quality );
157
157
}
158
158
159
- public function resizeToHeight ($ height )
159
+ public function resizeToHeight ($ height, $ allow_enlarge = false )
160
160
{
161
161
$ ratio = $ height / $ this ->getSourceHeight ();
162
162
$ width = $ this ->getSourceWidth () * $ ratio ;
163
163
164
- $ this ->resize ($ width , $ height );
164
+ $ this ->resize ($ width , $ height, $ allow_enlarge );
165
165
166
166
return $ this ;
167
167
}
168
168
169
- public function resizeToWidth ($ width )
169
+ public function resizeToWidth ($ width, $ allow_enlarge = false )
170
170
{
171
171
$ ratio = $ width / $ this ->getSourceWidth ();
172
172
$ height = $ this ->getSourceHeight () * $ ratio ;
173
173
174
- $ this ->resize ($ width , $ height );
174
+ $ this ->resize ($ width , $ height, $ allow_enlarge );
175
175
176
176
return $ this ;
177
177
}
@@ -189,6 +189,10 @@ public function scale($scale)
189
189
public function resize ($ width , $ height , $ allow_enlarge = false )
190
190
{
191
191
if (!$ allow_enlarge ) {
192
+ // if the user hasn't explicitly allowed enlarging,
193
+ // but either of the dimensions are larger then the original,
194
+ // then just use original dimensions - this logic may need rethinking
195
+
192
196
if ($ width > $ this ->getSourceWidth () || $ height > $ this ->getSourceHeight ()) {
193
197
$ width = $ this ->getSourceWidth ();
194
198
$ height = $ this ->getSourceHeight ();
@@ -210,8 +214,15 @@ public function resize($width, $height, $allow_enlarge = false)
210
214
public function crop ($ width , $ height , $ allow_enlarge = false )
211
215
{
212
216
if (!$ allow_enlarge ) {
213
- if ($ width > $ this ->getSourceWidth () || $ height > $ this ->getSourceHeight ()) {
217
+ // this logic is slightly different to resize(),
218
+ // it will only reset dimensions to the original
219
+ // if that particular dimenstion is larger
220
+
221
+ if ($ width > $ this ->getSourceWidth ()) {
214
222
$ width = $ this ->getSourceWidth ();
223
+ }
224
+
225
+ if ($ height > $ this ->getSourceHeight ()) {
215
226
$ height = $ this ->getSourceHeight ();
216
227
}
217
228
}
@@ -220,7 +231,7 @@ public function crop($width, $height, $allow_enlarge = false)
220
231
$ ratio_dest = $ width / $ height ;
221
232
222
233
if ($ ratio_dest < $ ratio_source ) {
223
- $ this ->resizeToHeight ($ height );
234
+ $ this ->resizeToHeight ($ height, $ allow_enlarge );
224
235
225
236
$ excess_width = ($ this ->getDestWidth () - $ width ) / $ this ->getDestWidth () * $ this ->getSourceWidth ();
226
237
@@ -229,7 +240,7 @@ public function crop($width, $height, $allow_enlarge = false)
229
240
230
241
$ this ->dest_w = $ width ;
231
242
} else {
232
- $ this ->resizeToWidth ($ width );
243
+ $ this ->resizeToWidth ($ width, $ allow_enlarge );
233
244
234
245
$ excess_height = ($ this ->getDestHeight () - $ height ) / $ this ->getDestHeight () * $ this ->getSourceHeight ();
235
246
0 commit comments