I have the following:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine;
class UploadController extends Controller {
public function processImage($request) {
$file = $request->file('file');
$path = '/images';
$fileName = 'image.png';
if ($file) {
$file->move('../public' . $path, $fileName);
$gThumb = $this->createThumbnail(219, 300, '../public/images', 'image', 'png', 'thumb', true);
$pThumb = $this->createThumbnail(300, 300, '../public/images', 'image', 'png', 'pthumb');
return response()->json([
'gallery_thumbnail' => $path . '/' . $gThumb,
'upload_thumbnail' => $path . '/' . $pThumb
]);
}
}
function createThumbnail($height, $width, $path, $filename, $extension, $postfix = null, $mask = null)
{
$mode = ImageInterface::THUMBNAIL_OUTBOUND;
$size = new Box($width, $height);
$postfix = $postfix ? $postfix : 'thumb';
$thumbnail = Imagine::open("{$path}/{$filename}.{$extension}")->thumbnail($size, $mode);
if ($mask) {
$mask = Imagine::open('../public/images/masks/bubble-splash.png');
$thumbnail->applyMask($mask);
}
$destination = "{$filename}" . "." . $postfix . "." . "{$extension}";
$thumbnail->save("{$path}/{$destination}");
return $destination;
}
}
It saves the images as expected but does not apply the mask to the thumbnail.
Where am I going wrong (I am using Laravel 5)?
Also, when the script runs it takes literally about 1 minute to complete, so it's doing something but the images are still outputted with no mask applied.
In the end I think I'm going to use these guys https://www.imgix.com/