resize images
Posted: Wed Oct 05, 2005 10:09 pm
Jcart | Please use
Jcart | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I am accepting images into my script and then resizing them to create both a feature image (400x300px) and a thumbnail (120x90px). When creating the feature image, all goes well until an image comes in less than 400x300. At this time, I just create the feature image with the original w and h. This looks okay, but I would like the image to be 400x300. So, my question is, is there a way to put a image that is, say 96x72, onto an image that is 400x300 without changing the image proportions? In other words, the picture would remian the original size (96x72), but would be centered on an 400x300 image with a white background.
Here is my current function:Code: Select all
function createFeature($dirname,$img,$w,$h,$i)
{
$imagedata = getimagesize($img);
if($imagedata[0]>$w && $imagedata[1]>$h){
if ($w && ($imagedata[0] < $imagedata[1]))
{
$w = ($h / $imagedata[1]) * $imagedata[0];
}
else
{
$h = ($w / $imagedata[0]) * $imagedata[1];
}
} else {
$w=$imagedata[0];
$h=$imagedata[1];
}
echo "<br>img = ".$img;
echo "<br>w = ".$w;
echo "<br>h = ".$h;
echo "<br>imagedata[0] = ".$imagedata[0];
echo "<br>imagedata[1] = ".$imagedata[1];
$im2 = ImageCreateTrueColor($w,$h);
$image = ImageCreateFromJpeg($img);
imagecopyResampled ($im2, $image, 0, 0, 0, 0, $w, $h, $imagedata[0], $imagedata[1]);
ImageJpeg($im2, "$dirname\pic.jpg", 70);
}Jcart | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]