Skip to content

Commit

Permalink
Null as height
Browse files Browse the repository at this point in the history
  • Loading branch information
notesz committed Apr 1, 2018
1 parent 674b4bf commit d8f472a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Add types. The type contains the key, and the image's size.
$image->setType('large', 640, 480);
$image->setType('medium', 320, 240);
$image->setType('thumbnail', 160, 120);
$image->setType('content', 500, null); // You can add 'null' as height. It won't be cropped.
```

Add the source file.
Expand Down
94 changes: 56 additions & 38 deletions src/ImageResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,56 +403,74 @@ public function resize()
$imageRotation = 'square';
}

switch ($imageRotation) {
case 'landscape':
$width = \round($imageWidth/($imageHeight/$imageType['sizeHeight']));
$height = $imageType['sizeHeight'];
if ($imageType['height'] == null) {

if ($width < $imageType['sizeWidth']) {
$width = $imageType['sizeWidth'];
$height = \round($imageHeight/($imageWidth/$imageType['sizeWidth']));
}
$width = $imageType['width'];
$height = \round($imageHeight/($imageWidth/$imageType['width']));

break;
$img->resizeImage(
$width,
$height,
\Imagick::FILTER_LANCZOS,
0.9,
true
);

case 'portrait':
$width = $imageType['sizeWidth'];
$height = \round($imageHeight/($imageWidth/$imageType['sizeWidth']));
} else {

if ($height < $imageType['sizeHeight']) {
switch ($imageRotation) {
case 'landscape':
$width = \round($imageWidth/($imageHeight/$imageType['sizeHeight']));
$height = $imageType['sizeHeight'];
}

break;
if ($width < $imageType['sizeWidth']) {
$width = $imageType['sizeWidth'];
$height = \round($imageHeight/($imageWidth/$imageType['sizeWidth']));
}

case 'square':
$width = $imageType['sizeWidth'];
$height = \round($imageHeight/($imageWidth/$imageType['sizeWidth']));
break;

if ($height < $imageType['sizeHeight']) {
$width = \round($imageWidth/($imageHeight/$imageType['sizeHeight']));
$height = $imageType['sizeHeight'];
}
case 'portrait':
$width = $imageType['sizeWidth'];
$height = \round($imageHeight/($imageWidth/$imageType['sizeWidth']));

if ($height < $imageType['sizeHeight']) {
$width = \round($imageWidth/($imageHeight/$imageType['sizeHeight']));
$height = $imageType['sizeHeight'];
}

break;

case 'square':
$width = $imageType['sizeWidth'];
$height = \round($imageHeight/($imageWidth/$imageType['sizeWidth']));

if ($height < $imageType['sizeHeight']) {
$width = \round($imageWidth/($imageHeight/$imageType['sizeHeight']));
$height = $imageType['sizeHeight'];
}

break;
}

$img->resizeImage(
$width,
$height,
\Imagick::FILTER_LANCZOS,
0.9,
true
);

// Crop the image
$img->cropImage(
$imageType['sizeWidth'],
$imageType['sizeHeight'],
0,
0
);

break;
}

$img->resizeImage(
$width,
$height,
\Imagick::FILTER_LANCZOS,
0.9,
true
);

// Crop the image
$img->cropImage(
$imageType['sizeWidth'],
$imageType['sizeHeight'],
0,
0
);

// Sharpen image
$img->adaptiveSharpenImage(2, 1);
Expand Down

0 comments on commit d8f472a

Please sign in to comment.