Forked from MicrowaveDev/ImageToInstagramController.php
Created
November 22, 2022 05:11
-
-
Save codeperl/9b9e285185ff977e605fac2fbd072d8d to your computer and use it in GitHub Desktop.
Laravel Intervention Image place to square for instagram(fill background, vertical or horizontal align a image) plus blur option.
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
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
class AdminController extends Controller | |
{ | |
public function imageFillToSquare(Request $request){ | |
$data = $request->all(); | |
$image = \Image::make(base_path($data['src'])); | |
$image_height = $image->height(); | |
$image_width = $image->width(); | |
if($image_height > $image_width) { | |
$is_vertical = true; | |
} else if($image_height < $image_width) { | |
$is_vertical = false; | |
} else { | |
return $image->response(); | |
} | |
$max_size = $is_vertical ? $image_height : $image_width; | |
$canvas = \Image::canvas($max_size, $max_size); | |
$image->backup(); | |
if(isset($data['blur_fill']) && $data['blur_fill']) | |
#recomended use Imagick driver | |
$canvas->fill($image->blur($data['blur_fill'])); | |
else | |
$canvas->fill('#ffffff'); | |
$image->reset(); | |
$canvas->insert($image->encode('data-url'), 'center'); | |
return $canvas->response(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment