开发者

How to resize linked images dynamically in PHP?

On my site I have given an option to user to choose thi开发者_如何学Cer profile image

  1. 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


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!


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.


I don't have ready to use source code, but it should look like:

  1. Load image pointed by image parameter into object of ImageMagick (or other graphics library).
  2. Resize it.
  3. Send content to output stream.

Optionally you could:

  1. Check if loaded file is image (plus other validation checks).
  2. Save resized image on disk and serve it from disk next time (if you do it often).

Check docs of you favorite graphics library used in PHP for details.

Good luck!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜