Home php教程 php手册 php提示Fatal error: Call to undefined function imagecreate()

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

May 27, 2016 am 08:47 AM
fatal undefined

在php中imagecreate函数是一个图形处理函数,主要用于新建一个基于调色板的图像了,然后在这个基础上我们可以创建一些图形数字字符之类的,但这个函数需要GD库支持,如果没有开启GD库使用时会提示Call to undefined function imagecreate()错误.

例,我在测试一个简单生成图形时实例,新建一个新的 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);
Copy after login

运行机制时提示: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 
&raquo; 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
Copy after login

               
               

本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if there is a fatal error when opening a game in win10? What to do if there is a fatal error when opening a game in win10? Feb 09, 2024 pm 12:54 PM

What should I do if there is a fatal error when opening a game in win10? What should we do if a fatal error message appears when running software or games? Let this site carefully introduce to users how to deal with the fatal error when opening games in Win10. What should I do if there is a fatal error when opening a game in win10? Method 1: There are problems with the game client, such as file damage or the use of some cracking patches, which will lead to fatalerror errors. You can re-download the game. Method 2: Too small computer memory can also cause fatalerror errors. If the physical memory is sufficient, you can try to set the virtual memory of the system.

How to solve the fatal error in Final Fantasy 7 How to solve the fatal error in Final Fantasy 7 Mar 07, 2024 pm 04:40 PM

When players play Final Fantasy 7, many players encounter fatal error problems and do not know how to solve them. It is usually about the problem that the memory cannot be read. It is recommended that players try to reinstall the game to solve the problem. How to solve the Final Fantasy 7 fatal error 1. Reinstall the game. Game client problems, such as file damage, incompleteness, and the use of some crack patches will lead to fatal errors. It is recommended to reinstall the game. 2. Remove the read-only properties of all files. Some file properties should not be read-only but are set to read-only. Just remove the read-only properties of all files. For example, if a game cannot be played, right-click on the game. Install the folder and cancel the read-only attribute. 3. Setting virtual memory may be due to the memory being too small. If the physical memory is sufficient

Solution to PHP Notice: Undefined property: Solution to PHP Notice: Undefined property: Jun 22, 2023 pm 02:48 PM

When writing code in PHP, we may encounter the error message "Notice: Undefinedproperty". This error means that we are accessing an undefined property, usually because the property has not been initialized in the code. So, how to solve this problem? Here are a few possible solutions: Initialize properties This is the simplest way to solve this problem. Explicitly initializing a property in code ensures that it is defined before use. For example: class

TypeError: Cannot read property '$XXX' of undefined in Vue, how to deal with it? TypeError: Cannot read property '$XXX' of undefined in Vue, how to deal with it? Nov 25, 2023 pm 12:14 PM

If you often encounter the error message "TypeError: Cannotreadproperty'$XXX'ofundefined" when developing with Vue.js, how should you deal with it? This article explains the causes of this error and how to fix it. The cause of the problem is that when using Vue.js, we often use this to call methods of Vue components, such as: exportdefault{data()

What do undefined and null mean? What do undefined and null mean? Nov 20, 2023 pm 02:39 PM

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

what is undefined what is undefined Jul 31, 2023 pm 02:28 PM

undefined represents a state in which a value or variable does not exist or is undefined. It can be used as a default value to determine whether a variable has been assigned a value, and can also be used to set default parameter values. Although undefined may have different meanings and usages in different programming languages, understanding the concept of undefined can help us better understand and write programs.

How to solve 'undefined: path.Join' error in golang? How to solve 'undefined: path.Join' error in golang? Jun 24, 2023 pm 01:12 PM

In the Go language, the path package is one of the important tools for processing file paths. The path.Join() function can combine multiple paths into a complete path. However, sometimes you will encounter the error message "undefined: path.Join", what should you do? Here are several common solutions: Check the import statement First, you need to confirm that you have imported the path package correctly. In Go language, when importing a package, you can

When to use null and undefined When to use null and undefined Nov 13, 2023 pm 02:11 PM

Both null and undefined indicate a lack of value or an undefined state. Depending on the usage scenario, there are some guiding principles for choosing to use null or undefined: 1. When you need to clearly indicate that a variable is empty or invalid, you can use null; 2. When a variable has been declared but not yet assigned a value, it will be set to undefined by default; 3. When you need to check whether a variable is empty or undefined, use the strict equality operator "===" to determine whether the variable is null or undefined. .

See all articles