English 中文(简体)
How to resize linked images dynamically in PHP?
原标题:

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&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





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签