470,870 Members | 1,409 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

PHP native graphics/image function

How do I find the information about an image, e.g. its dimension, whether
it's jpg, tiff, bmp, gif, etc using the
native PHP function? I know that we can do it by using the imagemagick, but
perhaps some webhosting site does not have that installed. Thanks
Jul 17 '05 #1
3 3794
Continue ...

Once we determine the type of the image, it's size, then I'd like to
resize(proportionately), then convert them to, say, a jpg file. And, then
display them. Thanks

"Ruby Tuesday" <ru*********@yahoo.com> wrote in message
news:c4*************@ID-205437.news.uni-berlin.de...
How do I find the information about an image, e.g. its dimension, whether
it's jpg, tiff, bmp, gif, etc using the
native PHP function? I know that we can do it by using the imagemagick, but perhaps some webhosting site does not have that installed. Thanks

Jul 17 '05 #2
"Ruby Tuesday" <ru*********@yahoo.com> wrote in message
news:c4*************@ID-205437.news.uni-berlin.de...
How do I find the information about an image, e.g. its dimension, whether
it's jpg, tiff, bmp, gif, etc using the
native PHP function? I know that we can do it by using the imagemagick, but perhaps some webhosting site does not have that installed. Thanks


You might start with the manual:
http://us2.php.net/manual/en/ref.image.php

Here's a script you can tinker with to get started:

<?PHP
// Capture GET parameters
$source_file = $_GET['image'];
$new_width = $_GET['width'];
$new_height = $_GET['height'];

// Open source image file and get image dimensions
$old_image = imagecreatefromjpeg($source_file);
$old_width = imagesx($old_image);
$old_height = imagesy($old_image);

// Create blank image
$new_image = imagecreatetruecolor($new_width,$new_height);

// Copy and resize old image into new image resource and then return to
browser

imagecopyresized($new_image,$old_image,0,0,0,0,$ne w_width,$new_height,$old_w
idth,$old_height);
header('Content-type: image/jpeg');
imagejpeg($new_image);
?>

Called with:
<img src="imagethumb.php?image=test.jpg&width=100&heigh t=75" ... />

Steve
--
Steven C. Gallafent - The Computer Guy
st***@compguy.com - http://www.compguy.com/

Have you tried http://www.pairusers.com/? I did. It's nifty!
Jul 17 '05 #3
The getimagesize() function will determine the size of any GIF, JPG, PNG,
SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file
and return the dimensions along with the file type and a height/width text
string to be used inside a normal HTML IMG tag.

http://ca.php.net/function.getimagesize

Savut

"Ruby Tuesday" <ru*********@yahoo.com> wrote in message
news:c4*************@ID-205437.news.uni-berlin.de...
How do I find the information about an image, e.g. its dimension, whether
it's jpg, tiff, bmp, gif, etc using the
native PHP function? I know that we can do it by using the imagemagick,
but
perhaps some webhosting site does not have that installed. Thanks


Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Martin Zenkel | last post: by
5 posts views Thread by Charles A. Lackman | last post: by
15 posts views Thread by dgk | last post: by
1 post views Thread by Frijoles | last post: by
6 posts views Thread by Blasting Cap | last post: by
6 posts views Thread by jt | last post: by
9 posts views Thread by DaveL | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.