0

我在使imagecopy函数在 PHP 中工作时遇到问题。

我什至不知道从哪里开始调试;图像对我来说是一种新的水果。

我有问题的部分:

imagecopy($png, $bgr, 0, 0, 0, 0, 0, 0, $width, $height);
        imagecopy($png, $bgr, 0, 0, 0, 0, 0, 0, imagesx($pbuble), imagesy($pbuble));

完整代码(我的计划是先复制在上面$png <- $bgr <- $pbuble):

<?php
//Check for correct GET variables
if (is_numeric($_GET['max']) AND is_numeric($_GET['val'])) {
    $max = $_GET['max'];
    $val = $_GET['val'];
} else {return false;}

    //Create empty placeholder
    $png = imagecreate(380, 37);
    $black = imagecolorallocate($png, 0, 0, 0);
    imagecolortransparent($png, $black);

    //Create background image with transparency
    $bgr = imagecreatefrompng("progress-bgr.png");
        imageAlphaBlending($bgr, true);
        imageSaveAlpha($bgr, true);

    //Calculate width of progress bar atm
        $width = imagesx($bgr);
        $height = imagesy($bgr);

    $pb_width = $val * $width / $max;

    //Percentage buble
    $pbuble = imagecreatefrompng("percentage-bubble.png");
        imageAlphaBlending($pbuble, true);
        imageSaveAlpha($pbuble, true);

        $perct = $val * 100 / $max;
        $txt = $perct . "%";
        $txt_color = imagecolorallocate($pbuble, 255, 255, 255);
        $font = "dejavusans-webfont.ttf";
        $font_size = 7;

        $bbox = imagettfbbox($font_size, 0, $font, $txt);

        $x = $bbox[0] + (imagesx($pbuble) / 2) - ($bbox[4] / 2);
        //$y = $bbox[1] + (imagesy($pbuble) / 2) - ($bbox[5] / 2);

    imagettftext($pbuble, $font_size, 0, $x, 14, $txt_color, $font, $txt);

    //
    imagecopy($png, $bgr, 0, 0, 0, 0, 0, 0, $width, $height);
    imagecopy($png, $bgr, 0, 0, 0, 0, 0, 0, imagesx($pbuble), imagesy($pbuble));


//Output image
header("Content-type: image/png");
imagepng($png);
//
imagedestroy($png);
imagedestroy($bgr);
imagedestroy($pbuble);
?> 
4

1 回答 1

0

愚蠢的我 :)

imagecopy($png, $bgr, 0, 0, 0, 0, 0, 0, $width, $height);

有两个额外的参数。应该:

imagecopy($png, $bgr, 0, 0, 0, 0, $width, $height);
于 2013-04-13T16:53:03.080 回答