2011-02-18 38 views

回答

1

在PHP中使用GD扩展可能会更容易。具体来说,imagesetstyle()函数用于设置折线,imageline()用于绘制直线。

此示例加载图像并在其上绘制虚线。你应该能够适应你的需求。

<?php 
$im = imagecreatefromjpeg('/your/file.jpg'); 
$w = imagecolorallocate($im, 255, 255, 255); 
$red = imagecolorallocate($im, 255, 0, 0); 

/* Draw a dashed line, 5 red pixels, 5 white pixels */ 
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w); 
imagesetstyle($im, $style); 
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED); 

imagejpeg($im, '/path/to/save.jpg'); 
imagedestroy($im); 
?> 
+0

如果我得到一个PNG文件会怎么样? imagecreatefrompng?它工作正确吗?关于GIF呢?谢谢。 – 2011-02-21 21:36:03