Skip to content

How to deal with images with unknown dimensions? #120

Discussion options

You must be logged in to vote

react-photo-album requires image dimensions in order to calculate pixel-perfect layout.

The most efficient solution is to obtain image dimensions on the server side and persist/cache them for future use. You can use a 3rd-party library like image-size.

The least performant solution would be to load images on the client, obtain the dimensions, and then render the gallery component.

It's also worth mentioning that you can use image aspect ratio in leu of the exact dimensions (i.e., you can use width: 400, height: 300 if your image is of 4:3 aspect ratio).

I hope this helps.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@falko-burghausen
Comment options

Answer selected by falko-burghausen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants