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
1 answer

php upload and letterbox

I need to upload an image file and then create a wider image with the original resized inside it. watching the internet, I found something that do this trick: function resize_image($source_image, $destination_width, $destination_height, $type =…
Ast
  • 337
  • 1
  • 4
  • 17
0
votes
1 answer

PHP :How Can i downgrade an gd library in php

Is is it possible to downgrade gd-library, If so please tellme how.google did not help me.
Hem Teja
  • 75
  • 1
  • 7
0
votes
2 answers

shuffle array keys and mix then in an foreach

I have 2 arrays that are combined into one. One array with some products and the other array with numbers (number of products). $brick = "RT542,RT543,RT538"; $ratio = "10,15,13"; $bricks = explode(",", $brick); $ratios = explode(",",…
Morten Hagh
  • 2,055
  • 8
  • 34
  • 66
0
votes
2 answers

PHP text to image

I got good result in PHP/GD to write text to image template, text wraps fine but is not "smooth", here is the code I am using:
Basheer
  • 328
  • 1
  • 2
  • 10
0
votes
1 answer

Is it possible to create an PNG with full alpha channel by using: imagecolortransparent()

I'm looking for a way to create a transparent area in an image by using its aplha channel. I just found that way: Define a color and set it to transparent. imagealphablending($img, false); // has to be false for…
-1
votes
1 answer

PHP - How to Rename an Image File on Upload

This is a complete script I am using that creates 3 different re-sized images from my original upload. Right now it renames the 3 output files with their size plus the original image file name. I want to rename the images with the size BUT change it…
-1
votes
1 answer

Give images "fake" names

I am trying to figure out if it's possible to rename images "on the fly" - by that meaning if you can do some sort of rename function, so in code the imagenames are changed, but the orginal image name is not. Example: I have a database with a table…
MazeyMazey
  • 303
  • 1
  • 2
  • 14
-1
votes
1 answer

Save image after copying it with PHP's GD Library

I'm cropping an image that was submitted through a form with a jQuery crop plugin. I have the following. But, how can I find out the path to the destination image? $pic = $this->input->post('pic'); //Get the coordinates from the image crop $x =…
Lance
  • 4,736
  • 16
  • 53
  • 90
-1
votes
1 answer

Uploading Image(manipulated) using Javascript to facebook

I use the Following Php Code to Manipulate image using GD library and upload that modified image to facebook.My question is Can i achieve the Same using Javascript.If so What technology should i use.thanks. $iOut =…
vishnu
  • 869
  • 1
  • 16
  • 25
-2
votes
1 answer

Text is not showing on image create by gd library

i have developed this code for image but the problem is that my text is not appearing on this image please help ! code is running fine with no error. Displaying the white image as mentioned in this code.
Dev vivek
  • 45
  • 1
  • 8
-2
votes
1 answer

Call to a member function insert() on string

I want to add a watermark to my uploaded image using intervention image library in laravel.I have installed it through command composer require intervention/image , added Intervention\Image\ImageServiceProvider::class in providers array and…
Irfan Ullah
  • 65
  • 1
  • 9
-2
votes
2 answers

Check if sub image exists in main image with PHP?

Using PHP, how can I check whether an image exists within another? Example: How can I check whether subimage.jpg exists within mainimage.jpg, using PHP? subimage.jpg mainimage.jpg
Manish Patolia
  • 507
  • 5
  • 23
-2
votes
2 answers

How do I generate an image file defined by CSS properties?

Is there any way to create image file (jpeg or png) from some html DIV which is defined by CSS style properties. For Example: #canvas_base { width: 400px; height: 200px; background-color: #1155aa; } div.text_div{ font-size: 15px; font-family:…
minimal
  • 457
  • 3
  • 15
-4
votes
2 answers

Add additional noise to Captcha image?

I have this simple captcha script from online. I like it, and I edited it to suit my site, but was wondering if someone could edit it to add some random lines on the captcha itself as it is somewhat too simple. I did find tutorials on how to do it…
PHPLOVER
  • 7,047
  • 18
  • 37
  • 54
1 2 3
10
11