Home  >  Article  >  Backend Development  >  PHP prompts Fatal error: Call to undefined function imagecreate()_PHP tutorial

PHP prompts Fatal error: Call to undefined function imagecreate()_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:43:311842browse

The imagecreate function in php is a graphics processing function. It is mainly used to create a new image based on the palette. Then on this basis we can create some graphics, digital characters, etc., but this function requires the support of the GD library , if the GD library is not enabled, a Call to undefined function imagecreate() error will be prompted.

Example, I am testing a simple generated graph

Example #1 Create a new GD image stream and output the image

The code is as follows Copy code
 代码如下 复制代码

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);
?>

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);

?>

Prompt when running the mechanism

Fatal error: Call to undefined function imagecreate() .....

I suddenly remembered that I didn’t open the gd library

This problem is: GD library is not installed or configured correctly, solution:

Found in php.ini


;extension=php_gd2.dll

 代码如下 复制代码
yum -y install php-gd
Remove the front;

Then copy php_gd2.dll under ext in the php directory into the c:/windows/system32 and c:/windows directories, and restart IIS or apache and it will be OK.

 代码如下 复制代码
/etc/rc.d/init.d/httpd restart(service httpd restart)
The gd library in centos is enabled There are only 2 commands for specific operations: Run the command to install PHP with GD library online: Restart the apachce service to make the installed GD library take effect

gd installation path

/etc/php.d/gd.ini                                                                                                                                                                                                                                                                                         You just need to write the *.ini file in the /etc/php.d/ folder. The system will automatically read the *.ini in this directory into php.ini
/usr/lib/php/modules/gd.so <----This is the gd file

Regarding the graphics processing functions that need to use the GD library, there are the following

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

imagesethickness

imagesettile

imagestring

imagestringup

imagesx

imagesy

imagetruecolortopalette

imagettfbbox

imagettftext

imagetypes

imagewbmp

imagewebp

imagexbm

iptcembed

iptcparse

jpeg2wbmp

png2wbmp

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633172.htmlTechArticleThe imagecreate function in php is a graphics processing function, mainly used to create a new palette-based image. Then on this basis we can create some graphics, digital characters and the like...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn