N
N
Nikolai Egorov2017-11-17 16:11:06
symfony
Nikolai Egorov, 2017-11-17 16:11:06

Best practices for generating thumbnails for galleries?

Hi all!
Now I'm making a gallery, and a small question arose about how to organize the generation, and work in general, with previews.
Previously, I did all this in the following way:
- I immediately generated previews when uploading images
- saved them like regular (original) images in the gallery folder
- The object had getPreview and setPreview methods, in addition to getImage and setImage for a regular size image.
Now, studying Symphony, I often see something like this:
- previews are generated when accessing them, by calling the appropriate filter in the View. On the example of Symphony, this is something like

<img src="{‌{ 'image.jpg' | imagine_filter('my_thumb') }}" />

- in this case, the preview is not stored in the main gallery folder, but in the cache folder.
- for the object, respectively, the getPreview and setPreview methods are unnecessary, because for its generation, preservation, etc. responsible for a separate service. It turns out that the Model knows nothing at all about the preview, as well as the Controller itself.
As I understand the second option is more correct? Who does what?
Please share your experience!
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2017-11-18
@BorisKorobkov

If there are many images, different sizes too, and access to them is not very frequent, then it is more profitable to store only one image of the maximum size and resize on the fly nginx.org/ru/docs/http/ngx_http_image_filter_modul...

N
Nikolai Egorov, 2017-11-20
@nickicool

Thanks to all who responded! I'll add the question then.
If we need to generate a preview, then generating it on the fly in the View, without changing the Model and Gallery Controller, is probably good practice.
But what if the picture should have several options for the main sizes. Let's say that to ensure the adaptability of the picture, you need 2 sizes + preview. And for adaptive images, sometimes it is required not only to reduce the image, but also, for example, crop it a little from the left / right, while changing the aspect ratio. Then, probably, it's better to generate a preview "on the fly" and not save it in the model and database, but for important sizes, implement the generation "by handles, by the admin" based on the original one with the specified parameters.
While I want to try to implement this approach (second). If you have something to say about this, I will be very grateful for the comments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question