Я запускаю этот код, который создает прозрачный png размером 640x1136 и рекламирует белый ящик с черным текстом в верхнем левом углу.PHP сделать прозрачным png с текстом
При запуске кода PNG создается, но это возвращается как выход
?PNG
IHDR?z??
IDATx???1 ?Om
??>g???IEND?B`?
бывают любой один, чтобы узнать, что это такое?
В то же время, может ли кто-нибудь подумать о более коротком пути?
$im = imagecreatetruecolor(640, 1136);
imagesavealpha($im, true);
$color = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $color);
imagepng($im);
imagesavealpha($im, true); // important to keep the png's transparency
$text_color = imagecolorallocate($im, 0, 0, 0);
$width = 640; // the width of the image
$height = 1136; // the heighst of the image
$font_size = 20; // font size
$box_color = imagecolorallocate($im, 255, 255, 255);
// Set the offset x and y for the text position
$offset_x = 0;
$offset_y = 20;
$dims = imagettfbbox($font_size, 0, $font, $text);
$text_width = $dims[4] - $dims[6] + $offset_x;
$text_height = $dims[3] - $dims[5] + $offset_y;
// Add text background
imagefilledrectangle($im, 0, 0, $text_width, $text_height, $box_color);
// Add text
imagettftext($im, $font_size, 0, $offset_x, $offset_y, $text_color, $font,$text);
imagepng($im, $img, 0);
Проблема сохраняется. –
Убедитесь, что вы помещаете вызов 'header()' в верхней части вашего скрипта. – uri2x
Проблема по-прежнему сохраняется –