Home Backend Development PHP Tutorial Complete collection of PHP GD library functions (collection)

Complete collection of PHP GD library functions (collection)

Jul 25, 2016 am 08:55 AM

Share the commonly used functions in the php gd library, with Chinese comments and classification processing, including image information, new/loading images, output images and other php gd library functions. Friends in need can refer to them.

Contents of this section: A complete list of functions of the php gd library.

1. Image information:

gd_info: Get information about the currently installed GD library imagetypes returns the image types supported by the current PHP version image_type_to_extension gets the file suffix of the image type image_type_to_mime_type gets the MIME type of the image type getimagesize Get image size imagesx gets image width imagesy gets image height imageistruecolor checks whether the image is a true color image

2. Create new/load image:

imagecreate — Create a new palette-based image imagecreatefromgd2 — Create a new image from a GD2 file or URL imagecreatefromgd2part — Create a new image from a part of the given GD2 file or URL imagecreatefromgd — Create a new image from a GD file or URL imagecreatefromgif — Create a new image from a GIF file or URL imagecreatefromjpeg — Create a new image from a JPEG file or URL imagecreatefrompng — Create a new image from a PNG file or URL imagecreatefromstring — Create an image from an image stream in a string imagecreatefromwbmp — Create a new image from a WBMP file or URL imagecreatefromxbm — Create a new image from an XBM file or URL imagecreatefromxpm — Create a new image from an XPM file or URL imagecreatetruecolor — Create a new true color image

3, output image:

image2wbmp Outputs images in WBMP format to a browser or file imagegd2 Output GD2 images to a browser or file imagegd Output GD images to a browser or file imagegif Outputs an image in GIF format to a browser or file imagewbmp Outputs images in WBMP format to a browser or file imagexbm outputs XBM images to a browser or file imagejpeg Outputs an image in JPEG format to a browser or file imagepng Outputs an image in PNG format to a browser or file

4, Miscellaneous related:

imagealphablending sets the color blending mode of the image imageantialias Whether to use the anti-aliasing (antialias) function imageinterlace Activate or disable interlacing imagegammacorrect applies gamma correction to GD images iptcembed embeds binary IPTC data into a JPEG image iptcparse parses binary IPTC http://www.iptc.org/ chunks into individual tokens imagesavealpha Set flag to save full alpha channel information when saving PNG images (as opposed to a single transparent color)

5, graphics related:

imagearc draws elliptical arc imageconvolution uses coefficients div and offset to apply for a 3x3 convolution matrix imagedashedline draw a dotted line imageellipse draws an ellipse imagerectangle draws a rectangle imagefilledarc draws an elliptical arc and fills it imagefilledellipse draws an ellipse and fills it imagefilledpolygon draws a polygon and fills it imagefilledrectangle draws a rectangle and fills it imagesetbrush sets the brush image used for drawing lines imagesetpixel draws a single pixel imagesetstyle sets the style of line drawing imagesethickness sets the width of the line drawing imagepolygon draws a polygon imageline draws a line segment

6, character/font related:

imagechar draws a character horizontally imagecharup draws a character vertically imagestring draws a line of string horizontally imagestringup draws a line of string vertically imagepsbbox gives a text box using PostScript Type1 font imagepsencodefont changes the character encoding vector in the font imagepsextendfont expands or condenses fonts imagepsfreefont Frees the memory occupied by a PostScript Type 1 font imagepsloadfont loads a PostScript Type 1 font from a file imagepsslantfont tilts a font imagepstext draws text strings on images using PostScript Type1 fonts imagettfbbox Gets the range of text using TrueType fonts imagettftext writes text to an image using TrueType fonts imageftbbox gives a text box using FreeType 2 fonts imagefttext Write text to an image using FreeType 2 fonts imagefontheight gets the font height imagefontwidth gets the font width imageloadfont loads a new font

7, color related:

imagecolorallocate assigns a color to an image imagecolorallocatealpha assigns color + alpha to an image imagecolorat gets the color index value of a pixel imagecolorclosest Gets the index value of the color closest to the specified color. Gets the color index value of a certain pixel. imagecolorclosestalpha Gets the color closest to the specified color plus transparency imagecolorclosesthwb Gets the black and white index of the hue closest to the given color imagecolordeallocate cancels the allocation of image color imagecolorexact gets the index value of the specified color imagecolorexactalpha Gets the index value of the specified color plus transparency imagecolormatch makes the palette version of colors in an image more closely match the true color version imagepalettecopy copies a palette from one image to another imagecolorresolve Gets the index value of the specified color or the closest possible replacement value imagecolorresolvealpha Gets the index value of the specified color + alpha or the closest alternative possible imagecolorset sets the color for the specified palette index imagecolorsforindex gets the color of an index imagecolorstotal Gets the number of colors in the palette of an image imagecolortransparent defines a color as transparent

8, Image operation:

imagecopy copies part of an image imagecopymerge copies and merges part of an image imagecopymergegray copies and merges part of an image in grayscale imagecopyresampled resamples copy part of the image and resizes it imagecopyresized copies part of the image and resizes it imagerotate rotates an image by a given angle jpeg2wbmp Converts JPEG image files to WBMP image files png2wbmp Converts PNG image files to WBMP image files imagedestroy destroys an image

1 2 Next Page Last Page



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)

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles