是否可以使用PHP創建圖像(而不是簡單地通過HTML鏈接到它們),如果是這樣,我應該先去哪裏瞭解這樣的事情?PHP中的圖像
PHP中的圖像
回答
我更喜歡GD library - 退房the Examples,和這個例子:
<?php
header ("Content-type: image/png");
$im = @imagecreatetruecolor(120, 20)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
輸出:
imagecreatetrucolor example http://uk2.php.net/manual/en/figures/image.imagecreatetruecolor.png
是的,這是可能的。我相信有多個庫可以實現這一點。使用最廣泛的可能是ImageMagick,它實際上不是PHP專用的,但帶有適當的綁定。
另請參閱PHP documentation。
結賬GD。它包含了大量用於圖像創建,操作和審問的功能。您的PHP安裝只需使用可能的GD庫進行構建。
對於使用PHP的圖像生成像樣的教程:
GD - http://devzone.zend.com/node/view/id/1269
ImageMagick的 - http://www.sitepoint.com/article/dynamic-images-imagemagick
+1是的,確實很好的教程,謝謝! – markus 2009-04-29 23:39:55
MagickWand是針對相當不錯的,以及,非常強大。
http://www.bitweaver.org/doc/magickwand/index.html
這個片段將拍攝圖像,線制的維拉「升至」,或什麼字體可用,並且圖像刷新到瀏覽器。
$drawing_wand=NewDrawingWand();
DrawSetFont($drawing_wand,"/usr/share/fonts/bitstream-vera/Vera.ttf");
DrawSetFontSize($drawing_wand,20);
DrawSetGravity($drawing_wand,MW_CenterGravity);
$pixel_wand=NewPixelWand();
PixelSetColor($pixel_wand,"white");
DrawSetFillColor($drawing_wand,$pixel_wand);
if (MagickAnnotateImage($magick_wand,$drawing_wand,0,0,0,"Rose") != 0) {
header("Content-type: image/jpeg");
MagickEchoImageBlob($magick_wand);
} else {
echo MagickGetExceptionString($magick_wand);
}
你可以使用它的不同功能的gd庫。 並與代碼中創建良好形象
header("Content-Type: image/png");
//try to create an image
$im = @imagecreate(800, 600)
or die("Cannot Initialize new GD image stream");
//set the background color of the image
$background_color = imagecolorallocate($im, 0xFF, 0xCC, 0xDD);
//set the color for the text
$text_color = imagecolorallocate($im, 133, 14, 91);
//adf the string to the image
imagestring($im, 5, 300, 300, "I'm a pretty picture:))", $text_color);
//outputs the image as png
imagepng($im);
//frees any memory associated with the image
imagedestroy($im);
顏色爲負面
if(!file_exists('dw-negative.png')) {
$img = imagecreatefrompng('dw-manipulate-me.png');
imagefilter($img,IMG_FILTER_NEGATE);
imagepng($img,'db-negative.png');
imagedestroy($img);
}
- 1. 居中圖像php
- 2. PHP中的圖像顯示
- 3. PHP中的動態圖像
- 4. PHP中的圖像處理
- 5. Watermark Outside PHP中的圖像?
- 6. 驗證PHP中的圖像
- 7. PHP中的圖像顯示
- 8. PHP中的圖像壓縮?
- 9. PHP的圖像代理中斷PHP 5
- 10. 圖像邊界圖像php
- 11. 用DIV與PHP中的圖像截圖
- 12. Facebook的PHP圖像
- 13. PHP的preg_match圖像
- 14. 我如何在php中顯示圖像中的圖像
- 15. 在php中顯示圖像
- 16. 在php中上傳圖像
- 17. 在php中創建圖像
- 18. 在PHP中旋轉圖像
- 19. 在php中修剪圖像
- 20. 在圖像中切角PHP
- 21. PHP imagecreatetruecolour中心圖像
- 22. 在PHP中隱藏圖像
- 23. 在PHP中裁剪圖像
- 24. 在php中編輯圖像
- 25. 在PHP中存儲圖像
- 26. php xpath圖像
- 27. PHP - 圖像
- 28. PHP圖像庫
- 29. 圖像從PHP
- 30. 由js或php中的瓷磚圖像組成的圖像?
你應該總是嘗試使用header()函數在最後時刻可能的(如,在imagepng前()功能可按)。現在的方式是,如果php腳本「無法初始化新的GD圖像流」,瀏覽器將嘗試將其解釋爲gif,因此它不會被理解。 – stalepretzel 2008-09-07 00:25:07