Hy, i have a little piece of code here wich creates thubnail from a jpg image and it keeps its aspect ratio, and the remaining space is filled with black, but the thing is i want to fill that space with transparent or white, cause black looks very ugly on my site. heres the piece of code, you can see i have tried with imagefill function but still doesnt work if(isset($_POST['Submit'])){ $thumbsize = 90; // dimensiunea thumbnail-ului $filedir = 'pics/'; // directorul imaginii pe care o vei uploada $thumbdir = 'pics/'; // directorul imaginii thumbnail $prefix = 'small_'; // prefixul adaugat imaginii $width = 90; $height = 90; $maxfile = '2000000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])){ $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); // Get new dimensions list($width_orig, $height_orig) = getimagesize($prod_img); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $destimg=ImageCreateTrueColor($thumbsize, $thumbsize) or die('Problem In Creeare thumbnail'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem la deschiderea imaginii sursa'); imagefill($destimg, 0, 0, $alb); ImageJPEG($destimg, null, 93) or die('Problema la salvare'); ImageCopyResampled($destimg,$srcimg,-($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig) or die('Problem In resizing'); $alb = imagecolorallocate($destimg, 255, 255, 255); imagedestroy($destimg); Code (markup): I have attached a thumb so you can see the how it looks like now. By the way sorry for my bad english.
Try putting $alb before the imagefill: $destimg=ImageCreateTrueColor($thumbsize, $thumbsize) or die('Problem In Creeare thumbnail'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem la deschiderea imaginii sursa'); [b] $alb = imagecolorallocate($destimg, 255, 255, 255); imagefill($destimg, 0, 0, $alb);[/b] ImageJPEG($destimg, null, 93) or die('Problema la salvare'); ImageCopyResampled($destimg,$srcimg,-($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig) or die('Problem In resizing'); imagedestroy($destimg); Code (markup):
Nope it doesnt work, how can i convert them to png ? or other ways of filling with white or transparent ?
before imagefill function add this line $alb= ImageColorAllocate($image, 255, 255, 255); Regards Alex