I have been working on a Photo Library project (I have taken over from the original developers). I’ve been working on this a couple of weeks now and I think I hve gone <strike>snow</strike> code blind.
I have the following code but it doesn’t seem to be capable of creating images of a fixed width (with a dynamic height).
$dest is destination (eg. /home/path/to/images/folder)
$src is the source path.
$maxW and $maxH are the maximum width and height respectively (I guess you already knew this, but I added for the sake of clarity).
try {
$i = new Resize("./img/back.s1.png");
# I load the image via createimagefromstring($data) instead of jpeg|png|gif
# that way I can call imagejpeg|imagepng|imagegif whenever.
imagejpeg($i->byHeight(100), "./img/thumb/back.s1.jpg", 100);
} catch (Exception $e) {
echo $e->getMessage();
}
What happens when the extension is .JPEG? That would have to be -4, not -3
$frags = explode(".", $src);
$ext = end($frags);
# the way i go
if (preg_match("/(\\.jpeg|jpg|png|gif)$/i", strtolower($image), $matches)) {
#checked to see if the supplied filepath is in fact an image.
$ext = $matches[0]
} else {
echo "Not an image.";
}