bodruk
bodruk

Reputation: 3262

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!

Upvotes: 7

Views: 5508

Answers (2)

manish1706
manish1706

Reputation: 1599

There is two options available:

1) LAMBDA : if you want to go with AWS services itself the lambda is a good solution for you

http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser.html

There are AWS lambda code which can generate thumbnails based on configured values. The AWS Lambda console itself has some of them which you could tweak into a working system. The link to the console will not work unless you are logged in.

2) ThirdParty : you can use third party resizer like

Timthumb : https://github.com/GabrielGil/TimThumb

TimThumb is a simple, flexible, PHP script that resizes images. (make sure your directory having public access)

Imagine: https://github.com/avalanche123/Imagine

Best image processing lib for a few years now. OOP, unit tested, easy to use and MIT licensed. If someone knows another one of the same quality I would be surprised and like to know about it as well. :)

EasyphpThumbnail : http://www.mywebmymail.com/?q=content/easyphpthumbnail-class

The EasyPhpThumbnail Image Effects class allows you to handle image manipulation and PHP thumbnail generation for GIF, JPG and PNG on-the-fly. The class is FREE, 100% PHP based, available for PHP4 (from 4.3.11) and PHP5, is easy to use and provides lots of functionality with over 60 manipulations:

Upvotes: 0

Eric Knudtson
Eric Knudtson

Reputation: 2583

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/

Upvotes: 3

Related Questions