Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I know the size of a resized image? #1080

Closed
petr-buchin opened this issue Mar 15, 2018 · 4 comments
Closed

How do I know the size of a resized image? #1080

petr-buchin opened this issue Mar 15, 2018 · 4 comments

Comments

@petr-buchin
Copy link

petr-buchin commented Mar 15, 2018

Q A
Bug Report? no
Feature Request? yes
BC Break Report? no
RFC? no
Imagine Bundle Version 2.0.0

I'm using stream loader to load image from Amazon S3 bucket, and AWS S3 cache adapter to upload resized image to another bucket.
I'm also using relative resize by width.
How do I know dimensions of the resized image?

The possible solution is to download original image from bucket, use local loader to load image, save it's dimensions and aspect ratio, and calculate new dimensions after resize.
But I would like to get this dimensions without repeating calculations, which already had been made by this bundle.
Is it possible?

@robfrawley
Copy link
Collaborator

You can inject the FilterService into a controller or service of your own and use the createFilteredBinary method to request a BinaryInterface instance.

@petr-buchin
Copy link
Author

petr-buchin commented Mar 15, 2018

@robfrawley, thank you for your answer, but I see that this method is private.
But using a dirty hack with reflection or Closure::call() I can use the private method.

But also I have the question:
If I call createFilteredBinary first, and then call FilterService::getUrlOfFilteredImage() - will image be downloaded from bucket once or twice, e.g. will method createFilteredBinary download and filter image, if it was called earlier, but image was not yet cached via CacheManager?

@robfrawley
Copy link
Collaborator

robfrawley commented Mar 15, 2018

My bad; I forgot that method wasn't public. Regarding your question, yes: calling createFilteredBinary followed by getUrlOfFilteredImage will request the cached image twice, which can be an expensive operation if the image is cached on Amazon S3.

You can alternatively inject the DataManager, FilterManager, and CacheManager inside your own service where you can essentially duplicate the logic of FilterService and implement your own logic to handle multiple calls to the same image with a caching layer of some sort (for example, using an array or external cache implementation).

@petr-buchin
Copy link
Author

@robfrawley thank you, I'll give it a try!

@dbu dbu closed this as completed Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants