<?php
$imagesize = getimagesize($modx->config['base_path'].'Images/Sunset.jpg');
$width = $imagesize[0]; // width
$height = $imagesize[1]; // height
$type = $imagesize[2]; // One of the IMAGETYPE_XXX constants indicating the type of the image.
$size_str = $imagesize[3]; // A text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
$mime_type = $imagesize['mime']; // The correspondant MIME type of the image. This information can be used to deliver images with correct the HTTP Content-type header.
$channels = $imagesize['channels']; // 3 for RGB pictures and 4 for CMYK pictures.
$bits = $imagesize['bits']; // The number of bits for each color.
?>
You could of course find out those yourself by doing a test and printing the array from the getimagesize function, eg:
<?php
print_r(getimagesize($modx->config['base_path'].'Images/Sunset.jpg'));
?>
That usually get’s you going when you don’t know exactly what kind of data the function outputs or cannot understand from the docs. You can also print_r objects in PHP.
EDIT: Also great thing about this function is that it doesn’t require GD to work.
"He can have a lollipop any time he wants to. That's what it means to be a programmer."
It would be better to store the size to a DB and retrieve from there (unless if your DB server is very slow due to shared environments or something). The getimagesize function needs to access file system and parse the image file header, so obviously it would be faster to just query the size from DB.
That being said, MaxiGallery snippet doesn’t save the sizes of the pictures to a DB, it get’s them by using getimagesize on each page load. It’s bad, I know, but it’s not so slow that I would fix it anytime soon.
But I’d definitely suggest to save the sizes to DB.
"He can have a lollipop any time he wants to. That's what it means to be a programmer."
Quote from: doze at Oct 12, 2008, 03:23 PM
But I’d definitely suggest to save the sizes to DB.
Or call your snippet cached so that it only needs to check the image sizes the first time it’s executed.