Hi everybody,
I just started with PHP and MySQL a couple of month ago, am making progress but still _so_ much to learn... Anyway, so now I am trying to build one of them fancy image galleries - you know - one of those where the user can click on a thumbnail on the "select" frame and the corresponding enlarged image would appear in the "details" frame. So far so good, works splendid and all - even with a MySQL database integrated and so forth. Now the only problem left is this: The images in the gallery have different proportions (3x4 and 4x3 respectively, depending on how my boss had turned his camera while taking them) and based on this the HTML of the detail frame should be different (e.g.: the small comments from the database should be on the bottom of the image for 3x4 images and on the right side for 4x3 images). I thought the easiest way to implement this would be read out the image proportions to build a small if loop of the kind:
if ($height > $width) { //some HTML}
else { //some othe HTML}
Now the only challenge I am unable to overcome is of how to convert the array that I get from getimagesize into variable ($width and $height respectively). Can anybody help me with this?
Regards,
Napper
Getimagesize Problem
Moderator: General Moderators
Somebody showed me how it works by now. So the appropriate code works like this:
And the reason why is explained here:

Code: Select all
$imagesize = getimagesize('imageFilename');
$width = $imagesizeї0];
$height = $imagesizeї1];
if ($height > $width)
{
# some HTML
}
else
{
# some HTML
}Splendid! And own he goes....Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF. These values correspond to the IMAGETYPE constants that were added in PHP 4.3. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
you might wanna get used to the php tag. it's better than the code tage... also, i can cut that down.... if the perosn isn't here you should get him to join. sounds like he'd be helpful. me.. i just saw this thread. i had the same issue earlier
Code: Select all
<?php list($width, $height)=getimagesize('imageFilename'); ?>I am not sure what you mean with getting used to the PHP tag instead of the of the code tag? As for the the piece of code you gave me: I was not familar with the list function as of yet so I did some reading on it. I think I understand of how it works except for one thing: how does PHP know which of the values in the getimagsize array it ought to assign to $width and which to $height? Does it have something to do with the order of values ([0] being width and [1] being height)? Would it work if I'd rephrase the whole thing to:
or something like that?
Either way, thanks for the help. This language becomes more fascinating every day.
Napper
Code: Select all
<?php list($no, $clue)=getimagesize('imageFilename'); ?>Napper