按比例调整图像大小
我想将上传的图像调整为宽度:180px,高度成比例。有没有任何课程可以做到这一点?
感谢您的帮助!
i want to resize uploaded images to width: 180px with proportional height. Is there any classes to do this?
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这个问题可以用实际的代码示例来回答。下面的代码向您展示了如何调整
uploaded
目录中图像的大小,并将调整后的图像保存在resized
文件夹中。I think this question can use an answer with an actual code example. The code below shows you how you to resize an image inside a directory
uploaded
, and save the resized image in the folderresized
.首先,您需要获取当前图像尺寸:
然后计算缩放因子:
当具有缩放因子时,只需计算图像的新高度:
然后创建新图像;
也许这些片段会有所帮助:
http:// /www.codeslices.net/snippets/resize-scale-image-proportionally-to-given-width-in-php http://www.codeslices.net/snippets/resize-scale-image -proportionally-in-php
至少他们为我工作。
First you need to get the current image dimensions:
Then calculate the scaling factor:
When having the scaling factor just calculate the new height of the image:
Then just create the new image;
Probably these snippets will help:
http://www.codeslices.net/snippets/resize-scale-image-proportionally-to-given-width-in-php http://www.codeslices.net/snippets/resize-scale-image-proportionally-in-php
at least they worked for me.
您可以使用 imagecopyresampled php 函数。您还可以计算新的尺寸。
you may use imagecopyresampled php function. new sizes you also can calculate.
使用 jquery 插件 JCrop,并设置图像的长宽比...
检查此链接了解详细信息:
http://www.webresourcesdepot.com/jquery-image-crop-plugin- jcrop/
User jquery plugin JCrop, and set its aspect ratio for the image...
Check this link for details:
http://www.webresourcesdepot.com/jquery-image-crop-plugin-jcrop/