例,我在測試一個簡單產生圖形時執行個體
Example #1 建立一個新的 GD 映像流並輸出映像
| 代碼如下 |
複製代碼 |
<?php header("Content-type: image/png"); $im = @imagecreate(100, 50) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); imagepng($im); imagedestroy($im); ?> |
運行機制時提示
Fatal error: Call to undefined function imagecreate() .....
後面突然想起沒開啟gd庫了
這一問題是:GD庫沒有正確安裝或配置,解決方案:
在php.ini中找到
;extension=php_gd2.dll
去掉前邊的;
然後將php目錄中的ext下的php_gd2.dll拷入c:/windows/system32和c:/windows目錄下,重啟IIS或者apache就OK了.
centos中gd庫開啟
具體操作只有2個命令如下:
運行線上安裝帶GD庫的PHP的命令:
| 代碼如下 |
複製代碼 |
| yum -y install php-gd |
重新啟動apachce服務以使安裝後的GD庫生效
| 代碼如下 |
複製代碼 |
| /etc/rc.d/init.d/httpd restart(service httpd restart) |
gd的安裝路徑
/etc/php.d/gd.ini <---這個是讓php支援gd的哦,這個是CentOS的特色之一,不用把全部東西都寫在php.ini這個檔案裡,只是需要把*.ini檔案寫在/etc/php.d/檔案夾就可以了,系統會自動把這個目錄下的*.ini讀入php.ini
/usr/lib/php/modules/gd.so <----這個就是gd的檔案啦
關於需要使用GD庫的圖形處理函數還有如下
gd_info
getimagesize
getimagesizefromstring
image_type_to_extension
image_type_to_mime_type
image2wbmp
imageaffine
imageaffinematrixconcat
imageaffinematrixget
imagealphablending
imageantialias
imagearc
imagechar
imagecharup
imagecolorallocate
imagecolorallocatealpha
imagecolorat
imagecolorclosest
imagecolorclosestalpha
imagecolorclosesthwb
imagecolordeallocate
imagecolorexact
imagecolorexactalpha
imagecolormatch
imagecolorresolve
imagecolorresolvealpha
imagecolorset
imagecolorsforindex
imagecolorstotal
imagecolortransparent
imageconvolution
imagecopy
imagecopymerge
imagecopymergegray
imagecopyresampled
imagecopyresized
» imagecreate
imagecreatefromgd2
imagecreatefromgd2part
imagecreatefromgd
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromstring
imagecreatefromwbmp
imagecreatefromwebp
imagecreatefromxbm
imagecreatefromxpm
imagecreatetruecolor
imagecrop
imagecropauto
imagedashedline
imagedestroy
imageellipse
imagefill
imagefilledarc
imagefilledellipse
imagefilledpolygon
imagefilledrectangle
imagefilltoborder
imagefilter
imageflip
imagefontheight
imagefontwidth
imageftbbox
imagefttext
imagegammacorrect
imagegd2
imagegd
imagegif
imagegrabscreen
imagegrabwindow
imageinterlace
imageistruecolor
imagejpeg
imagelayereffect
imageline
imageloadfont
imagepalettecopy
imagepalettetotruecolor
imagepng
imagepolygon
imagepsbbox
imagepsencodefont
imagepsextendfont
imagepsfreefont
imagepsloadfont
imagepsslantfont
imagepstext
imagerectangle
imagerotate
imagesavealpha
imagescale
imagesetbrush
imagesetinterpolation
imagesetpixel
imagesetstyle
imagesetthickness
imagesettile
imagestring
imagestringup
imagesx
imagesy
imagetruecolortopalette
imagettfbbox
imagettftext
imagetypes
imagewbmp
imagewebp
imagexbm
iptcembed
iptcparse
jpeg2wbmp
png2wbmp