如何在 PHP 中动态调整链接图像的大小?
在我的网站上,我为用户提供了选择个人资料图像的选项,
- 类型图像的链接图像
是一个 url 链接,首先我希望将其大小调整为 400x300(图像的原始大小并不重要),然后将其显示在我的网页。
如下所示:
<img src="http://mywebsite.com/resize.php?image=http://someotherurl.com/upload/image2.jpg&width=400&height=300" />
任何人都知道这种脚本,请告诉我如何解决这个问题。
谢谢
On my site I have given an option to user to choose thier profile image
- Type link of an image
Image is a url link, and first I want it to resize to 400x300 (image's original size doesn't matter), and then display it on my web page.
Something like below:
<img src="http://mywebsite.com/resize.php?image=http://someotherurl.com/upload/image2.jpg&width=400&height=300" />
anyone knows this kind of script, please tell me how to solve this issue.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您有 GD 扩展,则可以使用
imagecopyresampled
(该文档还提供了一些示例)。但是,如果要调整大小的图像很大并且服务器上的内存限制较低,则可能会耗尽内存。If you have the GD extenstion, you can use
imagecopyresampled
(the documentation also features some examples). However, if the image to be resized is large and there is a low memory limit on your server, you may run out of memory.我还没有准备好使用源代码,但它应该看起来像:
image
参数指向的图像加载到ImageMagick
(或其他图形库)的对象中。您可以选择:
有关详细信息,请检查 PHP 中使用的您最喜欢的图形库的文档。
祝你好运!
I don't have ready to use source code, but it should look like:
image
parameter into object ofImageMagick
(or other graphics library).Optionally you could:
Check docs of you favorite graphics library used in PHP for details.
Good luck!
使用名为 - class.upload.php 的类。
可以在以下位置找到它: PHP 类
我们在许多工作中始终使用它工作。
这个名字是骗人的,但实际上它是一个上传器和图像处理器。它有一个非常大的功能列表,用于调整图像大小、向图像添加文本、转换格式等。
有示例代码展示了如何从服务器读取图像,修改它,最后直接将其发送到浏览器,而无需在服务器上创建临时文件。
华泰
Use the Class called - class.upload.php.
Find it at: PHP Classes
We use it at all times in many of our work.
The name is deceptive but actually it is an uploader as well as image processor. It has a very big list of functionality for resizing images, adding text to images, converting formats, etc. etc.
There is sample code which shows how to read an Image from server, modify it and finally send it directly to browser without having to create a temp file on server.
HTH
最近的帖子:
https://stackoverflow.com/questions/1302464/php-image-resize-my-upload-script
有一些代码和注释可能会给您一些指导。否则我可以建议
http://www.white-hat-web-design.co.uk/articles/php-image-resizing .php。
祝你好运!
A recent post:
https://stackoverflow.com/questions/1302464/php-image-resize-my-upload-script
has some code and comments that may give you some pointers. Otherwise may I suggest
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php.
Good luck!