tags:

views:

317

answers:

6

On my site I have given an option to user to choose thier 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&amp;width=400&amp;height=300" />

anyone knows this kind of script, please tell me how to solve this issue.

Thanks

+2  A: 

A recent post:

http://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!

Mark Mayo
+2  A: 

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.

Ignas R
A: 

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!

Grzegorz Gierlik
A: 

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

Yogi Yang 007
A: 

phpThumb might help. Here is the online demo. You may need to check or edit your php configuration to allow phpThumb to open remote files (those that are accessible through http).

Salman A
+4  A: 

The best solution is to use Primage

Jack London