Reputation:
Let's look at this link: https://images-eu.ssl-images-amazon.com/images/I/51KyXgRx4cL.SY100.jpg. This shows an image with a height of 100px and a resolution of 5kb
You can change the size and also resolution by changing the number before .jpg
.
When changing it to e.g. https://images-eu.ssl-images-amazon.com/images/I/51KyXgRx4cL.SY300.jpg it has a height of 300px and a resolution of 30kb.
How are they doing it? Are there really hundreds of copies of this single image? Or, is this made by .htaccess
? Or are they using complicated web apps? Can I do this for my own server?
Upvotes: 0
Views: 8330
Reputation: 336
"How are they doing it? Are there really hundreds of copies of this single image?"
It can be done by using an image processing API. All you need to is to upload only one high resolution image to the cloud and then dynamically create multiple resized, cropped and manipulated images on-the-fly and deliver them via dynamic URLs.
"Can I do this for my own server?"
Sure,
I like to use Cloudinary to resize and optimize images in my website.
The images are uploaded in my server side PHP code and then for example, if I want to change the height of this image :
http://res.cloudinary.com/demo/image/upload/w_0.5/sample.jpg
I need to change the URL to
http://res.cloudinary.com/demo/image/upload/h_200/sample.jpg
and if I want to change the width to 200 pixels and the height to 100 pixels, change the URL to :
http://res.cloudinary.com/demo/image/upload/w_200,h_100/sample.jpg
Upvotes: 1
Reputation: 1053
Are there really hundreds of copies of this single image?
No.
I don't know, if the Amazon cloud works with htaccess mechanisms, but if you want to do it with your own code and htaccess you can route for example all requests for *.jpg (or any other image format) to a web script or api controller that analyses the string, looks up for the image name and returns a resized copy of that on the fly. Resizing an image of 30 KB or even less is not a big deal and can be done on demand.
This looks like an example for PHP: https://gist.github.com/davejamesmiller/3236415 (htaccess lets me think of PHP first)
Upvotes: 0