Michael Cheal
Michael Cheal

Reputation: 179

How do I directly display an image using PHP?

I have a question about displaying images in PHP. I need to have a PHP file display as JUST an image, as opposed to an image embedded in a web page, as if you had browsed to the JPEG image directly. The reason that I need it to be a PHP page as opposed to actually browsing to the image is that I need to resize the image before it is delivered. It would be easiest to use an image directly because that way I can display the image in a desktop application more easily. Is there any way to do this? Thanks!

Upvotes: 6

Views: 10388

Answers (3)

Cobra_Fast
Cobra_Fast

Reputation: 16061

<?php
header('Content-Type: image/jpeg');
readfile('path/to/image.jpeg');

Upvotes: 9

Digix
Digix

Reputation: 64

Choose the correct header :

header("Content-type: image/png"); 

And use php gd to change the image size : http://php.net/manual/fr/book.image.php

Upvotes: 0

Rob Allen
Rob Allen

Reputation: 17709

You need to set the header Content-Type property to be the correct image type. See this link for the some examples.

http://www.electrictoolbox.com/image-headers-php/

Upvotes: 0

Related Questions