Questions tagged [gdlib]

GD library is free PHP extension library used for image manipulation.

Introduction

PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM. Even more convenient, PHP can output image streams directly to a browser. You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.

You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and JPEG2000 images.

With the exif extension, you are able to work with information stored in headers of JPEG and TIFF images. This way you can read meta data generated by digital cameras. The exif functions do not require the GD library.


Requirements

If you have the GD library (available at » https://libgd.github.io/) you will also be able to create and manipulate images.

The format of images you are able to manipulate depend on the version of GD you install, and any other libraries GD might need to access those image formats. Versions of GD older than gd-1.6 support GIF format images, and do not support PNG, where versions greater than gd-1.6 and less than gd-2.0.28 support PNG, not GIF. GIF support was re-enabled in gd-2.0.28.


Installation

To enable GD-support configure PHP --with-gd[=DIR] , where DIR is the GD base install directory. To use the recommended bundled version of the GD library (which was first bundled in PHP 4.3.0), use the configure option --with-gd . GD library requires libpng and libjpeg to compile.

In Windows, you'll include the GD2 DLL php_gd2.dll as an extension in php.ini. The GD1 DLL php_gd.dll was removed in PHP 4.3.2. Also note that the preferred truecolor image functions, such as imagecreatetruecolor(), require GD2.

Enhance the capabilities of GD to handle more image formats by specifying the --with-XXXX configure switch to your PHP configure line.


Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

enter image description here

For further details and definitions of the PHP_INI_* modes, see the Where a configuration setting may be set.

Here's a short explanation of the configuration directives.

gd.jpeg_ignore_warning bool

Ignore warnings created by jpeg2wbmp() and imagecreatefromjpeg().

See also the exif configuration directives.

Warning: Image functions are very memory intensive. Be sure to set memory_limit high enough.


Resource Types

This extension defines two resource types: an image identifier and a font identifier.


Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

  • GD_VERSION (string) - The GD version PHP was compiled against. (Available as of PHP 5.2.4)
  • GD_MAJOR_VERSION (integer) - The GD major version PHP was compiled against. (Available as of PHP 5.2.4)
  • GD_MINOR_VERSION (integer) - The GD minor version PHP was compiled against. (Available as of PHP 5.2.4)
  • GD_RELEASE_VERSION (integer) - The GD release version PHP was compiled against. (Available as of PHP 5.2.4)
  • GD_EXTRA_VERSION (string) - The GD "extra" version (beta/rc..) PHP was compiled against. (Available as of PHP 5.2.4)
  • GD_BUNDLED (integer) - When the bundled version of GD is used this is 1 otherwise its set to 0.
  • IMG_GIF (integer) - Used as a return value by imagetypes()
  • IMG_JPG (integer) - Used as a return value by imagetypes()
  • IMG_JPEG (integer) - Used as a return value by imagetypes() (This constant has the same value as IMG_JPG)
  • IMG_PNG (integer) - Used as a return value by imagetypes()
  • IMG_WBMP (integer) - Used as a return value by imagetypes()
  • IMG_XPM (integer) - Used as a return value by imagetypes()
  • IMG_COLOR_TILED (integer) - Special color option which can be used in stead of color allocated with imagecolorallocate() or imagecolorallocatealpha()
  • IMG_COLOR_STYLED (integer) - Special color option which can be used in stead of color allocated with imagecolorallocate() or imagecolorallocatealpha()
  • IMG_COLOR_BRUSHED (integer) - Special color option which can be used in stead of color allocated with imagecolorallocate() or imagecolorallocatealpha()
  • IMG_COLOR_STYLEDBRUSHED (integer) - Special color option which can be used in stead of color allocated with imagecolorallocate() or imagecolorallocatealpha()
  • IMG_COLOR_TRANSPARENT (integer) - Special color option which can be used in stead of color allocated with imagecolorallocate() or imagecolorallocatealpha()
  • IMG_ARC_ROUNDED (integer) - A style constant used by the imagefilledarc() function (This constant has the same value as IMG_ARC_PIE)
  • IMG_ARC_PIE (integer) - A style constant used by the imagefilledarc() function.
  • IMG_ARC_CHORD (integer) - A style constant used by the imagefilledarc() function.
  • IMG_ARC_NOFILL (integer) - A style constant used by the imagefilledarc() function.
  • IMG_ARC_EDGED (integer) - A style constant used by the imagefilledarc() function.
  • IMG_GD2_RAW (integer) - A type constant used by the imagegd2() function.
  • IMG_GD2_COMPRESSED (integer) - A type constant used by the imagegd2() function.
  • IMG_EFFECT_REPLACE (integer) - Alpha blending effect used by the imagelayereffect() function.
  • IMG_EFFECT_ALPHABLEND (integer) - Alpha blending effect used by the imagelayereffect() function.
  • IMG_EFFECT_NORMAL (integer) - Alpha blending effect used by the imagelayereffect() function.
  • IMG_EFFECT_OVERLAY (integer) - Alpha blending effect used by the imagelayereffect() function.
  • IMG_FILTER_NEGATE (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_GRAYSCALE (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_BRIGHTNESS (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_CONTRAST (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_COLORIZE (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_EDGEDETECT (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_GAUSSIAN_BLUR (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_SELECTIVE_BLUR (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_EMBOSS (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_MEAN_REMOVAL (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_SMOOTH (integer) - Special GD filter used by the imagefilter() function.
  • IMG_FILTER_PIXELATE (integer) - Special GD filter used by the imagefilter() function. (Available as of PHP 5.3.0)
  • IMAGETYPE_GIF (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_JPEG (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_JPEG2000 (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_PNG (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_SWF (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_PSD (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_BMP (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_WBMP (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_XBM (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_TIFF_II (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_TIFF_MM (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_IFF (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_JB2 (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_JPC (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_JP2 (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_JPX (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_SWC (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions.
  • IMAGETYPE_ICO (integer) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. (Available as of PHP 5.3.0)
  • PNG_NO_FILTER (integer) - A special PNG filter, used by the imagepng() function.
  • PNG_FILTER_NONE (integer) - A special PNG filter, used by the imagepng() function.
  • PNG_FILTER_SUB (integer) - A special PNG filter, used by the imagepng() function.
  • PNG_FILTER_UP (integer) - A special PNG filter, used by the imagepng() function.
  • PNG_FILTER_AVG (integer) - A special PNG filter, used by the imagepng() function.
  • PNG_FILTER_PAETH (integer) - A special PNG filter, used by the imagepng() function.
  • PNG_ALL_FILTERS (integer) - A special PNG filter, used by the imagepng() function.

GD and Image Functions

Visit this link!


References

164 questions
0
votes
0 answers

gd2 library is not giving good results

I am using gd2 library to cut images but it is not working for my images. I am uploading images of 1000X1000px and then cut it in 300X300 and 107X84. 300X300 image is fine but 107X84 image isn't great. I can easily see the difference with same image…
user3110655
  • 121
  • 3
  • 20
0
votes
2 answers

How to use/link gdLibrary (libgd) with MS Visual C++ (e.g. 2008 Express Edition)? Getting LNK2019 errors

I have to use the gdLibrary (http://www.libgd.org) in a C++ App on MS Windows XP Prof. SP3 32bit - and I'm trying and googleing for two days now without success. Does anyone of you use libgd with MS VC++ 200x EE? My problem: It has to to compile…
Georg
  • 3
  • 2
0
votes
1 answer

PHP/GD: Image rotation gone wild

I am trying to rotate an image through GD Library and a database value: // Image for rotating $image = 'images/weather-icons/windDir.png'; //degrees from database $degrees = $row[WindDirDegrees]; // Create the canvas $source =…
braumer
  • 85
  • 11
0
votes
1 answer

PHP GD Text insert in a div equivalent

I am currently trying to generate a infographic with the PHP GD library, I can get the text to display in the correct place but when it gets larger it overlaps parts of the image that I don't wan't it to. What I want to do is have some form of html…
bobthemac
  • 1,172
  • 6
  • 26
  • 59
0
votes
1 answer

PHP image color analysis with transparency

I am currently working on an application that needs to analyse a number of images and figure out what color they're closest to. Therefore I found a code snippet that does exactly that: function analyzeImageColors($im, $xCount =3, $yCount =3) { …
phidah
  • 5,794
  • 6
  • 37
  • 58
0
votes
1 answer

PHP GD Library cannot Merge to image using function

This is my php class to merge to images mergepic.php class mergepic{ public function merge_barchart_drawing($object,$obj) { $src = imagecreatefrompng($obj->barchart()); $dest = imagecreatefrompng($object->drawing()); …
Serma
  • 44
  • 1
  • 2
  • 11
0
votes
0 answers

PHP ImageTTFText

why this show only the background image, and not the text? Without backgroundimage it's work... $code = rand(1000, 99999); $_SESSION["code"] = $code; $font = '../fonts/captcha.ttf'; $y = 30; $x = 10; $width = 100; //Image width in pixels $height =…
LosAngeles
  • 83
  • 1
  • 11
0
votes
1 answer

How to display dynamic button in codeigniter using Gd library?

I created form with dynamic color,font,size of button . when i submit the form, button image displaying in full page,i need to display in first page itself. my controller code : public function creatorbuton(){ $button_size =…
Kennedy
  • 325
  • 2
  • 14
  • 35
0
votes
0 answers

Embedding transparent png onto an image is too slow

The function below embeds a watermark onto an image. In some servers it's super slow while I never encounter the same issue in my server. What could be wrong with it? I'm out of ideas. function add_watermark( $source_file_path, $output_file_path,…
anlogg
  • 1,050
  • 1
  • 15
  • 36
0
votes
1 answer

Convert background on RGB jpg to be transparent

I know there are bunch of questions for this but none seem to provide actual code to use I am trying to convert a RGB jpg to convert everything that is either not black or is white to be transparent The code I tried using is: $im =…
Yeak
  • 2,470
  • 9
  • 45
  • 71
0
votes
2 answers

PHP image creation from hex values in database

I've got the code below to pull hex values from a database and create an image of that colour. There's over a thousand values, so it's looping to create an image for them all. It seems to work fine except it just keeps overwriting the first image…
logic-unit
  • 4,195
  • 12
  • 47
  • 72
0
votes
1 answer

Showing email addresses as an image

I'm trying to use Php's gd library to show emails on a my page as an image, so they can't be used by spammers. The problem is that the tutorial I am following uses a header with Content-type: image/jpeg. This means that I can only have images on…
user2471133
  • 1,377
  • 3
  • 14
  • 15
0
votes
1 answer

Generate a large amount of images then merge into a PDF (1,000 to 10,000 pages) from PHP site

I have created a site with a custom module built on top of OpenCart. It allows you to design a business card, brochure, or post card online (something like vistaprint but simpler) and generates a print ready file. One of the requested features was…
Developer Gee
  • 362
  • 3
  • 12
0
votes
2 answers

Join Multiple transparent png image in Single image into php

Friends i want to generate one png image from multiple transparent PNG image but the issue is that i can generate only last image Both images can not combine. My code is given below $x = 363; $y = 267; $im_dest = imagecreatetruecolor ($x,…
Munir Vora
  • 51
  • 11
0
votes
1 answer

php generated image in javascript

I have a picture generated with GDLib. In this picture gdlib adds some gif dots in various locations, according to database data. Now i would like to somehow identify these dots with javascript and make a simple fadein/fadeout function for these…
JPJens
  • 1,185
  • 1
  • 17
  • 39
1 2 3
10
11