image width and height

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

image width and height

Post by speedy33417 »

I have the following code to display some thumb pictures

Code: Select all

echo "<img border=\"0\" src=\"http://www.mysite.com/album/pics/" . $result['picture_filename'][$currentpic] . "-thumb.jpg\" width=\"150\" height=\"113\"><br>" . "\n";
I use mostly 640x480 pictures with 150x113 thumb pictures. Key word being mostly. I just realized that my pictures could be portrait or landscape or in rare cases the proportion could be different. I'd hate to do it without width and height values, because until the picture is totally downloaded the browser doesn't keep the required space open for it, shifting the set up of my page until all the thumbs are done downloading.

How do I get these values for a picture?

Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://de2.php.net/image
getimagesize -- Get the size of an image
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post by speedy33417 »

Does that mean that there is no php code to do it without an open source application?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?:
a) php itself is open source, so the answer must be "No?" ;)
b)
http://de2.php.net/getimagesize wrote:Note: The getimagesize() function does not require the GD image library.
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Post by SpecialK »

The GD library is for use with PHP. I would call it more of an extension then another application.

I could have used it a few times already, but my manager didnt want to use it which restricted what could be done.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

SpecialK wrote:I could have used it a few times already, but my manager didnt want to use it which restricted what could be done.
Why on Earth is your manager making development decisions? Everyone should use GD whereever it's applicable. Coz it's ace. I am not biased at all. ;)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

if your manager is biased try ImageMagick instead and use it to grow horns on your manager :lol:
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post by speedy33417 »

For those of you who's looking for a code to get the size of an image this is what I ended up with:

Code: Select all

$size = getimagesize("images/pic.jpg");
$width = $size[0];
$height = $size[1];
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

That $size array is superfluous.

Code: Select all

list($width,$height) = getimagesize("images/pic.jpg");
Does the same thing.
Post Reply