dotblue / nette-webimages

On-the-fly generated web images for your Nette app
Other
26 stars 17 forks source link

Resizing image in provider #13

Closed Lawondyss closed 9 years ago

Lawondyss commented 9 years ago

Why not create thumbnails in the provider? The provider generate only path to the picture, but I want to have in control the method of obtaining thumbnails.

vojtech-dobes commented 9 years ago

I am not sure I follow.

vysinsky commented 9 years ago

You can do whatever you want in provider. See https://github.com/dotblue/nette-webimages/blob/master/examples/DefaultImageProvider.php

Lawondyss commented 9 years ago

OK, but why Generator save image from Provider? https://github.com/dotblue/nette-webimages/blob/master/src/Generator.php#L88

vysinsky commented 9 years ago

Because the main goal of this library is that you process image only once.

When you access /images/dog.jpg and it does not exist it fires the provider which returns image and this images is saved to location /images/dog.jpg

Next time someonte access /images/dog.jpg the provider (whole nette application) is not called at all because web server returns it immediately.

Lawondyss commented 9 years ago

And why not save the image in the provider?

vysinsky commented 9 years ago

Why would you do that? It would be the same code in every provider. Provider does not care where it will be saved or if it will be saved at all. Provider just returns image in exact format.

Lawondyss commented 9 years ago

Because I cannot over save the image. Example: I have two provider. First return thumbnail from expected picture. Second return placeholder if expected picture not exist. If Generator save the placeholder, then first provider never save new picture when expected picture already exists.

Lawondyss commented 9 years ago

BTW sorry for the bad title of the Issue.

vojtech-dobes commented 9 years ago

Well, if picture exists and it's requested for the first time, it will generate and save thumbnail. If it doesn't exist, placeholder will be saved instead. If you get the image later and you want to change placeholder to correctly generated thumbnail, you can either:

  1. delete the current thumbnail
  2. save the image under new name.
Lawondyss commented 9 years ago

OK, thanks. I suppose you not change your opinion about moving deciding of saving to a provider.

vojtech-dobes commented 9 years ago

I suppose you not change your opinion about moving deciding of saving to a provider.

Well, why should I :) ? At this moment, without further arguments, I think it would break the whole architecture (it just wouldn't make any sense).