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

Image width and height on-the-fly #50

Closed
hasnatbabur opened this issue Dec 13, 2019 · 4 comments
Closed

Image width and height on-the-fly #50

hasnatbabur opened this issue Dec 13, 2019 · 4 comments

Comments

@hasnatbabur
Copy link

Is there any way to get the desired image height and width before sending html response? We need this feature for image gallery section. Thanks

@sherwinski
Copy link
Contributor

Hi @hasnatbabur, could you elaborate a bit more about what you are looking for? Or possibly provide an example of the feature that you're describing. Thanks

@hasnatbabur
Copy link
Author

@sherwinski
Let's consider the following html ...

I am using following libraries:
https://github.com/imgix/imgix-php
https://github.com/Otisz/Laravel-Imgix

/! blade template file

// get imgix url
$imagePath = 'image/path/on/web';
$imgixUrl = imgix_url($imagePath); // we pass only h=300, and width should be auto
<div class="gallery">
    <img class="gallery__img" width="??" height="??" src="{{ $imgixUrl }}"/>
    <img class="gallery__img" width="??" height="??" src="{{ $imgixUrl }}"/>
    <img class="gallery__img" width="??" height="??" src="{{ $imgixUrl }}"/>
</div>

For the example above is there any way to get the width and height of the image from imgix so that we can use in the markup above? The grid will not work without proper image height and width attribute values.

Please have a look the gallery here:
https://tookapic.com/photos
They also use imgix and getting image height and width in PHP variable for using.

Can you help? Thanks.

@sherwinski
Copy link
Contributor

Hi @hasnatbabur, thank you for providing more details.

Unfortunately, this is not a supported feature through imgix's service or this library. The best suggestion I can give is to use the fm=json parameter to extract the PixelWidth and PixelHeight metadata on the master image. This could possibly give you an idea of how to scale your width and height to maintain the image aspect ratio. However, this would have to be done for each image ahead of time so it's probably not the exact solution you are looking for.

I am not sure how tookapic is determining the width and height of their images. I would imagine that they are somehow extracting/storing the image dimensions separately.

I hope that helps you. Feel free to comment back if you have anymore questions.

@hasnatbabur
Copy link
Author

@sherwinski Thanks a lot for your clarification. From your suggestion I think I should store main image dimension/meta in database then calculate modified dimensions.

Thanks for your help.

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

2 participants