Я пытаюсь сделать прозрачное изображение с черной формой.
Затем используйте IMG_FILTER_GAUSSIAN_BLUR, чтобы немного размыть форму.
Проблема в том, как только я применяю размытие Фильтр, все изображение теряет свои прозрачные пиксели, и все изображение становится черным.
Поэтому, когда я копирую окончательное изображение на белом изображении, вместо того, чтобы получить белое изображение с некоторой размытой черной формой, я получаю полностью черное изображение ...
<?php
$image= imagecreatetruecolor( 200, 200 );
imagealphablending($image, false);
imagesavealpha($image, true);
$trans= imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefill( $image, 0,0, $trans);
$black= imagecolorallocatealpha( $image, 0,0,0,0 );
imagefilledrectangle( $image, 50,50, 150,150, $black );
//header("Content-Type: image/png"); imagepng($image); exit();
//above is our basic image
//now I gaussian blur this
imagefilter( $image, IMG_FILTER_GAUSSIAN_BLUR );
/*
//now get left most pixel which should be 127.127.127.127
$rgb= imagecolorat( $image, 0,0 );
$c= imagecolorsforindex($image, $rgb);
echo $c['red']."/".$c['green']."/".$c['blue']."/".$c['alpha']."<br>";
//should still be 255/255/255/127
//instead is 0/0/0/0 now...
*/
//copy this on a white image
//everything becomes black...
//this is the problem, all transparent pixels are lost after applying blur
$w=imagesx($image);
$h=imagesy($image);
$img = imagecreatetruecolor($w, $h);
imagesavealpha($img, true);
$white= imagecolorallocatealpha($img, 255, 255, 255, 0);
imagefill($img, 0,0, $white);
imagecopyresampled( $img, $image, 0,0, 0,0, $w,$h, $w,$h );
//this will output a black image.
//instead it should have given a white image with a blurred "black" shape on it.
//comment the imagefilter line to see what should appear (not blurred)
//I want blurred
header("Content-Type: image/png"); imagepng($img); exit();