inital commit
This commit is contained in:
30
app/Helpers/Compress.php
Normal file
30
app/Helpers/Compress.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user