📜 ⬆️ ⬇️

Cloud resizing of images

Hello World!


I am a web developer. In the course of my professional activities, I have to deal with various systems and platforms. As practice has shown, it is not always possible to use the full-fledged environment necessary for image processing. No matter how regrettable it is, sometimes you have to deal with customers who are principally hosted on a certain platform with prehistoric software, and sometimes, if this is an educational institution or any other component of the state system, on its servers, access to which is not who.

Task


What to do in this case? It seems possible not to get involved in such projects, but it is not always possible. We set the task to make cloud image processing, in particular - resize. Within one of the conditions of the problem, we set the necessary restrictions on the use of processor time and installed graphics libraries on the client side.

Decision


About a year ago I had a need for realtime generation of small thumbnails of pictures of the photo gallery on the website of one educational institution. As part of the affordable privacy option, I will not mention the name of this place. So, the images are loaded from the admin panel, and due to the specific nature of the activities of the people involved in administering the site, it is not possible to force them to change the size of the pictures to at least an acceptable minimum. So At the entrance, we have pictures up to 10MB in size, at the exit we need to display them in the form of a small lightweight gallery. The only possible option was the implementation of a cached proxy server, which would take on all the headaches of image resizing. Without hesitation, I made a decision on NodeJS using the ImageMagick graphics library. This solution is available for public use at http://thumber.io .
')

Implementation feature


I would like to pay special attention to the features of storing “crooked” images using the cache, thanks to which when you re-request an already processed image, the processing itself will not be started. This saves time reloading images. Cropped images are stored on S3. The invalidation of the cached object will be made only in case of a change in its hash sum or a change in the etag header. For those who are not familiar with this heading - https://ru.wikipedia.org/wiki/HTTP_ETag ( sorry, if this section may seem to someone to be the smallest and dullest ).

Examples


As an example of use, I can cite the processing of the image available at
https://habrastorage.org/getpro/habr/comment_images/f22/27f/7d8/f2227f7d86053a207ebc88ae3377af4f.jpg :
image

Using our solution, we can make it resize to fit the image into a 200x200 area using the following URL:
  http://thumber.io/get/200x200/https://habrastorage.org/getpro/habr/comment_images/f22/27f/7d8/f2227f7d86053a207ebc88ae3377af4f.jpg 

Result of processing:
image

I think it is intuitively clear how this kind of processing can be used. As a parameter after / get / you can also use the percentage change. For example,
  https://habrastorage.org/getpro/habr/post_images/1be/525/a7a/1be525a7a940f9e63705ffb1d4d9845e.jpg 

Result:
image


Hypothetically, it is possible to use any switch parameter -resize the convert utility. A more detailed description of the use of opportunities we have placed in a small document available at http://thumber.io/Thumber.io.Documentation.pdf . I hope that those who wish to familiarize themselves have no problems with the English language, and everything will be clear. If something may require additional explanation, please ask questions in the comments.

Conclusion


Almost a year has passed since the publication of this decision. During this time there were real examples of its use in production. Now there is a question about the expediency of dense work on this area, its development, adding new interesting features and capabilities. This small post is written with the purpose to make a copy. Habrasoobshchestvu, help make a decision. Do you have any thoughts about the further development of this product and its applied use?

Source: https://habr.com/ru/post/275739/


All Articles