PHP 图像大小调整未知源大小,已知输出大小
我目前正在一个网站上工作,这要求网站的管理员能够上传几乎任何大小的图像,然后我需要找到一种方法将图像缩小到前端所需的大小在网站的最后,所有这些都需要在不知道用户上传的图像大小的情况下完成,但图像总是需要缩放到 209x293 而不会看起来很糟糕。
这可能吗?
I am working on a site at the moment, that requires the admins of the site to be able to upload pretty much any size of image, I then need to find a way to get the image down to the size required for the front end of the end the site, all this needs to be done without know what size of image the user is uploading, but the image always needs to scale to 209x293 without looking awful.
Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该与您的客户争论,忘记该规则(接受任何图像),而只接受该比例的图像,或更好,您可以使用工具来裁剪图像,迫使用户以您需要的分辨率裁剪图像。
Jcrop 是 Jquery 中的一个库,如果您想创建裁剪功能,它可以为您提供很大帮助。
You should argue with your client, to forget that rule(accept ANY image), and accept rather, only images in that proportion, or better, you can use a tool to crop the image, forcing the user to crop an image in your needed resolution.
Jcrop is a library in Jquery which can help you a lot if you want to create that cropping feature.
不知道您的确切要求,但既然您用 CodeIgniter 标记了它,您可以查看 图像操作类 拥有完成这项工作所需的一切。
您知道,在上传之前不知道图像的大小是一个很常见的问题...只需注意 php.ini 中设置的 MAX SIZE。
您可能会发现 php 中的文件上传 页面也很有用手动的。
Don't know your precise requirements, but since you tagged it with CodeIgniter, you can check out the Image Manipulation Class which has everything you need to do the job.
Not knowing the size of images before uploading is, you know, quite a common problem...Just be careful of the MAX SIZE, which is set in your php.ini.
You might find useful also the page on file uploading right in php's manual.