Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added aspect ratio constraint #22

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
11 changes: 10 additions & 1 deletion src/Jasekz/Laradrop/Http/Controllers/LaradropController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ public function store()

$thumbDims = config('laradrop.thumb_dimensions');
$img = Image::make($tmpStorage . '/' . $movedFileName);
$img->resize($thumbDims['width'], $thumbDims['height']);
if(config('laradrop.thumb_aspect')){
$img->resize($thumbDims['width'], null, function ($constraint) {
$constraint->aspectRatio();
});
}
else
{
$img->resize($thumbDims['width'], $thumbDims['height']);
}

$img->save($tmpStorage . '/_thumb_' . $movedFileName);

// move thumbnail to final location
Expand Down
3 changes: 3 additions & 0 deletions src/Jasekz/Laradrop/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

// dimensions for thumbnail generator
'thumb_dimensions' => ['width' => env('LARADROP_THUMB_WIDTH', 150), 'height' => env('LARADROP_THUMB_HEIGHT', 150)],

// when true, the thumbnail sizes will be based solely on the width set above
'thumb_aspect' => env('LARADROP_THUMB_ASPECT', true),

// default thumbnail (if one can not be generated)
'default_thumbnail_url' => env('LARADROP_DEFAULT_THUMB', '/vendor/jasekz/laradrop/img/genericThumbs/no-thumb.png'),
Expand Down