-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intervention image update, deps update
- Loading branch information
Showing
4 changed files
with
46 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
use Intervention\Image\ImageManager; | ||
use Intervention\Image\Drivers\Gd\Driver as GdDriver; | ||
|
||
class Image | ||
{ | ||
/** | ||
* Convert image to webp, jpeg or png format and resize it | ||
*/ | ||
public static function convert(string $source, string $target, int $width = null, int $height = null, string $extension = 'webp', int $quality = 90): void | ||
{ | ||
$manager = new ImageManager(new GdDriver); | ||
|
||
$image = $manager->read($source); | ||
|
||
$maxSize = 1920; | ||
|
||
if ($width && $height) { | ||
$image->cover($width, $height); | ||
} elseif ($width || $image->width() > $maxSize) { | ||
$image->scale(width: $width ?? $maxSize); | ||
} elseif ($height || $image->height() > $maxSize) { | ||
$image->scale(height: $height ?? $maxSize); | ||
} | ||
|
||
if ($extension === 'webp') { | ||
$image->toWebp($quality)->save($target); | ||
} else if ($extension === 'jpeg') { | ||
$image->toJpeg($quality)->save($target); | ||
} else if ($extension === 'png') { | ||
$image->toPng($quality)->save($target); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters