If you get the following error message in PHP then it means you need to have the PHP GD extension installed. Obviously the /path/to/file.php will be the actual path and filename of the PHP script the error occured in, and the line number will be the actual line.
Fatal error: Call to undefined function ImageCreateFromPNG()
in /path/to/file.php on line 379
You'll also get this error message using other functions such as ImageCreateFromJPEG() if the PHP GD library is not installed.
On CentOS, Red Hat's Enterprise Linux and Fedora, you can easily add the PHP GD library from the command line using the command listed below, either as the root user or using sudo. You can also install it using the graphical software installation tools by searching for "php-gd" and installing from there.
yum install php-gd
After hitting <enter> the command will run and you'll get output similar to the following:
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-gd to pack into transaction set.
php-gd-5.1.6-15.el5.i386. 100% |=========================| 17 kB 00:00
---> Package php-gd.i386 0:5.1.6-15.el5 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
php-gd i386 5.1.6-15.el5 base 111 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 111 k
Is this ok [y/N]:
At this point you type in "Y" and hit <enter>. It will then install the PHP GD library.
Downloading Packages:
(1/1): php-gd-5.1.6-15.el 100% |=========================| 111 kB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-gd ######################### [1/1]
Installed: php-gd.i386 0:5.1.6-15.el5
Complete
The installation is now complete. However, you still can't use the GD functions until you have reloaded the Apache web server like so, using either sudo or running it as root:
/etc/init.d/httpd reload
Note that just doing a "reload" seems to work OK, it doesn't have to be a full "restart".
This is how to install the PHP GD library from the command line using Fedora, CentOS or Red Hat's Enterprise Linux and other Linux deritives. The process and package name will be similar using other Linux and BSD distros.
分享到:
相关推荐
$image = imagecreatefrompng('path/to/your/image.png'); ``` 一旦有了图像资源,你就可以使用各种GD库提供的函数来处理图像,比如改变大小、颜色调整、绘制文本等。 接下来,`imagecopyresampled`函数是用来缩放...
本文将深入探讨三个PHP图像处理函数:`imagecreatefromjpeg`、`imagecreatefrompng` 和 `imagecreatefromgif`,以及如何通过它们绕过某些安全防护措施。 `imagecreatefromjpeg` 是PHP内置的一个函数,专门用于从...
$watermark = imagecreatefrompng('watermark.png'); $image = imagecreatefromjpeg('image.jpg'); imagecopymerge($image, $watermark, imagesx($image) - imagesx($watermark), imagesy($image) - imagesy($...
1. 图像创建:`imagecreatefromjpeg()`, `imagecreatefrompng()`, `imagecreatefromgif()` 等函数用于从不同格式的文件创建图像资源。 2. 图像绘制:`imageline()`, `imagefilledrectangle()`, `ellipse()`, `arc()`...
2. **读取图片**:使用GD库或Imagick的函数读取上传的图片,如imagecreatefromjpeg()、imagecreatefrompng()等。 3. **设定裁切参数**:用户设置裁切的起点坐标(x, y)和裁切区域的宽高。 4. **裁切图片**:根据...
ImageString($im, 4, 5, 5, "Error loading: $imgname", $tc); } return $im; } $imgPng = Loadpng("./karte.png"); /* 输出图像到浏览器*/ header("Content-type: image/png"); imagePng($imgPng); ?> ``` 这段...
$font_path = 'path/to/font.ttf'; $text_color = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 24, 0, 50, 100, $text_color, $font_path, "Hello, World!"); ``` 这段代码将在图像上添加黑色的...
使用imagecreatefrompng()函数创建背景图片资源。 为了合成图片,我们需要遍历$imgs数组,使用imagecreatefromjpeg()函数创建每张图片的资源,并通过getimagesize()函数获取图片的尺寸。这些信息将用于确定每张图片...
PHP的`imagecreatefrompng()`函数可以用来读取PNG格式的图像,而`imagecreatetruecolor()`用于创建一个新的图像资源,我们可以在这张新图上进行文字和图像的合成。 4. **图片合成过程**: - 首先,加载背景图片...
require_once 'path/to/phpqrcode/qrlib.php'; // 设置二维码参数 QRcode::png($content, 'qr.png', QR_ECLEVEL_H, $size, 2, true, $color); // 如果有Logo,合并到二维码图像 if ($logoPath !== null) { $...
PHP的`imagecreatefromjpeg`、`imagecreatefrompng`或`imagecreatefromgif`函数可以用于加载不同格式的图像。例如,如果原始图像是JPEG格式,可以这样操作: ```php $src = imagecreatefromjpeg('original.jpg'); `...
require_once 'path/to/phpqrcode/qrlib.php'; ``` 2. **设置参数**:库通常允许我们设置二维码的相关参数,如版本、纠错级别、边距等。例如,设置为生成一个纠错级别为L(最低)的二维码,边距为4: ```php $...
在这个例子中,`imagecreatefrompng`用于打开PNG图片,`imagecolorallocate`分配颜色,`imagestring`在指定位置写入文字,`imagepng`保存结果,最后`imagedestroy`释放内存。 2. **imagettftext**: ```php <?php $...
$logo = imagecreatefrompng('path/to/logo.png'); // 获取LOGO图片的宽度和高度 $logoWidth = imagesx($logo); $logoHeight = imagesy($logo); // 计算LOGO在二维码中的合适位置 $qrWidth = $qrCode->getSize(); $...
function create_thumbnail($src, $dest, $width=100, $height=100) { $info = getimagesize($src); $image_type = $info[2]; switch ($image_type) { case IMAGETYPE_JPEG: $img = imagecreatefromjpeg($src...
$logo = imagecreatefrompng('path/to/your/logo.png'); // 获取二维码尺寸 $qrWidth = $qrCode->getSize(); // 调整LOGO大小使其适合二维码 $logoWidth = imagesx($logo); $logoHeight = imagesy($logo); $...
$this->im = ImageCreateFromPNG($this->srcimg); break; // ... 其他支持的格式 ... } } function dst_img($dstpath) { $this->dstimg = $dstpath; } function newimg() { // 根据比例计算缩放尺寸,并...
require_once 'path/to/qr/qrcode.php'; $data = 'http://example.com'; $level = 'L'; // 纠错级别,L(低)、M(中)、Q(高)、H(最高) $size = 4; // 二维码的大小 QRcode::png($data, 'output.png', $...
1. **加载图像**:使用`imagecreatefromjpeg()`、`imagecreatefrompng()`或`imagecreatefromgif()`等函数来加载不同格式的图像。例如,如果图像为PNG格式,我们可以这样加载: ```php $image = imagecreatefrompng('...
$image = imagecreatefrompng($source_path); break; // 添加其他类型如GIF等 } // 设置新的宽度和高度,这里以保持原图宽高比缩小为例 $new_width = 800; // 目标宽度 $ratio = $width / $new_width; $new_...