2011-02-18 36 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