Skip to content

Commit 96fc9d2

Browse files
committed
Resize Regardless Orientation
Replace variables
1 parent 2c4cdaa commit 96fc9d2

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

lib/ImageResize.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ public function output($image_type = null, $quality = null)
280280
public function resizeToShortSide($max_short, $allow_enlarge = false)
281281
{
282282
if ($this->getSourceHeight() < $this->getSourceWidth()) {
283-
$ratio = $height / $this->getSourceHeight();
283+
$ratio = $max_short / $this->getSourceHeight();
284284
$width = $this->getSourceWidth() * $ratio;
285285

286-
$this->resize($width, $height, $allow_enlarge);
286+
$this->resize($width, $max_short, $allow_enlarge);
287287
} else {
288-
$ratio = $height / $this->getSourceWidth();
288+
$ratio = $max_short / $this->getSourceWidth();
289289
$width = $this->getSourceHeight() * $ratio;
290290

291-
$this->resize($width, $height, $allow_enlarge);
291+
$this->resize($width, $max_short, $allow_enlarge);
292292
}
293293

294294
return $this;
@@ -304,15 +304,15 @@ public function resizeToShortSide($max_short, $allow_enlarge = false)
304304
public function resizeToLongSide($max_long, $allow_enlarge = false)
305305
{
306306
if ($this->getSourceHeight() > $this->getSourceWidth()) {
307-
$ratio = $height / $this->getSourceHeight();
307+
$ratio = $max_long / $this->getSourceHeight();
308308
$width = $this->getSourceWidth() * $ratio;
309309

310-
$this->resize($width, $height, $allow_enlarge);
310+
$this->resize($width, $max_long, $allow_enlarge);
311311
} else {
312-
$ratio = $height / $this->getSourceWidth();
312+
$ratio = $max_long / $this->getSourceWidth();
313313
$width = $this->getSourceHeight() * $ratio;
314314

315-
$this->resize($width, $height, $allow_enlarge);
315+
$this->resize($width, $max_long, $allow_enlarge);
316316
}
317317

318318
return $this;

test/Test.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ public function testInvalidString()
121121
* Resize tests
122122
*/
123123

124+
public function testResizeToLongSide()
125+
{
126+
$image = $this->createImage(200, 100, 'png');
127+
$resize = new ImageResize($image);
128+
129+
$resize->resizeToLongSide(100);
130+
131+
$this->assertEquals(100, $resize->getDestWidth());
132+
$this->assertEquals(50, $resize->getDestHeight());
133+
}
134+
135+
public function testResizeToShortSide()
136+
{
137+
$image = $this->createImage(200, 100, 'png');
138+
$resize = new ImageResize($image);
139+
140+
$resize->resizeToShortSide(50);
141+
142+
$this->assertEquals(100, $resize->getDestWidth());
143+
$this->assertEquals(50, $resize->getDestHeight());
144+
}
145+
124146
public function testResizeToHeight()
125147
{
126148
$image = $this->createImage(200, 100, 'png');

0 commit comments

Comments
 (0)