Resize an Image before upload to S3
Hi All.
I want to resize an image before sending it to S3 ( I use Intervention/Image ):
$image = request()->file( 'file' );
$image = Image::make( $image )->widen( 1500, function( $constraint )
{
$constraint->upsize();
} );
$path = $image->store( 'safe-papers', 's3' );
But I have this error :
Command (store) is not available for driver (Gd)
Is it not save() rather than store()?
When I try with store there is no error but if I die the result I have some strange caracters
dd( $path );
+encoded: b"""
Ï Ó\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00 ■\x00:CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), quality = 0\n
█\x00C\x00 █\x00C\x01 └\x00\x11\x08\x03\x07\x03 \x03\x01"\x00\x02\x11\x01\x03\x11\x01 ─\x00\x1F\x00\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n
\v ─\x00Á\x10\x00\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01}\x01\x02\x03\x00\x04\x11\x05\x12!1A\x06\x13Qa\x07"q\x142üæí\x08#B▒┴\x15RÐ$3bré\t\n
\x16\x17\x18\x19\x1A%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzâäàåçêëèÆôöòûùÿÖÜóúñѪº¿®¬▓│┤ÁÂÀ©╣║┬├─┼ãÃ╚╔╩ÊËÈıÍÎÏ┘┌ßÔÒõÕµþÞÚÛ±‗¾¶§÷¸°¨· ─\x00\x1F\x01\x00\x03\x01\x01\ .....
That's the contents of the JFIF file.
that's the raw content of the image. Save that to S3.
With :
$path = $image->save( 'safe-papers', 's3' );
There is no errors but nothing is save to S3 !
Give the Storage facade a run at this:
$image = request()->file( 'file' );
$image = Image::make( $image )->widen( 1500, function( $constraint ) {
$constraint->upsize();
Storage::disk('s3')->put('/path/to/image.jpg', $image->stream()); // is 'safe-papers' a filename/directory/bucket?
My working code is:
$file = request()->file('my_input_file_name');
$imageName = $file->getClientOriginalName();
$img = Image::make($file);
$img->resize(null, 1000, function ($constraint) {
$constraint->aspectRatio();
});
//detach method is the key! Hours to find it... :/
$resource = $img->stream()->detach();
$path = Storage::disk('s3')->put(
'my-s3-folder/' . $imageName,
$resource
);
Please or to participate in this conversation.