如何检查图像的尺寸,以便按比例缩小图像以避免失真?

发布于 2024-10-03 11:37:13 字数 255 浏览 0 评论 0原文

当人们写文章时,他们会提交一张照片来说明事件。但是,展示的空间并不宽阔。因此,我想减少它们的宽度和/或高度,同时保持其原始比例。否则,图像会失真。

假设最大宽度为 300px。任何比这更宽的宽度都会减少到 300 像素。但是,我希望高度减少到相同的比例。例如:600 x 800 将变为 300px x 400px。因此,我需要能够检查尺寸,

如何检查这些尺寸? 我什么时候检查它们? (i) 上传后,(ii) 从数据库检索时?...

感谢您的帮助

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦行七里 2024-10-10 11:37:13

我建议您在上传后检查图像并将两个版本保存到数据库中 - 原始版本和调整大小的版本。您应该将调整大小的版本与文章一起提供。这样您只需调整图像大小一次。

有关代码示例,请查看此处:

C#:在保持宽高比和最大高度的同时调整图像大小

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文