30 lines
675 B
PHP
30 lines
675 B
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use Intervention\Image\Facades\Image as Image;
|
|
|
|
|
|
class Compress
|
|
{
|
|
public static function resize($path, $width = 400, $height = 320)
|
|
{
|
|
/// get size
|
|
list($width_orig, $height_orig) = getimagesize($path);
|
|
|
|
$ratio_orig = $width_orig / $height_orig;
|
|
|
|
if ($width / $height > $ratio_orig) {
|
|
$width = $height * $ratio_orig;
|
|
} else {
|
|
$height = $width / $ratio_orig;
|
|
}
|
|
|
|
$size['width'] = $width ?? 0;
|
|
$size['height'] = $height ?? 0;
|
|
|
|
$img = Image::make($path)
|
|
->resize($size['width'], $size['height'])
|
|
->save();
|
|
}
|
|
} |