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

Compare a shape in an image with PHP

I'm trying to compare shapes in php. I have a database with a lot of images, in those images there is a shape ( mostly in the center of the image ). Now I want to compare those images to a Shape. The input is a shape (png) that is exact the same…
S.Visser
  • 4,645
  • 1
  • 22
  • 43
5
votes
4 answers

PHP Color Manipulation

I am currently looking into color manipulation / selection etc and have come across the following piece of code. I was wondering of someone could tell me what the following piece of code is doing and break it down for me thanks! $newVal =…
Lizard
  • 43,732
  • 39
  • 106
  • 167
5
votes
3 answers

Choosing suitable background / foreground colour using PHP

I am looking to find a why to calculate a suitable background colour and a colour for the text that would go over the top, obviously I need to take into account readability and accessibility. I would need to pick the two colours from the array, the…
Lizard
  • 43,732
  • 39
  • 106
  • 167
5
votes
2 answers

Take screenshot with openGL and save it as png

I'm trying to take a screenshot of full screen and save it as a png. I found a code here and modified it a bit. For the screenshot I use openGL and Glut and for the saving in png the gd library for c. All I'm getting is a black png and I can't…
user1656466
  • 145
  • 1
  • 9
4
votes
3 answers

Image curving with PHP or HTML5

I am looking to achieve: http://i53.tinypic.com/2gule04.jpg I have tried the answers mentioned at Curving an image that starts as a rectangle (uploaded by user), preferably using Canvas or JS Based on the answers there, I have tried pixel wise…
4
votes
2 answers

Using the PHP GD library to resize and save images is HELL

I'm writing a script that will upload a file from user input, resize it to a thumbnail and add the two new filenames to a database. However, I cannot for the life of me figure out how to get PHP to detect the image's MIME type and then give it to…
Seraw
  • 41
  • 1
  • 2
4
votes
5 answers

Find JPEG resolution with PHP

Calling all PHP gurus! I understand that you can use getimagesize() to get the actual pixel height and width of an image in PHP. However, if you open an image in photoshop and look at the image size dialog, you notice that there is a resolution…
Rafe
  • 8,467
  • 8
  • 47
  • 67
4
votes
4 answers

In CakePHP, whats the best Image Upload / Resizing component you've used?

Im looking for somthing that can belong to many many models and, hopfully, has all the resizing functionality built in too. Wondering if there's any good suggestions out there, I don't want to pick the wrong one. Or is it just worth building my own?
CafeHey
  • 5,699
  • 19
  • 82
  • 145
4
votes
3 answers

PHP - save a converted image into a folder

I am trying to convert a jpeg image to black & white (grayscale) through the php function IMG_FILTER_GRAYSCALE . It works fine but i would like to save the image into a folder. Below the code: $im =…
Roberto Rizzi
  • 1,525
  • 5
  • 26
  • 39
3
votes
3 answers

Radial gradients with opacity in PHP

I need to create a PNG radial gradient with opacity. I've looked through GDLib but I can't see a way to generate radial gradients. Does anyone know of a way with GDlib or any other graphics library for PHP? I suppose worst-case I could generate it…
Tak
  • 11,428
  • 5
  • 29
  • 48
3
votes
1 answer

Codeigniter Blue Hue

UPDATE: THE ANSWER IS USE THE GD2 LIBRARY, DOH! I am working with Codeigniter's image manipulation library to resize some photos. Unfortunately, they are producing a blue tint or hue to the photos. Not sure why this is and needed to see if it was…
Nathan Stanford II
  • 617
  • 3
  • 9
  • 16
3
votes
1 answer

Extract words from an Image and PDF - Laravel

is there any way to extract words from scanned images and PDF? Is there any such library for Laravel as I want to use it for laravel. I have searched a lot for that but did not found any such thing for Laravel. Please let me know if you are aware…
Siddharth
  • 1,649
  • 4
  • 22
  • 47
3
votes
2 answers

Resize PNG without losing quality and transparency

I have to resize images, cause we upload printable high res images and for the preview people dont need a 4000px+ image. Some images using the rgb color space "eci" and others using the color space srgb. The srgb files dont have any problems, but…
TobiasHH
  • 125
  • 1
  • 10
3
votes
3 answers

Writing Hindi Fonts with GD Library do not render as desired

If I want to write the following text on the image: दीक्षा शिक्षा क्या क्या हो गया! Then it does not not give the expected result but instead is printing out text on the picture as below. I have tried almost all the devanagari ttf and unicode fonts…
Vishal Mohla
  • 71
  • 1
  • 7
3
votes
2 answers

Codeigniter and uploading zip files

I am currently building a backend to a site using the codeigniter framework, I have hit a bit of a problem, I needing a way to allow the user to upload a zipped folder of images, on completing the form, zipped folder must be unzipped, and the files…
Udders
  • 6,914
  • 24
  • 102
  • 194
1
2
3
10 11