Skip to content

Commit 2c4cdaa

Browse files
authored
Update ImageResize.php for vertical images
If you want resize your image to a given measure (long side or short side) regardingless the image orientation. (resizeToLongSide and resizeToShortSide)
1 parent d4c41f4 commit 2c4cdaa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/ImageResize.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,54 @@ public function output($image_type = null, $quality = null)
270270
$this->save(null, $image_type, $quality);
271271
}
272272

273+
/**
274+
* Resizes image according to the given short side (short side proportional)
275+
*
276+
* @param integer $max_short
277+
* @param boolean $allow_enlarge
278+
* @return \static
279+
*/
280+
public function resizeToShortSide($max_short, $allow_enlarge = false)
281+
{
282+
if ($this->getSourceHeight() < $this->getSourceWidth()) {
283+
$ratio = $height / $this->getSourceHeight();
284+
$width = $this->getSourceWidth() * $ratio;
285+
286+
$this->resize($width, $height, $allow_enlarge);
287+
} else {
288+
$ratio = $height / $this->getSourceWidth();
289+
$width = $this->getSourceHeight() * $ratio;
290+
291+
$this->resize($width, $height, $allow_enlarge);
292+
}
293+
294+
return $this;
295+
}
296+
297+
/**
298+
* Resizes image according to the given long side (short side proportional)
299+
*
300+
* @param integer $max_long
301+
* @param boolean $allow_enlarge
302+
* @return \static
303+
*/
304+
public function resizeToLongSide($max_long, $allow_enlarge = false)
305+
{
306+
if ($this->getSourceHeight() > $this->getSourceWidth()) {
307+
$ratio = $height / $this->getSourceHeight();
308+
$width = $this->getSourceWidth() * $ratio;
309+
310+
$this->resize($width, $height, $allow_enlarge);
311+
} else {
312+
$ratio = $height / $this->getSourceWidth();
313+
$width = $this->getSourceHeight() * $ratio;
314+
315+
$this->resize($width, $height, $allow_enlarge);
316+
}
317+
318+
return $this;
319+
}
320+
273321
/**
274322
* Resizes image according to the given height (width proportional)
275323
*

0 commit comments

Comments
 (0)