PHP Tutorials - Herong's Tutorial Examples
∟Functions to Manage Directories, Files and Images
∟imagecreatetruecolor() and GD Imaging Library Functions
This section describes some GD Imaging library functions. imagecreatetruecolor() creates an image in true color mode. imagecreatefromgif() creats an image from a GIF file. imagegif() writes an image to a GIF file. imagerotate() rotates an image. imagecopyresized() copies and resizes an image.
If you are interested in managing image files, you enable the GD Imaging library by turning on
the extension=gd2 (or extension=php_gd2.dll in PHP 5) setting in php.ini.
The GD Imaging library offers a lots of nice functions to manage image files:
- gd_info() - This "GD information" function returns information about the GD Imaging library as an array.
- imagecreate($width,$height) - This "image create" function creates a blank image object.
- imagecreatetruecolor($width,$height) - This "image create true color" function creates a blank image object with in true color mode,
which uses RGB color format with 256 value for each color component.
- imagecreatefromgif($path) - This "image create from GIF" function creates an image object from a GIF image file.
- imagecreatefromjpeg($path) - This "image create from JPEG" function creates an image object from a JPEG (JPG) image file.
- imagecreatefromwbmp($path) - This "image create from BMP" function creates an image object from a BMP image file.
- imagegif($image,$path) - This "image GIF" function writes an image object to a GIF image file.
- imagejpeg($image,$path) - This "image JPEG" function writes an image object to a JPEG (JPG) image file.
- imagerotate($image,$angle,$color) - This "image rotate" function rotates an image object of $angle degrees
and returns the rotated image. $color is used to fill uncovered area after the rotation.
- imagesx($image) - This "image size x" function returns the width of $image.
- imagesy($image) - This "image size y" function returns the height of $image.
- imagedestroy($image) - This "image destroy" function descries an image object.
- imagecopyresized($dst_image,$src_image, $dst_x,$dst_y, $src_x,$src_y, $dst_w,$dst_h, $src_w,$src_h)
- This "image copy resized" function copies a part of an image from $src_image to $dst_image.
$src_x and $src_y specifies the copy-from location.
$dst_x and $dst_y specifies the copy-to location.
$src_w and $src_h specifies the copy-from size.
$dst_w and $dst_h specifies the copy-to size.
If the copy-to size is larger or smaller than the copy-from size, the copied part will be resized.
- imagecopyresampled($dst_image,$src_image, $dst_x,$dst_y, $src_x,$src_y, $dst_w,$dst_h, $src_w,$src_h)
- This "image copy resampled" function does the same job as imagecopyresized() with a better qualit.
- imagecopy($dst_image,$src_image, $dst_x,$dst_y, $src_x,$src_y, $src_w,$src_h)
- This "image copy" function does the same job as imagecopyresized() except that the copied part will not be resized.
- imagecopymerge($dst_image,$src_image, $dst_x,$dst_y, $src_x,$src_y, $src_w,$src_h, $percentage)
- This "image copy merge" function does the same job as imagecopy() except that the copied part will be merged
to $dst_image with a $percentage factor.
- imagecolortransparent($image,$color) - This "image color transparent" function sets new color as the transparent color.
- imagecolorat($image, $x,$y) - This "image color at" function returns the color value from $image at $x and $y position.
In true color mode, the returned $rgb value can be decomposed as $r = ($rgb >> 16) & 0xFF, $g = ($rgb >> 8) & 0xFF,
and $b = $rgb & 0xFF.
- imagecolorsforindex(image, $color) - This "image color for index" function return RGB color values and alpha key
of the specified color index.
- imagesetpixel($image, $x,$y, $color) - This "image set pixel" function set one pixel at $x and $y with $color.
- imagefill($image, $x,$y, $color) - This "image fill" function performs a flood fill at $x and $y position with
a given $color.
- imagecolorallocate($image, $r,$g,$b) - This "image color allocate" function allocates a color index with $r, $g and $b
values. The allocated color index is returned.
- imagecolorallocatealpha($image, $r,$g,$b, $alpha) - This "image color allocate alpha" function does the same job
as imagecolorallocate() except that it applies a transparency parameter $alpha between
0, completely opaque, and 127, completely transparent.
- imagestring($image, $font, $x,$y, $string, $color) - This "image string" function draws a $string horizontally
at $x and $y with $font in $color.
- imagettftext($image, $size, $angle, $x,$y, $color, $font, $text) -
This "image TTF Text draws a $text at $x and $y with a $font of $size in a $color at an $angle.
- imageline($image, $x1,$y1, $x2,$y2, $color) - This "image line" function draws a line in a $color.
- imagerectangle($image, $x1,$y1, $x2,$y2, $color) - This "image rectangle" function draws a retangle in a $color.
Last update: 2019.
Table of Contents
About This Book
Introduction and Installation of PHP 7.3
PHP Script File Syntax
PHP Data Types and Data Literals
Variables, References, and Constants
Expressions, Operations and Type Conversions
Conditional Statements - "if" and "switch"
Loop Statements - "while", "for", and "do ... while"
Function Declaration, Arguments, and Return Values
Arrays - Ordered Maps
Introduction of Class and Object
Integrating PHP with Apache Web Server
Retrieving Information from HTTP Requests
Creating and Managing Sessions in PHP Scripts
Sending and Receiving Cookies in PHP Scripts
Controlling HTTP Response Header Lines in PHP Scripts
MySQL Server Connection and Access Functions
►Functions to Manage Directories, Files and Images
opendir() and Directory Management Functions
file_exists() and File Testing Functions
FileExistsTest.php - File Testing Examples
fopen() and File Input/Output Functions
File_Input_Output_Test.php - File Input/Output Examples
readfile() and Special File Handling Functions
►imagecreatetruecolor() and GD Imaging Library Functions
ShowPhoto.php - Simple Slid Show Script
SOAP Extension Function and Calling Web Services
SOAP Server Functions and Examples
Localization Overview of Web Applications
Using Non-ASCII Characters in HTML Documents
Using Non-ASCII Characters as PHP Script String Literals
Receiving Non-ASCII Characters from Input Forms
"mbstring" Extension and Non-ASCII Encoding Management
Managing Non-ASCII Character Strings with MySQL Servers
Configuring and Sending out Emails
Outdated Tutorials
References
Full Version in PDF/EPUB