I use php imagecolorallocate() and imagefill() in an image upload to also let png files have a white background (like in this post: imagescreatetruecolor with a white background)
Here is the part of the code it concerns:
//create new images
$nimgac_0=imagecreatetruecolor($maxw_img0,$maxh_img0); //img1
$nimgac_1=imagecreatetruecolor($maxw_img1,$maxh_img1); //img2
$nimgac_2=imagecreatetruecolor($maxw_img2,$maxh_img2); //img3
$nimgaa_0=imagecolorallocate($nimgac_0,255,255,255);
$nimgaa_1=imagecolorallocate($nimgac_1,255,255,255);
$nimgaa_2=imagecolorallocate($nimgac_2,255,255,255);
$nimga_0=imagefill($nimgac_0,0,0,$nimgaa_0);
$nimga_1=imagefill($nimgac_1,0,0,$nimgaa_1);
$nimga_2=imagefill($nimgac_2,0,0,$nimgaa_2);
//create images from temp folder
if ($type=="jpg") {
$nimgb_0=imagecreatefromjpeg("../imga/".$_FILES['file']['name']);
$nimgb_1=imagecreatefromjpeg("../imga/".$_FILES['file']['name']);
$nimgb_2=imagecreatefromjpeg("../imga/".$_FILES['file']['name']);
}
if ($type=="png") {
$nimgb_0=imagecreatefrompng("../imga/".$_FILES['file']['name']);
$nimgb_1=imagecreatefrompng("../imga/".$_FILES['file']['name']);
$nimgb_2=imagecreatefrompng("../imga/".$_FILES['file']['name']);
}
imagecopyresized($nimga_0,$nimgb_0,0,0,0,0,$nwidth_0,$nheight_0,$width,$height);
imagecopyresized($nimga_1,$nimgb_1,0,0,0,0,$nwidth_1,$nheight_1,$width,$height);
imagecopyresized($nimga_2,$nimgb_2,0,0,0,0,$nwidth_2,$nheight_2,$width,$height);
imagejpeg($nimga_0,"../imga/".$_FILES['file']['name'],80);
imagejpeg($nimga_1,"../imga/".$imgname_1,80);
imagejpeg($nimga_2,"../imga/".$imgname_2,80);
but I get this warnings:
Warning: imagecopyresized() expects parameter 1 to be resource, boolean given in ... on line 114
Warning: imagecopyresized() expects parameter 1 to be resource, boolean given in ... on line 115
Warning: imagecopyresized() expects parameter 1 to be resource, boolean given in ... on line 116
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in ... on line 117
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in ... on line 118
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in ... on line 119
Warning: imagedestroy() expects parameter 1 to be resource, boolean given in ... on line 120
Warning: imagedestroy() expects parameter 1 to be resource, boolean given ... on line 121
Warning: imagedestroy() expects parameter 1 to be resource, boolean given in ... on line 122
Same code without the immagecolorallocate() and imagefill() works perfectly fine. However, I cannot find any error or any difference to the above posted code.
Anyone any ideas? Thank you in advance!
PS: I want to save all images as jpg, that's why I convert pngs to jpg too.
EDIT 3 (sorry, I got confused):
print_r(getimagesize($_FILES['file']['tmp_name']));
returns
Array ( [0] => 354 [1] => 332 [2] => 2 [3] => width="354" height="332" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
so, everything is fine with if($size['2']==3) {$type="jpg";}
...