Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize images in AWS S3

I have a PHP REST API that hosts all images in the Amazon S3. I'm looking for a plugin, or trick, to resize the images using GET params. For example:

http://my-bucket.s3.amazon.com/image.jpg?width=300&height=300

I found this plugin, but a member of my team said it is ASP.NET based and doesn't fit to my PHP API project. Should I use a script hosted in EC2 to resize those images? Is there other way? Ideas are welcome.

Thanks!

like image 801
bodruk Avatar asked Nov 05 '14 15:11

bodruk


People also ask

Can S3 compress images?

As you can see from the image below, with one S3 bucket our user would upload an image to our bucket. That bucket generates a notification out to our lambda function to compress an image. When the lambda function is finished, the image gets saved back into the bucket.

Is S3 good for image hosting?

S3 is a more professional image hosting choice; it offers tighter control along with a full set of developer APIs.

Can I store images in S3 bucket?

With buckets, you will store your files and images, and you will be comfortable for the rest!


1 Answers

I suggest setting up your own PHP service to resize images based on the query string values, as you describe. Yes, the PHP service could be hosted on AWS EC2 or another hosting platform. The service would need to receive the query string such as:

http://example.com/images/image.jpg?width=300&height=300

This would need to be configured (perhaps using mod_rewrite [1]) to receive the name of the image (example: 'image.jpg') and pass the query string size values into your PHP script. The script would then find your image on S3, resize it using an image library (such as ImageMagick / PHP GD or PHPThumb [2]) save it (or not) back to S3 and also pass the image data back through on the original request.

I wish you good fortune!

[1] https://httpd.apache.org/docs/current/mod/mod_rewrite.html

[2] http://phpthumb.sourceforge.net/

like image 134
Eric Knudtson Avatar answered Sep 18 '22 06:09

Eric Knudtson