2012-05-24 6 views
1
$background = imagecreatetruecolor(709,709); 

$whiteBackground = imagecolorallocate($background, 255, 255, 255); 

imagecopyresampled($whiteBackground, $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height); 

ImageJpeg ($background,"$path/$newName.$file_ext", 85); 

흰색 바탕에 GD로 이미지를 만들려고합니다. 그러나 운이 없다, 무엇을 잘못하고있는 어떤 아이디어? 나는 마법사가 whiteBackground 비트를 꺼내면 펌프가 빠져 나간다는 것을 안다. 그래서 이미지 코드를 만드는 데 아무 문제가 없다.이미지 GD - 흰색 배경

감사

답변

2

을 필요가 없습니다 있도록

$new_img는, 그것이 내가 생각 흰색 배경해야한다 코드에 존재하고 기본적으로 imagecreatetruecolor();

으로 생성 할 필요가 없습니다 할당 된 흰색 색으로 $background에.

으로 표시되며 [색상]에서 [이미지]로 채워지지 않을 수 있으므로 [이미지]에서 [이미지]로 변경해야합니다.

$background = imagecreatetruecolor(709,709); 
$whiteBackground = imagecolorallocate($background, 255, 255, 255); 
imagefill($background,0,0,$whiteBackground); 
imagecopyresampled($background, $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height); 
ImageJpeg ($background,"$path/$newName.$file_ext", 85); 
0

나는이

$background = imagecreatetruecolor(709,709); 
$whiteBackground = imagecolorallocate($background, 255, 255, 255); 
imagefill($background,0,0,$whiteBackground); 
$use_new_img = imagecreatefromjpeg($new_img); 
imagecopyresampled($whiteBackground,$use_new_img,(709-$imageWidth)/2, (709-$imageHeight)/2, 0, 0,$imageWidth,$imageHeight,$width,$height); 
ImageJpeg ($background,"$path/$newName.$file_ext", 85); 
작동 희망