0
我正在運行此代碼,它創建一個640x1136透明PNG,並在左上角廣告一個黑色文本的白色框。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
問題仍然存在 –