Richard77
Richard77

Reputation: 21609

How can I check the dimensions of a image so that I can reduce them proportionaly to avoid distortion?

When people write an article, they submit a photo to illustrate the event. But, the space to display is not wide. So, I'd like to reduce they width and/or height while keeping their original proportion. Otherwise, the image gets distorted.

Let's say the max width is 300px. Anyting wider than that would see its width reduced to 300px. However, I'd like the Height to be reduced to the same proportion. For instance: 600 x 800 will become 300px x 400px. So, I need to be able to check the dimensions

How do I check those dimensions? When do I check them? (i) after uploading, (ii) while retreiving from the database?...

Thanks for helping

Upvotes: 2

Views: 266

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

I would suggest you check the image after upload and save two versions to the database - the original and the resized version. You should serve the resized versions with the article. That way you resize the image only once.

For code example take a look here:

C#: Resize An Image While Maintaining Aspect Ratio and Maximum Height

Upvotes: 2

Related Questions