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

こ雲淡風輕ζ 提交于 2019-12-02 05:49:59

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/4233039/how-can-i-check-the-dimensions-of-a-image-so-that-i-can-reduce-them-proportional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!