Как сохранить png с прозрачностью?

В папке лежат изображения png с прозрачным фоном
они склеиваются скриптом в одно изображение
Но при сохранении прозрачность пропадает

$images = glob("img/test/*.png");
asort($images);


$imgWidth = 240;
$imgHeight = 240;

$rows = 1;
$cols = count($images);

$bgWidth = $imgWidth * $cols;
$bgHeight = $imgHeight * $rows;

$im = imagecreatetruecolor($bgWidth, $bgHeight);

$f=0;

for($j=0; $j<$cols; $j++){
    for($i=0; $i<$rows; $i++){
        $src = imagecreatefrompng($images[$f]);
      
        imagecopy($im, $src, $j * $imgWidth, $i * $imgHeight, 0, 0, $imgWidth, $imgHeight);

        $f++; 
    }
}

header('Content-Type: image/png');

imagepng($im);

imagedestroy($im);
imagedestroy($src);
  • Вопрос задан
  • 220 просмотров
Решения вопроса 1
@fortoster82 Автор вопроса
$im = imagecreatetruecolor($bgWidth, $bgHeight);

$transparent = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $transparent);

imagesavealpha($im, true); // save alphablending setting (important);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы