我想創建一個透明png image.this是一個EAN-13條碼圖像,我想在png格式中透明。我在創建透明png時遇到了麻煩。它目前有一個白色的背景。php GD爲ean13條形碼創建一個透明PNG圖像
任何人都可以指向正確的方向。這是到目前爲止的代碼...
include('./php-barcode.php');
$font = './NOTTB___.TTF';
$fontSize = 16; // GD1 in px ; GD2 in point
$marge = 10; // between barcode and hri in pixel
$x = 80; // barcode center
$y = 80; // barcode center
$height = 50; // barcode height in 1D ; module size in 2
$width = 2; // barcode height in 1D ; not use in 2D
$angle = 0; // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
$code = $codevalue; // barcode, of course ;)
$type = $typevalue; //
function drawCross($im, $color, $x, $y){
imageline($im, $x - 10, $y, $x + 10, $y, $color);
imageline($im, $x, $y- 10, $x, $y + 10, $color);
}
$im = imagecreatetruecolor(150, 150);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
$white = ImageColorAllocate($im,0xff,0xff,0xff);
imagefilledrectangle($im, 0, 0, 150, 150, $white);
$data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);
if (isset($font)){
$box = imagettfbbox($fontSize, 0, $font, $data['hri']);
$len = $box[2] - $box[0];
Barcode::rotate(-$len/2, ($data['height']/2) + $fontSize + $marge, $angle, $xt, $yt);
imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $black, $font, $data['hri']);
}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
「這是我的代碼到目前爲止...」 - **我的**代碼? https://github.com/jbdemonte/barcode/blob/master/php/sample%20php/sample-gd.php。應該是「我發現有人在線代碼,根據我的需要調整它」 –