8

これが私がやりたいことの例です:

ここに画像の説明を入力

結果は次のとおりです。

function red_rectangle($img_src,$x1,$y1,$x2,$y2,$tr = 50)
{
    // Load image
    $img = imagecreatefromjpeg($img_src);
    // Transparent red
    $red = imagecolorallocatealpha($img, 255, 0, 0, $tr);
    // Draw a white rectangle
    imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red);
    // Save the image (overwrite)
    imagejpeg($img, $img_src);
    imagedestroy($img);
}
4

2 に答える 2

5

http://php.net/manual/en/function.imagefilledrectangle.phpを使用して、 http ://www.php.net/manual/en/function.imagecolorallocatealpha.phpで作成された色を渡す必要があります。

ご覧のとおり、http://php.net/manual/en/function.imagefilledrectangle.phpの例、実際に何をしたいのかを示しています。

于 2011-12-09T09:55:30.907 に答える
3
function red_rectangle($img_src,$x1,$y1,$x2,$y2,$tr = 100)
{
// Load image
$img = imagecreatefromjpeg($img_src);

// Transparent red
$red = imagecolorallocatealpha($img, 255, 0, 0, $tr);

// Draw a white rectangle
imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red);


// Don't forget to output a correct header
header('Content-Type: image/jpg');

// Save the image (overwrite)
imagejpeg($img);
imagedestroy($img);
}
$img_src = 'test.jpg';
$x1= 500;
$y1= 450;
$x2 = 370;
$y2=180;
red_rectangle($img_src,$x1,$y1,$x2,$y2);
于 2013-01-25T12:21:00.953 に答える