graham23s Posted March 31, 2008 Share Posted March 31, 2008 Hi Guys, my website is mainly white , but when i create thumbnails of some products there is a black background behind them (i take it GD makes it black by default) is there a way i can change the background colour to white at all? function resize_image($upload_directory, $new_image_name) { // original image location // $original_image = $upload_directory; // set up a canvas my babies // $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); // do some math for the scaled image // $image_ratio = $image_width / $image_height; // new sizes // $new_image_width = 65; $new_image_height = ($image_height/$image_width) * 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"); } } thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/98794-gd-library-help/ Share on other sites More sharing options...
rhodesa Posted March 31, 2008 Share Posted March 31, 2008 Immediately after you 'create the canvas', fill it with a white background by using: $background = imagecolorallocate($canvas, 255, 255, 255); Link to comment https://forums.phpfreaks.com/topic/98794-gd-library-help/#findComment-505811 Share on other sites More sharing options...
Barand Posted March 31, 2008 Share Posted March 31, 2008 That will work with a palletted image created with imagecreate() but not true color. You need an explicit fill command with those. However, the background should be completely overwritten by the copy anyway. Have you tried allocating a transparent color to the new image. Link to comment https://forums.phpfreaks.com/topic/98794-gd-library-help/#findComment-505820 Share on other sites More sharing options...
rhodesa Posted March 31, 2008 Share Posted March 31, 2008 Good catch Barand... So, immediately after you 'create the canvas', fill it with a white background by using: $white = imagecolorallocate($canvas, 255, 255, 255); imagefill($canvas, 0, 0, $white); Link to comment https://forums.phpfreaks.com/topic/98794-gd-library-help/#findComment-505824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.