Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #226 from developerbmw/patch
Browse files Browse the repository at this point in the history
Add fill option to image resizer
  • Loading branch information
cuneytsenturk committed Oct 23, 2015
2 parents 101ddee + 9a54950 commit 7aa3bea
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions catalog/model/tool/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

class ModelToolImage extends Model {
public function resize($filename, $width, $height) {
public function resize($filename, $width, $height, $fill = false) {
if (!is_file(DIR_IMAGE . $filename)) {
return;
}
Expand All @@ -33,8 +33,14 @@ public function resize($filename, $width, $height) {
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);

if ($width_orig != $width || $height_orig != $height) {
if ($fill) {
$dimension = $width_orig > $height_orig ? 'h' : 'w';
} else {
$dimension = '';
}

$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->resize($width, $height, $dimension);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
Expand Down

0 comments on commit 7aa3bea

Please sign in to comment.