I am trying to upload a couple of resized images to S3, but somehow all images have the same size. Storing them locally in different sizes gives no problems. What am I missing?
public function uploadFileToS3(Request $request) {
$image = Image::make($request->file('image'))->encode('jpg', 75);
$s3 = Storage::disk('s3');
$image_file_name = $this->generateName($request->name) . '.jpg';
$file_path = '/' . config('folder') . '/' . $request->name . '/';
$s3->put($file_path.'original_'.$image_file_name, $image, 'public');
$s3->put($file_path.'medium_'.$image_file_name, $image->fit(300, 300), 'public');
$s3->put($file_path.'thumb_'.$image_file_name, $image->fit(100, 100), 'public');
return json_encode(array(
'filename' => $image_file_name
));
}
All versions are stored successfully in S3, only all in the same size
I have two possible solutions.
Try to do the image manipulation completely before attempting to store them:
$s3->put($file_path.'original_'.$image_file_name, $image, 'public');
$image->fit(300, 300);
$s3->put($file_path.'medium_'.$image_file_name, $image, 'public');
$image->fit(100, 100);
$s3->put($file_path.'thumb_'.$image_file_name, $image, 'public');
Try to cast the image to a string, the actual output file contents should work fine:
$s3->put($file_path.'original_'.$image_file_name, (string) $image, 'public');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With