By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,433 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

PHP native graphics/image function

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
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.