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!
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/
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:
Related
I have a quiz site which creates images from a set of source images, the result images are stored in S3 and i don't care about it. My question is about source images, S3 or EFS is better for storing the source images for this purpose. I am using php to create result images.
Here's a general rule for you: Always use Amazon S3 unless you have a reason to do otherwise.
Why?
It has unlimited storage
The data is replicated for resilience
It is accessible from anywhere (given the right permissions)
It has various cost options
Can be accessed by AWS Lambda functions
The alternative is a local disk (EBS) or a shared file system (EFS). They are more expensive, can only be accessed from EC2 and take some amount of management. However, they have the benefit that they act as a directly-attached storage device, so your code can reference it directly without having to upload/download.
So, if your code needs the files locally, the EFS would be a better choice. But if you code can handle S3 (download from it, use the files, upload the results), then S3 is a better option.
Given your source images will (presumably) be at a higher resolution than those you are creating, and that once processed, they will not need to be accessed regularly after while (again, presumably), I would suggest that the lower cost of S3 and the archiving options available there means it would be best for you. There's a more in depth answer here:
AWS EFS vs EBS vs S3 (differences & when to use?)
I have a bunch of images in Amazon S3 that I need to physically rotate. I currently do this by downloading the image to my server, rotating it using GD and overwriting it back to S3.
This process takes ~5 secs per image. I was wondering if there is any AWS API or such that can do this rotation directly in S3, preferably as in a batch mode?
I would appreciate it if anyone who has any experience with that kind of stuff can give me any pointers!
There is no way to rotate an image 'on' S3. Any method you employ is going to have to read the file from S3, do the rotation, and write it back to S3.
If the server you are doing it on now is not an EC2 instance, than its worth a try to do it there - the latency will be reduced quite a bit. Lambda is another option for you in that it will run within the AWS infrastructure, so network overhead will be reduced.
Not quite sure what your constraints might be, but if you're preparing the images for a web page - you could rotate them client-side using CSS. That would prevent the additional calls to S3, and eliminate processing load on your application server.
img {
transform: rotate(90deg);
}
i have been working in a video website [platform: php] where i need to upload videos in Amazon S3 server and extract thumbnail.
I have created a bucket and uploaded video file successfully in that bucket. But i don't know how to extract the thumbnail from that uploaded video. So, that's where i stuck.
Any help will be appreciated. Thanks in advance!
Here you've got some options.
First - you can "extract" a thumbnail from the video before you upload it to AWS. Something like: upload video to your server, convert it to appropriate format if needed, take a thumbnail (or thumbnails), save them somewhere (e.g. on S3 or your local server) and then upload the video to S3. The disatvantage of this method is that your local server will have to do a lot of extra work, instead of serving your web visitors.
Second - you can use Amazon EC2 computing service for that: upload video to S3, trigger EC2 (e.g. with cron jobs) to take the video from S3, convert it, take thumbnails and upload the final result (converted video + thumbnails) back to S3. Disatvantages are: it's not very easy to implement this "communication" (you'll have to solve a lot of problems, like ensuring stable converts, creating job queues etc.), plus you'll have to use one more AWS service along with S3.
What's about video converting and getting thumbnails? There are many tools and programs for that. I like using ffmpeg for video converting (also there's PHP wrapper for using it's functionality with php - php-ffmpeg, but using ffmpeg itself (e.g. using php's exec() function) will give you more flexibility and features, please read documentation for more details). FFMpeg can extract thumbnails from videos as well, but it takes some time (there are lots of discussions about how to do it effectively), but I'd suggest you to use ffmpegthumbnailer for this purpose. It has simpler usage and is optimized especially for getting thumbnails from video files.
You should do this on the machine you are using for the upload. Here you have direct file-system access to the file. Once it is in S3 it is accessible via HTTP only.
The tool ffmpeg can be used to create a thumbnail of many video formats.
Example:
ffmpeg -i "video.flv" -ss 00:00:10 -f image2 "thumbnail.jpg"
Would create a thumbnail at video second 10 and save it as thumbnail.jpg
When using PHP you can use system to execute
I am developing a website in php hosted on a shared linux server.
I need to allow the users of my site to upload and play flv videos with flowplayer.
It would be fantastic to show a snapshot of the video before it starts, something like these: http://flowplayer.org/demos/plugins/streaming/first-frame.html
My server doesn't support pseudostreaming and it has no ffmpeg/mplayer support (it's a shared host after all...)
I am guessing how can I take a snapshot of the nth frame of the video with only php or javascript or action script.
I read something about bitmapdata class in flash >= 8, but i don't know how to do all the work automatically without the user's input.
Can someone help me?
Thanks.
AFAIK - if your server doesn't have ffmpeg, you're not going to be able to do it with PHP.
You definitely can't do it with JS.
Which leaves AS - you can create a bitmap from any display object, and save that as an image file with PHP, both of which are pretty straightforward - but you're not going to be able to run through the video to find the first frame... with AS, the image "snapshot" is the exact current visible state of the display object.
if that is enough - taking the current state of a display object and saving it as an image file - post back and i'll link a sample.
If you're on a shared Linux server, you might have ImageMagick installed. That in turn may be able to extract a screenshot of a particular frame from a movie. However this will probably only work on AVI files - MPEG movies require ffmpeg, and I am not sure about FLV files (they're not in the list of supported formats on the IM website).
Could you switch to a VPS? This will give you the root access you need to install the conversion binaries you need. These days a reasonable one with 256M-512M of RAM will cost you from 5USD pcm depending on the quality and support (I pay 4GBP pcm for a 512M box and it really has been rock solid).
Currently I am looking to move my websites images to a storage service. I have two websites developed in PHP and ASP.NET.
Using Amazon S3 service we can host all our images and videos to serve web pages. But there are some limitations using S3 service when we want to serve images.
If website needs different thumbnail images with different sizes from original image, it is tough. We have again need to subscribe for EC2 also. Though the data transfer from S3 to EC2 is free, it takes time for data transfer before processing image resize operation.
Uploading number of files in zip format and unzipping in S3 is not possible to reduce number of uploads.
Downloading multiple files from S3 is not possible in case if we want to shift to another provider.
Image names are case sensitive in S3. Which will not load images if image name does not match with request.
Among all these first one is very important thing since image resize is general requirement.
Which provider is best suitable to achieve my goal. Can I move to Google AppEngine only for the purpose of image hosting or is there any other vendor who can provide above services?
I've stumbled upon a nice company called Cloudinary that provides CDN image storage service - they also provide a variety of ways that allow on the fly image manipulation (Cropping will mainly concern you as you we're talking about different sized thumbnails).
I'm not sure how they compete with other companies like maxcdn in site speed enhancement but from what I can see - they have more options when it come to image manipulation.
S3 is really slow and also not distributed. Cloudfront in comparison is also one of the slowest and most expensive CDNs you can get. The only advantage is that if you're using other AWS already you'll get one bill.
I blogged about different CDNs and ran some tests:
http://till.klampaeckel.de/blog/archives/100-Shopping-for-a-CDN.html
As for the setup, I'd suggest something that uses origin-pull. So you host the images yourself and the CDN requests a copy of it the first time it's requested.
This would also mean you can use a script to "dynamically" generate the images because they'll be pulled only once or so. Just have to set appropriate cache headers. The images would then be cached until you purge the CDN's cache.
HTH
I've just come across CloudFlare - from what I understand from their site, you shouldn't need to make any changes to your website. Apparently all you need to do is change your DNS settings. Even provides a free option.
If you're using EC2, then S3 is your best option. The "best practice" is to simply pre-render the image in all sizes and upload with different names. I.e.:
/images/image_a123.large.jpg
/images/image_a123.med.jpg
/images/image_a123.thumb.jpg
This practice is in use by Digg, Twitter (once upon a time, maybe not with twimg...), and a host of other companies.
It may not be ideal, but it's the fastest and most simple way to do it. In terms of switching to another provider, you'll likely not do that because of the amount of work to transfer all of the files anyway. If you've got 1,000,000 images or 3,000,000 images, you've still got many megabytes of files.
Fortunately, S3 has an import/export service. You can send them an empty hard drive and they'll format it and download your data to it for a small fee.
In terms of your concern about case sensitivity, you won't find a provider that doesn't have case sensitivity. If your code is written properly, you'll normalize all names to uppercase or lowercase, or use some sort of base 64 ID system that takes care of case for you.
All in all, S3 is going to give you the best "bang for your buck", and it has CloudFront support if you want to speed it up. Not using S3 because of reasons 3 and 4 is nonsense, as they'll likely apply anywhere you go.