You can use the Spatie Media Library package for PHP to resize and compress images before saving them to Amazon S3. Here's an example code block:
main.php828 chars30 lines
In this example, we first get the media object using its ID. We then create a new conversion named thumb
that resizes the image to 100x100 pixels and sets its quality to 70.
We then perform the conversion on the media object using getConversion()
and get the stream of the converted image using Image::load()->stream()
. Finally, we save the image to Amazon S3 using the put()
method of the s3
disk of Laravel's Storage facade.
gistlibby LogSnag