php提示Fatal error: Call to undefined function imagecreate()


在php中imagecreate函數是一個圖形處理函數,主要用於新建一個基於調色板的圖像了,然后在這個基礎上我們可以創建一些圖形數字字符之類的,但這個函數需要GD庫支持,如果沒有開啟GD庫使用時會

undefined

 

 

在php中imagecreate函數是一個圖形處理函數,主要用於新建一個基於調色板的圖像了,然后在這個基礎上我們可以創建一些圖形數字字符之類的,但這個函數需要GD庫支持,如果沒有開啟GD庫使用時會提示Call to undefined function imagecreate()錯誤。

例,我在測試一個簡單生成圖形時實例

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

undefined

 

http://www.android100.org/html/201407/11/38612.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM