如何在上传时限制图像宽度或高度 [英] How to restrict image width or height on upload

查看:116
本文介绍了如何在上传时限制图像宽度或高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以与 Pinterest 类似的方式操纵/调整图片大小,但我不确定什么是最好的方式接近它。目标是允许混合纵向和横向图像,但对最大高度和宽度进行一些限制。

I would like manipulate/resize images in a similar way to Pinterest but I am not sure what is the best way to approach it. The goal is to allow a mix of both portrait and landscape images but put some restrictions on the maximum height and width.

我可以看到的问题是,如果我调整大小宽度,肖像图像可能会变得太薄,而景观图像则相反。

The problem i can see is that if I resize to a width, a portrait image may become too thin, and the opposite it true for a landscape image.

有关如何使用PHP实现这些结果的任何想法?

Any ideas on how to achieve those sort of results with PHP?

推荐答案

您只需要了解图像的两个边缘中的哪一个更长,并按比例计算另一个维度。如果最大long-egde为1024,那么如果两个边之一较大,则将其设置为1024,并计算另一个以适合比例。然后,您将这两个值传递给图像管理功能。

You just need to understand which of the two edges of the image is longer, and compute the other dimension proportionally. If the maximum long-egde is 1024, then if one of the two edges is larger you will set that to 1024, and compute the other to fit the proportions. Then you will pass those two values to your image management functions.

喜欢这里:
http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

或者这里:
http://www.9lessons.info/2009/03/upload-and-resize-image-with-php.html

这篇关于如何在上传时限制图像宽度或高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆