graham23s
04-23-2008, 08:20 PM
Hi Guys,
in my thumbnail function i wanted the canvas background color to be white, by default it's black and throws my site out of whack, can anyone show me how to change it all?
<?php
function resize_image($upload_directory, $new_image_name)
{
// original image location //
$original_image = $upload_directory;
// set up a canvas sizes //
$canvas_width = 65;
$canvas_height = 65;
// create the canvas //
$canvas = imagecreatetruecolor($canvas_width, $canvas_height);
// get the image height and width //
list($image_width, $image_height) = getimagesize($upload_directory);
// RATIO CALCULATION //
$ratio = $image_width / $image_height;
if ($ratio > 1 )
{
$new_image_width = 65;
$new_image_height = 65 / $ratio;
} else {
$new_image_width = (float) 65 * $ratio;
$new_image_height = 65;
}
// store original into memory //
$original_image = imagecreatefromjpeg($original_image);
// copy the original image onto the canvas canvas, original and top/left co-ordinates //
imagecopyresampled($canvas, $original_image, 0,0,0,0, $new_image_width, $new_image_height, $image_width, $image_height);
// thumbnail name //
$new_thumbnail_name = "thumb-$new_image_name";
// save the thumbnail in the thumbs folder //
if(imagejpeg($canvas, "products/thumbnails/$new_thumbnail_name", 100))
{
return("$new_thumbnail_name");
}
// destroy the images in memory //
imagedestroy($original_image);
imagedestroy($canvas);
}
?>
Thanks for any help guys
Graham
in my thumbnail function i wanted the canvas background color to be white, by default it's black and throws my site out of whack, can anyone show me how to change it all?
<?php
function resize_image($upload_directory, $new_image_name)
{
// original image location //
$original_image = $upload_directory;
// set up a canvas sizes //
$canvas_width = 65;
$canvas_height = 65;
// create the canvas //
$canvas = imagecreatetruecolor($canvas_width, $canvas_height);
// get the image height and width //
list($image_width, $image_height) = getimagesize($upload_directory);
// RATIO CALCULATION //
$ratio = $image_width / $image_height;
if ($ratio > 1 )
{
$new_image_width = 65;
$new_image_height = 65 / $ratio;
} else {
$new_image_width = (float) 65 * $ratio;
$new_image_height = 65;
}
// store original into memory //
$original_image = imagecreatefromjpeg($original_image);
// copy the original image onto the canvas canvas, original and top/left co-ordinates //
imagecopyresampled($canvas, $original_image, 0,0,0,0, $new_image_width, $new_image_height, $image_width, $image_height);
// thumbnail name //
$new_thumbnail_name = "thumb-$new_image_name";
// save the thumbnail in the thumbs folder //
if(imagejpeg($canvas, "products/thumbnails/$new_thumbnail_name", 100))
{
return("$new_thumbnail_name");
}
// destroy the images in memory //
imagedestroy($original_image);
imagedestroy($canvas);
}
?>
Thanks for any help guys
Graham