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

Predict dimensions for img tag #16

Open
mikeboers opened this issue Jun 7, 2014 · 5 comments
Open

Predict dimensions for img tag #16

mikeboers opened this issue Jun 7, 2014 · 5 comments

Comments

@mikeboers
Copy link
Owner

It would be swell if we could predict the final width/height of an image so that they can be used in the template as well (to avoid a jump in layout when the images load).

Perhaps something like:

{{ resized_img('path/to/image.jpg', class_="myclass", mode='fit', width=200, height=200) }}

would render into:

<img class="myclass" src="/imgsizer/path/to/image.jpg?m=fit&w=200&h=200&s=xxx" width="200" height="150" />

Some testing needs to be done with regards to the speed at which dimension data can be extracted from images on disk without loading all of the data, so that we know if we can get away with the naive implementation or if we have to intelligently cache dimensions.

@iurisilvio
Copy link
Contributor

Code to do it with .png: http://stackoverflow.com/questions/8032642/how-to-obtain-image-size-using-standard-python-class-without-using-external-lib

You have to read only some file headers.

@iurisilvio
Copy link
Contributor

Also, PIL does not load the image to memory on .open.

http://stackoverflow.com/a/19034942/617395

@mikeboers
Copy link
Owner Author

PIL doesn't require loading the image on .open, but the docs don't lead me to believe that they never will. Looking at the SO question you linked to it seems that malformed JPEGs would result in loading everything, but I don't think that is something to be really concerned about.

So I guess we need to see how PIL[low] behaves with the other formats, and if it doesn't actually load the data (from valid files) then I'm cool with just using PIL to do it. Otherwise, it sounds like a good idea for another small library. ;)

@mikeboers
Copy link
Owner Author

This is underway now as it is required for the implementation of "retina" support for my personal site.

@mikeboers
Copy link
Owner Author

This is done in the "retina" branch.

@mikeboers mikeboers reopened this Oct 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants