zuk1
zuk1

Reputation: 18389

PHP Pull Image And Display

I have a PHP file which I have used mod rewrite to make a .jpg extension. I want to grab an image from a url

example: http://msn.com/lol.gif

take the data and then display it in my .jpg with jpeg headers, so as far as the user is concerned it is a normal image. Is this possible and if so can anyone give me some pointers?

Upvotes: 1

Views: 428

Answers (3)

Luis Melgratti
Luis Melgratti

Reputation: 12060

using php GD library:

header('Content-type: image/jpeg');
$pic = imagecreatefromgif($url);
Imagejpeg($pic);
ImageDestroy($pic);

Using Imagick Library:

header('Content-type: image/jpeg');
$image = new Imagick($url);
$image->setImageFormat( "jpg" );
echo $image;

Upvotes: 2

Tim Lytle
Tim Lytle

Reputation: 17624

Depending on you needs (do you need to manipulate the image?), you can just open the remote file and output it to the browser.

Check out the documentation on the readfile function and the http wrapper.

Upvotes: 0

alxp
alxp

Reputation: 6341

If you use a combination of curl and PHP's image manipulation methods, which you can learn about here, will get you to what you are looking for.

Upvotes: 2

Related Questions