I’m using http://image.intervention.io/ with Laravel to resize images before storing them in an AWS S3 bucket. Here is the applicable code:
$extension = $image->extension(); $realPath = $image->getRealPath(); $resizedImage = Image::make($realPath) // ->resize(255, 255); // resize or not, make() seems to always return an empty Image $file_path = "posts/$post->id/images/image-$post->id-num-$pictureCount.$extension/"; $path = Storage::disk('s3')->put($file_path, $resizedImage->__toString(), ['visibility' => 'public']);
When debugging (breakpoint on the line
$path is set) this I can see that
$realPath holds a value like
/private/var/folders/23/jl2dytp168g9g9s5j51w2m780000gn/T/php9047Fh – and going there I can see the image that I’m trying to
$resizedImage object has the following fields:
[encoded] => [mime] => image/jpeg [dirname] => /private/var/folders/23/jl2dytp168g9g9s5j51w2m780000gn/T [basename] => phpTNRdXe [extension] => [filename] => phpTNRdXe
I’m guessing that the encoded property should hold something like the base 64 image data?
When checking the image in AWS S3 bucket, it is always getting uploaded as a image with 0 bytes. What am I doing wrong here?
Intervention is configured to use GD if it makes any difference
The file object can be passed directly in
Image::make gets the
The image should be encoded before accessing its encoded value.
$path = Storage::disk('s3')->put($file_path, $resizedImage->__toString(), ['visibility' => 'public']);