= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // getimagesize() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | getimagesizefromstring() - PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // OFFLINE | image_type_to_extension() - PHP_5 >= PHP_5_2_0, PHP_7, PHP_8 // image_type_to_mime_type() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // OFFLINE | image2wbmp() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // OFFLINE | imageaffine() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // OFFLINE | imageaffinematrixconcat() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // OFFLINE | imageaffinematrixget() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // imagealphablending() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imageantialias() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // imagearc() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imageavif() - PHP_8 // OFFLINE | imagebmp() - PHP_7 >= PHP_7_2_0, PHP_8 // imagechar() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecharup() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorallocate() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorallocatealpha() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // imagecolorat() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorclosest() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorclosestalpha() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagecolorclosesthwb() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // imagecolordeallocate() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorexact() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorexactalpha() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagecolormatch() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // imagecolorresolve() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorresolvealpha() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagecolorset() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorsforindex() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolorstotal() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecolortransparent() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imageconvolution() - PHP_5 >= PHP_5_1_0, PHP_7, PHP_8 // imagecopy() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecopymerge() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // imagecopymergegray() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagecopyresampled() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagecopyresized() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecreate() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imagecreatefromavif() - PHP_8 >= PHP_8_1_0 // OFFLINE | imagecreatefrombmp() - PHP_7 >= PHP_7_2_0, PHP_8 // imagecreatefromgd2() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // imagecreatefromgd2part() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // imagecreatefromgd() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // imagecreatefromgif() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecreatefromjpeg() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecreatefrompng() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecreatefromstring() - PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imagecreatefromtga() - PHP_7 >= PHP_7_4_0, PHP_8 // imagecreatefromwbmp() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // OFFLINE | imagecreatefromwebp() - PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // imagecreatefromxbm() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // imagecreatefromxpm() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // imagecreatetruecolor() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // OFFLINE | imagecrop() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // OFFLINE | imagecropauto() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8_1_0 // imagedashedline() - PHP_4, PHP_5, PHP_7, PHP_8 // imagedestroy() - PHP_4, PHP_5, PHP_7, PHP_8 // imageellipse() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagefill() - PHP_4, PHP_5, PHP_7, PHP_8 // imagefilledarc() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagefilledellipse() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagefilledpolygon() - PHP_4, PHP_5, PHP_7, PHP_8 // imagefilledrectangle() - PHP_4, PHP_5, PHP_7, PHP_8 // imagefilltoborder() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imagefilter() - PHP_5, PHP_7, PHP_8 // OFFLINE | imageflip() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // imagefontheight() - PHP_4, PHP_5, PHP_7, PHP_8 // imagefontwidth() - PHP_4, PHP_5, PHP_7, PHP_8 // imageftbbox() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // imagefttext() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // imagegammacorrect() - PHP_4, PHP_5, PHP_7, PHP_8 // imagegd2() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // imagegd() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // OFFLINE | imagegetclip() - PHP_7 >= PHP_7_2_0, PHP_8 // OFFLINE | imagegetinterpolation() - PHP_8 // imagegif() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imagegrabscreen() - PHP_5 >= PHP_5_2_2, PHP_7, PHP_8 // OFFLINE | imagegrabwindow() - PHP_5 >= PHP_5_2_2, PHP_7, PHP_8 // imageinterlace() - PHP_4, PHP_5, PHP_7, PHP_8 // imageistruecolor() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // imagejpeg() - PHP_4, PHP_5, PHP_7, PHP_8 // imagelayereffect() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // imageline() - PHP_4, PHP_5, PHP_7, PHP_8 // imageloadfont() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imageopenpolygon() - PHP_7 >= PHP_7_2_0, PHP_8 // imagepalettecopy() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // OFFLINE | imagepalettetotruecolor() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // imagepng() - PHP_4, PHP_5, PHP_7, PHP_8 // imagepolygon() - PHP_4, PHP_5, PHP_7, PHP_8 // imagerectangle() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | imageresolution() - PHP_7 >= PHP_7_2_0, PHP_8 // imagerotate() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // imagesavealpha() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // OFFLINE | imagescale() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // imagesetbrush() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // OFFLINE | imagesetclip() - PHP_7 >= PHP_7_2_0, PHP_8 // OFFLINE | imagesetinterpolation() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // imagesetpixel() - PHP_4, PHP_5, PHP_7, PHP_8 // imagesetstyle() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagesetthickness() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagesettile() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagestring() - PHP_4, PHP_5, PHP_7, PHP_8 // imagestringup() - PHP_4, PHP_5, PHP_7, PHP_8 // imagesx() - PHP_4, PHP_5, PHP_7, PHP_8 // imagesy() - PHP_4, PHP_5, PHP_7, PHP_8 // imagetruecolortopalette() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // imagettfbbox() - PHP_4, PHP_5, PHP_7, PHP_8 // imagettftext() - PHP_4, PHP_5, PHP_7, PHP_8 // imagetypes() - PHP_4 >= PHP_4_0_2, PHP_5, PHP_7, PHP_8 // imagewbmp() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // OFFLINE | imagewebp() - PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // OFFLINE | imagexbm() - PHP_5, PHP_7, PHP_8 // iptcembed() - PHP_4, PHP_5, PHP_7, PHP_8 // iptcparse() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | jpeg2wbmp() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // OFFLINE | png2wbmp() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ============================== USING CLASSES (0) // ============================== USING DATA_TYPES (11) // array // false // string // int // bool // resource // OFFLINE | GdImage - PHP_8 // float // null // OFFLINE | GdFont - PHP_8 >= PHP_8_1_0 // void // ============================== END // REQUIREMENTS // ============================== // ============================== BEGIN // PHP_IMAGE_GD // ============================== ABOUT // PHP Manual / Function Reference / Image Processing and Generation / GD - Image Processing and GD // URL: https://www.php.net/manual/en/book.image.php // ============================== DESCRIPTION // IMAGE_PROCESSING_AND_GD // // IMAGE_PROCESSING_AND_GD - BEGIN // Image Processing and GD // // INTRODUCTION // INSTALLING_CONFIGURING // PREDEFINED_CONSTANTS // EXAMPLES // GD_AND_IMAGE_FUNCTIONS // THE_GDIMAGE_CLASS // THE_GDFONT_CLASS // // INTRODUCTION - BEGIN // 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 conveniently, 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. // Note: Read the requirements section about how to expand image capabilities to read, write and modify images. To read meta data of pictures taken by digital cameras you need the above mentioned exif extension. // Note: The getimagesize() function does not require the GD extension. // Caution: While the bundled version of the GD library uses the Zend memory manager to allocate memory, system versions do not, so that memory_limit does not apply. // GD supports a varity of formats, below is a list of formats supported by GD and notes to their availability including read/write support. // // Formats supported by GD // Format | Read support | Write support | Notes // JPEG | true | true | // PNG | true | true | // GIF | true | true | // XBM | true | true | // XPM | true | false | // WBMP | true | true | // WebP | true | true | // BMP | true | true | Available as of PHP 7.2.0 // // Despite most formats being available for both reading and writing in the above table, doesn't mean that PHP was compiled with support for them. To find out which formats that was available to GD during compilation, use the gd_info() function, for more information about compiling support for one or more formats, see the installation chapter. // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/intro.image.php // INTRODUCTION - END // // INSTALLING_CONFIGURING - BEGIN // Installing/Configuring // // REQUIREMENTS // INSTALLATION // RUNTIME_CONFIGURATION // RESOURCE_TYPES // // REQUIREMENTS - BEGIN // Requirements // // If you have the GD library (available at > http://www.libgd.org/) 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. // Note: libgd-2.1.0 or higher is required. Alternatively, use the bundled GD library that ships with PHP. // Note: The GD library requires zlib >= 1.2.0.4. // You may wish to enhance GD to handle more image formats. // // Supported image formats // Image format (Library to download) - Notes // gif () - // jpeg (http://www.ijg.org/) - When building the jpeg library (prior to building PHP) you must use the --enable-shared option in the configure step. If you do not, you will receive an error saying libjpeg.(a|so) not found when you get to the configure step of building PHP. // png (http://www.libpng.org/pub/png/libpng.html) - // xpm (http://www.ibiblio.org/pub/Linux/libs/X/!INDEX.html) - It's likely you have this library already available, if your system has an installed X-Environment. // You may wish to enhance GD to deal with different fonts. The > FreeType 2 library is supported. // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.requirements.php // REQUIREMENTS - END // // INSTALLATION - BEGIN // 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, use the configure option --with-gd. GD library requires libpng and libjpeg to compile. As of PHP 7.4.0, --with-gd becomes --enable-gd (whether to enable the extension at all) and --with-external-gd (to opt into using an external libgd, rather than the bundled one). // In Windows, you'll include the GD DLL php_gd.dll as an extension in php.ini. Prior to PHP 8.0.0, the DLL was named php_gd2.dll. // Enhance the capabilities of GD to handle more image formats by specifying the --with-XXXX configure switch to your PHP configure line. // // Supported image formats // Image Format - Configure Switch // jpeg - To enable support for jpeg add --with-jpeg-dir=DIR. Jpeg 6b, 7 or 8 are supported. As of PHP 7.4.0, use --with-jpeg instead. // png - To enable support for png add --with-png-dir=DIR. Note, libpng requires the zlib library, therefore add --with-zlib-dir[=DIR] to your configure line. As of PHP 7.4.0, --with-png-dir and --with-zlib-dir have been removed. libpng and zlib are required. // xpm - To enable support for xpm add --with-xpm-dir=DIR. If configure is not able to find the required libraries, you may add the path to your X11 libraries. As of PHP 7.4.0, use --with-xpm instead. // webp - To enable support for webp add --with-webp-dir=DIR. As of PHP 7.4.0, use --with-webp instead. // Note: When compiling PHP with libpng, you must use the same version that was linked with the GD library. // Enhance the capabilities of GD to deal with different fonts by specifying the --with-XXXX configure switch to your PHP configure line. // // Supported font libraries // Font library - Configure Switch // FreeType 2 - To enable support for FreeType 2 add --with-freetype-dir=DIR. As of PHP 7.4.0 use --with-freetype instead, which relies on pkg-config. // Native TrueType string function - To enable support for native TrueType string function add --enable-gd-native-ttf. (This option has no effect and has been removed as of PHP 7.2.0.) // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.installation.php // INSTALLATION - END // // RUNTIME_CONFIGURATION - BEGIN // Runtime Configuration // // The behaviour of these functions is affected by settings in php.ini. // // Image Configure Options // Name | Default | Changeable | Changelog // gd.jpeg_ignore_warning | "1" | PHP_INI_ALL | // // 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 (but not errors) created by libjpeg(-turbo). // // Changelog for gd.jpeg_ignore_warning // Version - Description // 7.1.0 - The default of gd.jpeg_ignore_warning has been changed from 0 to 1. // // See also the exif configuration directives. // Warning: Image functions are very memory intensive. Be sure to set memory_limit high enough, if you are using the bundled version of the GD library. // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.configuration.php // RUNTIME_CONFIGURATION - END // // RESOURCE_TYPES - BEGIN // Resource Types // // This extension defines the following resource types: // List of resource types in GD // Name | Description | Notes // gd | Image resource, used by functions like imagecreatefrompng() | Prior to PHP 8.0.0 // gd font | Font resource internally created by imageloadfont() | Prior to PHP 8.1.0 // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.resources.php // RESOURCE_TYPES - END // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.setup.php // INSTALLING_CONFIGURING - END // // PREDEFINED_CONSTANTS - BEGIN // 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. // GD_MAJOR_VERSION (int) - The GD major version PHP was compiled against. // GD_MINOR_VERSION (int) - The GD minor version PHP was compiled against. // GD_RELEASE_VERSION (int) - The GD release version PHP was compiled against. // GD_EXTRA_VERSION (string) - The GD "extra" version (beta/rc..) PHP was compiled against. // GD_BUNDLED (int) - When the bundled version of GD is used this is 1 otherwise its set to 0. // IMG_AVIF (int) - Used as a return value by imagetypes() (Available as of PHP 8.1.0) // IMG_BMP (int) - Used as a return value by imagetypes() // IMG_GIF (int) - Used as a return value by imagetypes() // IMG_JPG (int) - Used as a return value by imagetypes() // IMG_JPEG (int) - Used as a return value by imagetypes() // Note: This constant has the same value as IMG_JPG // IMG_PNG (int) - Used as a return value by imagetypes() // IMG_WBMP (int) - Used as a return value by imagetypes() // IMG_XPM (int) - Used as a return value by imagetypes() // IMG_WEBP (int) - Used as a return value by imagetypes() (Available as of PHP 7.0.10) // IMG_WEBP_LOSSLESS (int) - (Available as of PHP 8.1.0) // IMG_COLOR_TILED (int) - Special color option which can be used instead of a color allocated with imagecolorallocate() or imagecolorallocatealpha(). // IMG_COLOR_STYLED (int) - Special color option which can be used instead of a color allocated with imagecolorallocate() or imagecolorallocatealpha(). // IMG_COLOR_BRUSHED (int) - Special color option which can be used instead of a color allocated with imagecolorallocate() or imagecolorallocatealpha(). // IMG_COLOR_STYLEDBRUSHED (int) - Special color option which can be used instead of a color allocated with imagecolorallocate() or imagecolorallocatealpha(). // IMG_COLOR_TRANSPARENT (int) - Special color option which can be used instead of a color allocated with imagecolorallocate() or imagecolorallocatealpha(). // IMG_AFFINE_TRANSLATE (int) - An affine transformation type constant used by the imageaffinematrixget() function. // IMG_AFFINE_SCALE (int) - An affine transformation type constant used by the imageaffinematrixget() function. // IMG_AFFINE_ROTATE (int) - An affine transformation type constant used by the imageaffinematrixget() function. // IMG_AFFINE_SHEAR_HORIZONTAL (int) - An affine transformation type constant used by the imageaffinematrixget() function. // IMG_AFFINE_SHEAR_VERTICAL (int) - An affine transformation type constant used by the imageaffinematrixget() function. // IMG_ARC_ROUNDED (int) - A style constant used by the imagefilledarc() function. // Note: This constant has the same value as IMG_ARC_PIE // IMG_ARC_PIE (int) - A style constant used by the imagefilledarc() function. // IMG_ARC_CHORD (int) - A style constant used by the imagefilledarc() function. // IMG_ARC_NOFILL (int) - A style constant used by the imagefilledarc() function. // IMG_ARC_EDGED (int) - A style constant used by the imagefilledarc() function. // IMG_GD2_RAW (int) - A type constant used by the imagegd2() function. // IMG_GD2_COMPRESSED (int) - A type constant used by the imagegd2() function. // IMG_EFFECT_REPLACE (int) - Alpha blending effect used by the imagelayereffect() function. // IMG_EFFECT_ALPHABLEND (int) - Alpha blending effect used by the imagelayereffect() function. // IMG_EFFECT_NORMAL (int) - Alpha blending effect used by the imagelayereffect() function. // IMG_EFFECT_OVERLAY (int) - Alpha blending effect used by the imagelayereffect() function. // IMG_EFFECT_MULTIPLY (int) - Alpha blending effect used by the imagelayereffect() function. // IMG_FILTER_NEGATE (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_GRAYSCALE (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_BRIGHTNESS (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_CONTRAST (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_COLORIZE (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_EDGEDETECT (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_GAUSSIAN_BLUR (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_SELECTIVE_BLUR (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_EMBOSS (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_MEAN_REMOVAL (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_SMOOTH (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_PIXELATE (int) - Special GD filter used by the imagefilter() function. // IMG_FILTER_SCATTER (int) - Special GD filter used by the imagefilter() function. (Available as of PHP 7.4.0) // IMAGETYPE_GIF (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_JPEG (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_JPEG2000 (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_PNG (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_SWF (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_PSD (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_BMP (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_WBMP (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_XBM (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_TIFF_II (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_TIFF_MM (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_IFF (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_JB2 (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_JPC (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_JP2 (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_JPX (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_SWC (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_ICO (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. // IMAGETYPE_WEBP (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. (Available as of PHP 7.1.0) // IMAGETYPE_AVIF (int) - Image type constant used by the image_type_to_mime_type() and image_type_to_extension() functions. (Available as of PHP 8.1.0) // PNG_NO_FILTER (int) - A special PNG filter, used by the imagepng() function. // PNG_FILTER_NONE (int) - A special PNG filter, used by the imagepng() function. // PNG_FILTER_SUB (int) - A special PNG filter, used by the imagepng() function. // PNG_FILTER_UP (int) - A special PNG filter, used by the imagepng() function. // PNG_FILTER_AVG (int) - A special PNG filter, used by the imagepng() function. // PNG_FILTER_PAETH (int) - A special PNG filter, used by the imagepng() function. // PNG_ALL_FILTERS (int) - A special PNG filter, used by the imagepng() function. // IMG_FLIP_VERTICAL (int) - Used together with imageflip(), available as of PHP 5.5.0. // IMG_FLIP_HORIZONTAL (int) - Used together with imageflip(), available as of PHP 5.5.0. // IMG_FLIP_BOTH (int) - Used together with imageflip(), available as of PHP 5.5.0. // IMG_BELL (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BESSEL (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BILINEAR_FIXED (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BICUBIC (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BICUBIC_FIXED (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BLACKMAN (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BOX (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_BSPLINE (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_CATMULLROM (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_GAUSSIAN (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_GENERALIZED_CUBIC (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_HERMITE (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_HAMMING (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_HANNING (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_MITCHELL (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_POWER (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_QUADRATIC (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_SINC (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_NEAREST_NEIGHBOUR (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_WEIGHTED4 (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // IMG_TRIANGLE (int) - Used together with imagesetinterpolation(), available as of PHP 5.5.0. // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.constants.php // PREDEFINED_CONSTANTS - END // // EXAMPLES - BEGIN // Examples // // PNG_CREATION_WITH_PHP // ADDING_WATERMARKS_TO_IMAGES_USING_ALPHA_CHANNELS // USING_IMAGECOPYMERGE_TO_CREATE_A_TRANSLUCENT_WATERMARK // // PNG_CREATION_WITH_PHP - BEGIN // PNG creation with PHP // // [example] // Example #1 PNG creation with PHP // [php] // // header("Content-type: image/png"); // $string = $_GET['text']; // $im = imagecreatefrompng("images/button1.png"); // $orange = imagecolorallocate($im, 220, 210, 60); // $px = (imagesx($im) - 7.5 * strlen($string)) / 2; // imagestring($im, 3, $px, 9, $string, $orange); // imagepng($im); // imagedestroy($im); // // [/php] // This example would be called from a page with a tag like: . The above button.php script then takes this "text" string and overlays it on top of a base image which in this case is "images/button1.png" and outputs the resulting image. This is a very convenient way to avoid having to draw new button images every time you want to change the text of a button. With this method they are dynamically generated. // [/example] // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.examples-png.php // PNG_CREATION_WITH_PHP - END // // ADDING_WATERMARKS_TO_IMAGES_USING_ALPHA_CHANNELS - BEGIN // Adding watermarks to images using alpha channels // // [example] // Example #1 Adding watermarks to images using alpha channels // [php] // // Load the stamp and the photo to apply the watermark to // $stamp = imagecreatefrompng('stamp.png'); // $im = imagecreatefromjpeg('photo.jpeg'); // // // Set the margins for the stamp and get the height/width of the stamp image // $marge_right = 10; // $marge_bottom = 10; // $sx = imagesx($stamp); // $sy = imagesy($stamp); // // // Copy the stamp image onto our photo using the margin offsets and the photo // // width to calculate positioning of the stamp. // imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp)); // // // Output and free memory // header('Content-type: image/png'); // imagepng($im); // imagedestroy($im); // [/php] // This example is a common way to add watermarks and stamps to photos and copyrighted images. Note that the presence of an alpha channel in the stamp image as the text is anti-aliased. This is preserved during copying. // [/example] // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.examples-watermark.php // ADDING_WATERMARKS_TO_IMAGES_USING_ALPHA_CHANNELS - END // // USING_IMAGECOPYMERGE_TO_CREATE_A_TRANSLUCENT_WATERMARK - BEGIN // Using imagecopymerge() to create a translucent watermark // // [example] // Example #1 Using imagecopymerge() to create a translucent watermark // [php] // // Load the stamp and the photo to apply the watermark to // $im = imagecreatefromjpeg('photo.jpeg'); // // // First we create our stamp image manually from GD // $stamp = imagecreatetruecolor(100, 70); // imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF); // imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF); // imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF); // imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0x0000FF); // // // Set the margins for the stamp and get the height/width of the stamp image // $marge_right = 10; // $marge_bottom = 10; // $sx = imagesx($stamp); // $sy = imagesy($stamp); // // // Merge the stamp onto our photo with an opacity of 50% // imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50); // // // Save the image to file and free memory // imagepng($im, 'photo_stamp.png'); // imagedestroy($im); // // [/php] // This example uses imagecopymerge() to merge the stamp with our original image. Using this we can set the opacity of our stamp - in our example we've set it to 50% opacity. In practice this would be useful in copyright protection as semi-transparent watermarks are hard to remove yet allow viewers to see the image. // [/example] // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.examples.merged-watermark.php // USING_IMAGECOPYMERGE_TO_CREATE_A_TRANSLUCENT_WATERMARK - END // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/image.examples.php // EXAMPLES - END // // GD_AND_IMAGE_FUNCTIONS - BEGIN // GD and Image Functions // // Table of Contents // * gd_info - Retrieve information about the currently installed GD library // * getimagesize - Get the size of an image // * getimagesizefromstring - Get the size of an image from a string // * image_type_to_extension - Get file extension for image type // * image_type_to_mime_type - Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype // * image2wbmp - Output image to browser or file // * imageaffine - Return an image containing the affine transformed src image, using an optional clipping area // * imageaffinematrixconcat - Concatenate two affine transformation matrices // * imageaffinematrixget - Get an affine transformation matrix // * imagealphablending - Set the blending mode for an image // * imageantialias - Should antialias functions be used or not // * imagearc - Draws an arc // * imageavif - Output image to browser or file // * imagebmp - Output a BMP image to browser or file // * imagechar - Draw a character horizontally // * imagecharup - Draw a character vertically // * imagecolorallocate - Allocate a color for an image // * imagecolorallocatealpha - Allocate a color for an image // * imagecolorat - Get the index of the color of a pixel // * imagecolorclosest - Get the index of the closest color to the specified color // * imagecolorclosestalpha - Get the index of the closest color to the specified color + alpha // * imagecolorclosesthwb - Get the index of the color which has the hue, white and blackness // * imagecolordeallocate - De-allocate a color for an image // * imagecolorexact - Get the index of the specified color // * imagecolorexactalpha - Get the index of the specified color + alpha // * imagecolormatch - Makes the colors of the palette version of an image more closely match the true color version // * imagecolorresolve - Get the index of the specified color or its closest possible alternative // * imagecolorresolvealpha - Get the index of the specified color + alpha or its closest possible alternative // * imagecolorset - Set the color for the specified palette index // * imagecolorsforindex - Get the colors for an index // * imagecolorstotal - Find out the number of colors in an image's palette // * imagecolortransparent - Define a color as transparent // * imageconvolution - Apply a 3x3 convolution matrix, using coefficient and offset // * imagecopy - Copy part of an image // * imagecopymerge - Copy and merge part of an image // * imagecopymergegray - Copy and merge part of an image with gray scale // * imagecopyresampled - Copy and resize part of an image with resampling // * imagecopyresized - Copy and resize part of an image // * imagecreate - Create a new palette based image // * imagecreatefromavif - Create a new image from file or URL // * imagecreatefrombmp - Create a new image from file or URL // * imagecreatefromgd2 - Create a new image from GD2 file or URL // * imagecreatefromgd2part - Create a new image from a given part of GD2 file or URL // * imagecreatefromgd - Create a new image from GD file or URL // * imagecreatefromgif - Create a new image from file or URL // * imagecreatefromjpeg - Create a new image from file or URL // * imagecreatefrompng - Create a new image from file or URL // * imagecreatefromstring - Create a new image from the image stream in the string // * imagecreatefromtga - Create a new image from file or URL // * imagecreatefromwbmp - Create a new image from file or URL // * imagecreatefromwebp - Create a new image from file or URL // * imagecreatefromxbm - Create a new image from file or URL // * imagecreatefromxpm - Create a new image from file or URL // * imagecreatetruecolor - Create a new true color image // * imagecrop - Crop an image to the given rectangle // * imagecropauto - Crop an image automatically using one of the available modes // * imagedashedline - Draw a dashed line // * imagedestroy - Destroy an image // * imageellipse - Draw an ellipse // * imagefill - Flood fill // * imagefilledarc - Draw a partial arc and fill it // * imagefilledellipse - Draw a filled ellipse // * imagefilledpolygon - Draw a filled polygon // * imagefilledrectangle - Draw a filled rectangle // * imagefilltoborder - Flood fill to specific color // * imagefilter - Applies a filter to an image // * imageflip - Flips an image using a given mode // * imagefontheight - Get font height // * imagefontwidth - Get font width // * imageftbbox - Give the bounding box of a text using fonts via freetype2 // * imagefttext - Write text to the image using fonts using FreeType 2 // * imagegammacorrect - Apply a gamma correction to a GD image // * imagegd2 - Output GD2 image to browser or file // * imagegd - Output GD image to browser or file // * imagegetclip - Get the clipping rectangle // * imagegetinterpolation - Get the interpolation method // * imagegif - Output image to browser or file // * imagegrabscreen - Captures the whole screen // * imagegrabwindow - Captures a window // * imageinterlace - Enable or disable interlace // * imageistruecolor - Finds whether an image is a truecolor image // * imagejpeg - Output image to browser or file // * imagelayereffect - Set the alpha blending flag to use layering effects // * imageline - Draw a line // * imageloadfont - Load a new font // * imageopenpolygon - Draws an open polygon // * imagepalettecopy - Copy the palette from one image to another // * imagepalettetotruecolor - Converts a palette based image to true color // * imagepng - Output a PNG image to either the browser or a file // * imagepolygon - Draws a polygon // * imagerectangle - Draw a rectangle // * imageresolution - Get or set the resolution of the image // * imagerotate - Rotate an image with a given angle // * imagesavealpha - Whether to retain full alpha channel information when saving images // * imagescale - Scale an image using the given new width and height // * imagesetbrush - Set the brush image for line drawing // * imagesetclip - Set the clipping rectangle // * imagesetinterpolation - Set the interpolation method // * imagesetpixel - Set a single pixel // * imagesetstyle - Set the style for line drawing // * imagesetthickness - Set the thickness for line drawing // * imagesettile - Set the tile image for filling // * imagestring - Draw a string horizontally // * imagestringup - Draw a string vertically // * imagesx - Get image width // * imagesy - Get image height // * imagetruecolortopalette - Convert a true color image to a palette image // * imagettfbbox - Give the bounding box of a text using TrueType fonts // * imagettftext - Write text to the image using TrueType fonts // * imagetypes - Return the image types supported by this PHP build // * imagewbmp - Output image to browser or file // * imagewebp - Output a WebP image to browser or file // * imagexbm - Output an XBM image to browser or file // * iptcembed - Embeds binary IPTC data into a JPEG image // * iptcparse - Parse a binary IPTC block into single tags // * jpeg2wbmp - Convert JPEG image file to WBMP image file // * png2wbmp - Convert PNG image file to WBMP image file // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/ref.image.php // GD_AND_IMAGE_FUNCTIONS - END // // THE_GDIMAGE_CLASS - BEGIN // The GdImage class // // PHP_8 // // Introduction // A fully opaque class which replaces gd resources as of PHP 8.0.0. // // Class synopsis // [code] // final class GdImage { // } // [/code] // // LITERATURE_SOURCES // * PHP_NET (2023-11-11) // URL: https://www.php.net/manual/en/class.gdimage.php // THE_GDIMAGE_CLASS - END // // THE_GDFONT_CLASS - BEGIN // The GdFont class // // PHP_8 >= PHP_8_1_0 // // Introduction // A fully opaque class which replaces gd font resources as of PHP 8.1.0. // // Class synopsis // [code] // final class GdFont { // } // [/code] // // LITERATURE_SOURCES // * PHP_NET (2023-11-11) // URL: https://www.php.net/manual/en/class.gdfont.php // THE_GDFONT_CLASS - END // // LITERATURE_SOURCES // * PHP_NET (2023-09-09) // URL: https://www.php.net/manual/en/book.image.php // IMAGE_PROCESSING_AND_GD - END // ============================== // ============================== BEGIN // PHP_IMAGE_GD_GD_INFO // ============================== PUBLIC // ============================== ABOUT // Retrieve information about the currently installed GD library. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // gd_info() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_gd_info() { $return_gd_info = null; // ========== GD_INFO - BEGIN // ===== ABOUT // Retrieve information about the currently installed GD library // ===== DESCRIPTION // Gets information about the version and capabilities of the installed GD library. // ===== SUPPORTED // PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // gd_info(): array // ===== CODE $return_gd_info = gd_info( // This function has no parameters. ); // Return Values // Returns an associative array. // Elements of array returned by gd_info() // Attribute - Meaning // GD Version - string value describing the installed libgd version. // FreeType Support - bool value. true if FreeType Support is installed. // FreeType Linkage - string value describing the way in which FreeType was linked. Expected values are: 'with freetype', 'with TTF library', and 'with unknown library'. This element will only be defined if FreeType Support evaluated to true. // GIF Read Support - bool value. true if support for reading GIF images is included. // GIF Create Support - bool value. true if support for creating GIF images is included. // JPEG Support - bool value. true if JPEG support is included. // PNG Support - bool value. true if PNG support is included. // WBMP Support - bool value. true if WBMP support is included. // XBM Support - bool value. true if XBM support is included. // WebP Support - bool value. true if WebP support is included. // AVIF Support - bool value. true if AVIF support is included. Available as of PHP 8.1.0. // // [examples] // Examples // [example] // Example #1 Using gd_info() // [php] // var_dump(gd_info()); // [/php] // The above example will output something similar to: // [result] // array(10) { // ["GD Version"]=> // string(24) "bundled (2.1.0 compatible)" // ["FreeType Support"]=> // bool(false) // ["GIF Read Support"]=> // bool(true) // ["GIF Create Support"]=> // bool(false) // ["JPEG Support"]=> // bool(false) // ["PNG Support"]=> // bool(true) // ["WBMP Support"]=> // bool(true) // ["XBM Support"]=> // bool(false) // ["WebP Support"]=> // bool(false) // ["AVIF Support"]=> // bool(false) // } // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.gd-info.php // ========== GD_INFO - END // SYNTAX: // array gd_info() return $return_gd_info; // array } // ============================== END // PHP_IMAGE_GD_GD_INFO // ============================== // ============================== BEGIN // PHP_IMAGE_GD_GETIMAGESIZE // ============================== PUBLIC // ============================== ABOUT // Get the size of an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // getimagesize() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_getimagesize($filename, & $image_info) { $return_getimagesize = false; // ========== GETIMAGESIZE - BEGIN // ===== ABOUT // Get the size of an image // ===== DESCRIPTION // The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type. // getimagesize() can also return some more information in image_info parameter. // Caution: // This function expects filename to be a valid image file. If a non-image file is supplied, it may be incorrectly detected as an image and the function will return successfully, but the array may contain nonsensical values. // Do not use getimagesize() to check that a given file is a valid image. Use a purpose-built solution such as the Fileinfo extension instead. // Note: Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain multiple JPEG 2000 codestreams. In this case, getimagesize() returns the values for the first codestream it encounters in the root of the file. // Note: The information about icons are retrieved from the icon with the highest bitrate. // Note: GIF images consist of one or more frames, where each frame may only occupy part of the image. The size of the image which is reported by getimagesize() is the overall size (read from the logical screen descriptor). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // getimagesize(string $filename, array &$image_info = null): array|false // ===== CODE $return_getimagesize = getimagesize( $filename, // string filename - This parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams. $image_info // array image_info - This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed > IPTC information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable. // Note: The image_info only supports JFIF files. ); // Return Values // Returns an array with up to 7 elements. Not all image types will include the channels and bits elements. // Index 0 and 1 contains respectively the width and the height of the image. // Note: Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases. // Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image. // Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag. // mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header: // [example] // Example #1 getimagesize() and MIME types // [php] // $size = getimagesize($filename); // $fp = fopen($filename, "rb"); // if ($size && $fp) { // header("Content-type: {$size['mime']}"); // fpassthru($fp); // exit; // } else { // // error // } // [/php] // channels will be 3 for RGB pictures and 4 for CMYK pictures. // bits is the number of bits for each color. // For some image types, the presence of channels and bits values can be a bit confusing. As an example, GIF always uses 3 channels per pixel, but the number of bits per pixel cannot be calculated for an animated GIF with a global color table. // On failure, false is returned. // [/example] // // Errors/Exceptions // If accessing the filename image is impossible getimagesize() will generate an error of level E_WARNING. On read error, getimagesize() will generate an error of level E_NOTICE. // // Changelog // Version - Description // 8.2.0 - Now returns the actual image dimensions, bits and channels of AVIF images; previously, the dimensions were reported as 0x0, and bits and channels were not reported at all. // 7.1.0 - Added WebP support. // // [examples] // Examples // [example] // Example #2 getimagesize() example // [php] // list($width, $height, $type, $attr) = getimagesize("img/flag.jpg"); // echo "\"getimagesize()"; // [/php] // [/example] // [example] // Example #3 getimagesize (URL) // [php] // $size = getimagesize("http://www.example.com/gifs/logo.gif"); // // // if the file name has space in it, encode it properly // $size = getimagesize("http://www.example.com/gifs/lo%20go.gif"); // // [/php] // [/example] // [example] // Example #4 getimagesize() returning IPTC // [php] // $size = getimagesize("testimg.jpg", $info); // if (isset($info["APP13"])) { // $iptc = iptcparse($info["APP13"]); // var_dump($iptc); // } // [/php] // [/example] // [/examples] // // Notes // Note: This function does not require the GD image library. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.getimagesize.php // ========== GETIMAGESIZE - END // SYNTAX: // array|false getimagesize(string $filename, array& $image_info) return $return_getimagesize; // array|false } // ============================== END // PHP_IMAGE_GD_GETIMAGESIZE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_GETIMAGESIZEFROMSTRING // ============================== OFFLINE // ============================== ABOUT // Get the size of an image from a string. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // getimagesizefromstring() - PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_getimagesizefromstring($string, & $image_info) { $return_getimagesizefromstring = false; // ========== GETIMAGESIZEFROMSTRING - BEGIN // ===== ABOUT // Get the size of an image from a string // ===== DESCRIPTION // Identical to getimagesize() except that getimagesizefromstring() accepts a string instead of a file name as the first parameter. // See the getimagesize() documentation for details on how this function works. // ===== SUPPORTED // PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // ===== SYNTAX // getimagesizefromstring(string $string, array &$image_info = null): array|false // ===== CODE $return_getimagesizefromstring = getimagesizefromstring( $string, // string string - The image data, as a string. $image_info // array& image_info - See getimagesize(). ); // Return Values // See getimagesize(). // // [examples] // Examples // [example] // Example #1 getimagesizefromstring() example // [php] // $img = '/path/to/test.png'; // // // Open as a file // $size_info1 = getimagesize($img); // // // Or open as a string // $data = file_get_contents($img); // $size_info2 = getimagesizefromstring($data); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.getimagesizefromstring.php // ========== GETIMAGESIZEFROMSTRING - END // SYNTAX: // array|false getimagesizefromstring(string $string, array& $image_info) return $return_getimagesizefromstring; // array|false } */ // ============================== END // PHP_IMAGE_GD_GETIMAGESIZEFROMSTRING // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGE_TYPE_TO_EXTENSION // ============================== OFFLINE // ============================== ABOUT // Get file extension for image type. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // image_type_to_extension() - PHP_5 >= PHP_5_2_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_image_type_to_extension($image_type, $include_dot = true) { $return_image_type_to_extension = false; // ========== IMAGE_TYPE_TO_EXTENSION - BEGIN // ===== ABOUT // Get file extension for image type // ===== DESCRIPTION // Returns the extension for the given IMAGETYPE_XXX constant. // ===== SUPPORTED // PHP_5 >= PHP_5_2_0, PHP_7, PHP_8 // ===== SYNTAX // image_type_to_extension(int $image_type, bool $include_dot = true): string|false // ===== CODE $return_image_type_to_extension = image_type_to_extension( $image_type, // int image_type - One of the IMAGETYPE_XXX constant. $include_dot // bool include_dot - Whether to prepend a dot to the extension or not. Default to true. ); // Return Values // A string with the extension corresponding to the given image type, or false on failure. // // [examples] // Examples // [example] // Example #1 image_type_to_extension() example // [php] // // Create image instance // $im = imagecreatetruecolor(100, 100); // // // Save image // imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG)); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: This function does not require the GD image library. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.image-type-to-extension.php // ========== IMAGE_TYPE_TO_EXTENSION - END // SYNTAX: // string|false image_type_to_extension(int $image_type, bool $include_dot = true) return $return_image_type_to_extension; // string|false } */ // ============================== END // PHP_IMAGE_GD_IMAGE_TYPE_TO_EXTENSION // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGE_TYPE_TO_MIME_TYPE // ============================== PUBLIC // ============================== ABOUT // Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // image_type_to_mime_type() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_image_type_to_mime_type($image_type) { $return_image_type_to_mime_type = null; // ========== IMAGE_TYPE_TO_MIME_TYPE - BEGIN // ===== ABOUT // Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype // ===== DESCRIPTION // The image_type_to_mime_type() function will determine the Mime-Type for an IMAGETYPE constant. // ===== SUPPORTED // PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // image_type_to_mime_type(int $image_type): string // ===== CODE $return_image_type_to_mime_type = image_type_to_mime_type( $image_type // int image_type - One of the IMAGETYPE_XXX constants. ); // Return Values // The returned values are as follows // Returned values Constants // image_type - Returned value // IMAGETYPE_GIF - image/gif // IMAGETYPE_JPEG - image/jpeg // IMAGETYPE_PNG - image/png // IMAGETYPE_SWF - application/x-shockwave-flash // IMAGETYPE_PSD - image/psd // IMAGETYPE_BMP - image/bmp // IMAGETYPE_TIFF_II - (intel byte order) image/tiff // IMAGETYPE_TIFF_MM - (motorola byte order) image/tiff // IMAGETYPE_JPC - application/octet-stream // IMAGETYPE_JP2 - image/jp2 // IMAGETYPE_JPX - application/octet-stream // IMAGETYPE_JB2 - application/octet-stream // IMAGETYPE_SWC - application/x-shockwave-flash // IMAGETYPE_IFF - image/iff // IMAGETYPE_WBMP - image/vnd.wap.wbmp // IMAGETYPE_XBM - image/xbm // IMAGETYPE_ICO - image/vnd.microsoft.icon // IMAGETYPE_WEBP - image/webp // IMAGETYPE_AVIF - image/avif // // [examples] // Examples // [example] // Example #1 image_type_to_mime_type() example // [php] // header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG)); // [/php] // [/example] // [/examples] // // Notes // Note: This function does not require the GD image library. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.image-type-to-mime-type.php // ========== IMAGE_TYPE_TO_MIME_TYPE - END // SYNTAX: // string image_type_to_mime_type(int $image_type) return $return_image_type_to_mime_type; // string } // ============================== END // PHP_IMAGE_GD_IMAGE_TYPE_TO_MIME_TYPE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGE2WBMP // ============================== OFFLINE // ============================== ABOUT // Output image to browser or file. // // Warning: This function has been DEPRECATED as of PHP 7.3.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. // ============================== SUPPORT // PHP_4 - PHP_7 // ============================== USING FUNCTIONS (1) // image2wbmp() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ============================== CODE /* function php_image_gd_image2wbmp($image, $filename, $foreground) { $return_image2wbmp = false; // ========== IMAGE2WBMP - BEGIN // ===== ABOUT // Output image to browser or file // Warning: This function has been DEPRECATED as of PHP 7.3.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. // ===== DESCRIPTION // image2wbmp() outputs or save a WBMP version of the given image. // ===== SUPPORTED // PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ===== SYNTAX // image2wbmp(resource $image, string $filename = ?, int $foreground = ?): bool // ===== CODE $return_image2wbmp = image2wbmp( $image, // resource image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). $filename, // string filename - Path to the saved file. If not given, the raw image stream will be output directly. $foreground // int foreground - You can set the foreground color with this parameter by setting an identifier obtained from imagecolorallocate(). The default foreground color is black. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // [examples] // Examples // [example] // Example #1 image2wbmp() example // [php] // $file = 'php.png'; // $image = imagecreatefrompng($file); // // header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_WBMP)); // image2wbmp($image); // output the stream directly // imagedestroy($image); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.image2wbmp.php // ========== IMAGE2WBMP - END // SYNTAX: // bool image2wbmp(resource $image, string $filename, int $foreground) return $return_image2wbmp; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGE2WBMP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEAFFINE // ============================== OFFLINE // ============================== ABOUT // Return an image containing the affine transformed src image, using an optional clipping area. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imageaffine() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imageaffine($image, $affine, $clip = null) { $return_imageaffine = false; // ========== IMAGEAFFINE - BEGIN // ===== ABOUT // Return an image containing the affine transformed src image, using an optional clipping area // ===== DESCRIPTION // Warning: This function is currently not documented; only its argument list is available. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imageaffine(GdImage $image, array $affine, ?array $clip = null): GdImage|false // ===== CODE $return_imageaffine = imageaffine( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $affine, // array affine - Array with keys 0 to 5. $clip // array clip - Array with keys "x", "y", "width" and "height"; or null. ); // Return Values // Return affined image object on success or false on failure. // // Changelog // Version - Description // 8.0.0 - clip is now nullable. // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imageaffine.php // ========== IMAGEAFFINE - END // SYNTAX: // GdImage|false imageaffine(GdImage $image, array $affine, array $clip = null) return $return_imageaffine; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGEAFFINE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEAFFINEMATRIXCONCAT // ============================== OFFLINE // ============================== ABOUT // Concatenate two affine transformation matrices. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imageaffinematrixconcat() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imageaffinematrixconcat($matrix1, $matrix2) { $return_imageaffinematrixconcat = false; // ========== IMAGEAFFINEMATRIXCONCAT - BEGIN // ===== ABOUT // Concatenate two affine transformation matrices // ===== DESCRIPTION // Returns the concatenation of two affine transformation matrices, what is useful if multiple transformations should be applied to the same image in one go. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imageaffinematrixconcat(array $matrix1, array $matrix2): array|false // ===== CODE $return_imageaffinematrixconcat = imageaffinematrixconcat( $matrix1, // array matrix1 - An affine transformation matrix (an array with keys 0 to 5 and float values). $matrix2 // array matrix2 - An affine transformation matrix (an array with keys 0 to 5 and float values). ); // Return Values // An affine transformation matrix (an array with keys 0 to 5 and float values) or false on failure. // // [examples] // Examples // [example] // Example #1 imageaffinematrixconcat() example // [php] // $m1 = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' => 2, 'y' => 3)); // $m2 = imageaffinematrixget(IMG_AFFINE_SCALE, array('x' => 4, 'y' => 5)); // $matrix = imageaffinematrixconcat($m1, $m2); // print_r($matrix); // [/php] The above example will output: // [result] // Array // ( // [0] => 4 // [1] => 0 // [2] => 0 // [3] => 5 // [4] => 8 // [5] => 15 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imageaffinematrixconcat.php // ========== IMAGEAFFINEMATRIXCONCAT - END // SYNTAX: // array|false imageaffinematrixconcat(array $matrix1, array $matrix2) return $return_imageaffinematrixconcat; // array|false } */ // ============================== END // PHP_IMAGE_GD_IMAGEAFFINEMATRIXCONCAT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEAFFINEMATRIXGET // ============================== OFFLINE // ============================== ABOUT // Get an affine transformation matrix. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imageaffinematrixget() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imageaffinematrixget($type, $options) { $return_imageaffinematrixget = false; // ========== IMAGEAFFINEMATRIXGET - BEGIN // ===== ABOUT // Get an affine transformation matrix // ===== DESCRIPTION // Returns an affine transformation matrix. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imageaffinematrixget(int $type, array|float $options): array|false // ===== CODE $return_imageaffinematrixget = imageaffinematrixget( $type, // int type - One of the IMG_AFFINE_* constants. $options // array|float options - If type is IMG_AFFINE_TRANSLATE or IMG_AFFINE_SCALE, options has to be an array with keys x and y, both having float values. // If type is IMG_AFFINE_ROTATE, IMG_AFFINE_SHEAR_HORIZONTAL or IMG_AFFINE_SHEAR_VERTICAL, options has to be a float specifying the angle. ); // Return Values // An affine transformation matrix (an array with keys 0 to 5 and float values) or false on failure. // // [examples] // Examples // [example] // Example #1 imageaffinematrixget() example // [php] // $matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, array('x' => 2, 'y' => 3)); // print_r($matrix); // [/php] // The above example will output: // [result] // Array // ( // [0] => 1 // [1] => 0 // [2] => 0 // [3] => 1 // [4] => 2 // [5] => 3 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imageaffinematrixget.php // ========== IMAGEAFFINEMATRIXGET - END // SYNTAX: // array|false imageaffinematrixget(int $type, array|float $options) return $return_imageaffinematrixget; // array|false } */ // ============================== END // PHP_IMAGE_GD_IMAGEAFFINEMATRIXGET // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEALPHABLENDING // ============================== PUBLIC // ============================== ABOUT // Set the blending mode for an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagealphablending() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagealphablending($image, $enable) { $return_imagealphablending = false; // ========== IMAGEALPHABLENDING - BEGIN // ===== ABOUT // Set the blending mode for an image // ===== DESCRIPTION // imagealphablending() allows for two different modes of drawing on truecolor images. In blending mode, the alpha channel component of the color supplied to all drawing function, such as imagesetpixel() determines how much of the underlying color should be allowed to shine through. As a result, gd automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagealphablending(GdImage $image, bool $enable): bool // ===== CODE $return_imagealphablending = imagealphablending( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $enable // bool enable - Whether to enable the blending mode or not. On true color images the default value is true otherwise the default value is false ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagealphablending() usage example // [php] // // Create image // $im = imagecreatetruecolor(100, 100); // // // Set alphablending to on // imagealphablending($im, true); // // // Draw a square // imagefilledrectangle($im, 30, 30, 70, 70, imagecolorallocate($im, 255, 0, 0)); // // // Output // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagealphablending.php // ========== IMAGEALPHABLENDING - END // SYNTAX: // bool imagealphablending(GdImage $image, bool $enable) return $return_imagealphablending; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEALPHABLENDING // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEANTIALIAS // ============================== PUBLIC // ============================== ABOUT // Should antialias functions be used or not. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageantialias() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageantialias($image, $enable) { $return_imageantialias = false; // ========== IMAGEANTIALIAS - BEGIN // ===== ABOUT // Should antialias functions be used or not // ===== DESCRIPTION // Activate the fast drawing antialiased methods for lines and wired polygons. It does not support alpha components. It works using a direct blend operation. It works only with truecolor images. // Thickness and styled are not supported. // Using antialiased primitives with transparent background color can end with some unexpected results. The blend method uses the background color as any other colors. The lack of alpha component support does not allow an alpha based antialiasing method. // ===== SUPPORTED // PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageantialias(GdImage $image, bool $enable): bool // ===== CODE $return_imageantialias = imageantialias( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $enable // bool enable - Whether to enable antialiasing or not. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 7.2.0 - imageantialias() is now generally available. Formerly it was only available if PHP was compiled with the bundled version of the GD library. // // [examples] // Examples // [example] // Example #1 A comparison of two lines, one with anti-aliasing switched on // [php] // // Setup an anti-aliased image and a normal image // $aa = imagecreatetruecolor(400, 100); // $normal = imagecreatetruecolor(200, 100); // // // Switch antialiasing on for one image // imageantialias($aa, true); // // // Allocate colors // $red = imagecolorallocate($normal, 255, 0, 0); // $red_aa = imagecolorallocate($aa, 255, 0, 0); // // // // Draw two lines, one with AA enabled // imageline($normal, 0, 0, 200, 100, $red); // imageline($aa, 0, 0, 200, 100, $red_aa); // // // Merge the two images side by side for output (AA: left, Normal: Right) // imagecopymerge($aa, $normal, 200, 0, 0, 0, 200, 100, 100); // // // Output image // header('Content-type: image/png'); // // imagepng($aa); // imagedestroy($aa); // imagedestroy($normal); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imageantialias.php // ========== IMAGEANTIALIAS - END // SYNTAX: // bool imageantialias(GdImage $image, bool $enable) return $return_imageantialias; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEANTIALIAS // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEARC // ============================== PUBLIC // ============================== ABOUT // Draws an arc. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagearc() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagearc($image, $center_x, $center_y, $width, $height, $start_angle, $end_angle, $color) { $return_imagearc = false; // ========== IMAGEARC - BEGIN // ===== ABOUT // Draws an arc // ===== DESCRIPTION // imagearc() draws an arc of circle centered at the given coordinates. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagearc( // GdImage $image, // int $center_x, // int $center_y, // int $width, // int $height, // int $start_angle, // int $end_angle, // int $color // ): bool // ===== CODE $return_imagearc = imagearc( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $center_x, // int center_x - x-coordinate of the center. $center_y, // int center_y - y-coordinate of the center. $width, // int width - The arc width. $height, // int height - The arc height. $start_angle, // int start_angle - The arc start angle, in degrees. $end_angle, // int end_angle - The arc end angle, in degrees. 0° is located at the three-o'clock position, and the arc is drawn clockwise. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Drawing a circle with imagearc() // [php] // // // create a 200*200 image // $img = imagecreatetruecolor(200, 200); // // // allocate some colors // $white = imagecolorallocate($img, 255, 255, 255); // $red = imagecolorallocate($img, 255, 0, 0); // $green = imagecolorallocate($img, 0, 255, 0); // $blue = imagecolorallocate($img, 0, 0, 255); // // // draw the head // imagearc($img, 100, 100, 200, 200, 0, 360, $white); // // mouth // imagearc($img, 100, 100, 150, 150, 25, 155, $red); // // left and then the right eye // imagearc($img, 60, 75, 50, 50, 0, 360, $green); // imagearc($img, 140, 75, 50, 50, 0, 360, $blue); // // // output image in the browser // header("Content-type: image/png"); // imagepng($img); // // // free memory // imagedestroy($img); // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagearc.php // ========== IMAGEARC - END // SYNTAX: // bool imagearc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color) return $return_imagearc; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEARC // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEAVIF // ============================== OFFLINE // ============================== ABOUT // Output image to browser or file. // ============================== SUPPORT // PHP_8 // ============================== USING FUNCTIONS (1) // imageavif() - PHP_8 // ============================== CODE /* function php_image_gd_imageavif($image, $file = null, $quality = -1, $speed = -1) { $return_imageavif = false; // ========== IMAGEAVIF - BEGIN // ===== ABOUT // Output image to browser or file // ===== DESCRIPTION // Outputs or saves a AVIF Raster image from the given image. // ===== SUPPORTED // PHP_8 >= PHP_8_1_0 // ===== SYNTAX // imageavif( // GdImage $image, // resource|string|null $file = null, // int $quality = -1, // int $speed = -1 // ): bool // ===== CODE $return_imageavif = imageavif( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. $quality, // int quality - quality is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, larger file). If -1 is provided, the default value 30 is used. $speed // int speed - speed is optional, and ranges from 0 (slow, smaller file) to 10 (fast, larger file). If -1 is provided, the default value 6 is used. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // ===== LITERATURE_SOURCES // * PHP_NET (2023-08-01) // URL: https://www.php.net/manual/en/function.imageavif.php // ========== IMAGEAVIF - END // SYNTAX: // bool imageavif(GdImage $image, resource|string|null $file = null, int $quality = -1, int $speed = -1) return $return_imageavif; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEAVIF // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEBMP // ============================== OFFLINE // ============================== ABOUT // Output a BMP image to browser or file. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imagebmp() - PHP_7 >= PHP_7_2_0, PHP_8 // ============================== CODE /* function php_image_gd_imagebmp($image, $file = null, $compressed = true) { $return_imagebmp = false; // ========== IMAGEBMP - BEGIN // ===== ABOUT // Output a BMP image to browser or file // ===== DESCRIPTION // Outputs or saves a BMP version of the given image. // ===== SUPPORTED // PHP_7 >= PHP_7_2_0, PHP_8 // ===== SYNTAX // imagebmp(GdImage $image, resource|string|null $file = null, bool $compressed = true): bool // ===== CODE $return_imagebmp = imagebmp( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. // Note: null is invalid if the compressed arguments is not used. $compressed // bool compressed - Whether the BMP should be compressed with run-length encoding (RLE), or not. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - The type of compressed is bool now; formerly it was int. // // [examples] // Examples // [example] // Example #1 Saving a BMP file // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // // imagestring($im, 1, 5, 5, 'BMP with PHP', $text_color); // // // Save the image imagebmp($im, 'php.bmp'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagebmp.php // ========== IMAGEBMP - END // SYNTAX: // bool imagebmp(GdImage $image, resource|string|null $file = null, bool $compressed = true) return $return_imagebmp; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEBMP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECHAR // ============================== PUBLIC // ============================== ABOUT // Draw a character horizontally. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagechar() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagechar($image, $font, $x, $y, $char, $color) { $return_imagechar = false; // ========== IMAGECHAR - BEGIN // ===== ABOUT // Draw a character horizontally // ===== DESCRIPTION // imagechar() draws the first character of char in the image identified by image with its upper-left at x,y (top left is 0, 0) with the color color. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagechar( // GdImage $image, // GdFont|int $font, // int $x, // int $y, // string $char, // int $color // ): bool // ===== CODE $return_imagechar = imagechar( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $font, // GdFont|int font - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont(). $x, // int x - x-coordinate of the start. $y, // int y - y-coordinate of the start. $char, // string char - The character to draw. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The font parameter now accepts both an GdFont instance and an int; previously only int was accepted. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagechar() example // [php] // // $im = imagecreate(100, 100); // // $string = 'PHP'; // // $bg = imagecolorallocate($im, 255, 255, 255); // $black = imagecolorallocate($im, 0, 0, 0); // // // prints a black "P" in the top left corner // imagechar($im, 1, 0, 0, $string, $black); // // header('Content-type: image/png'); // imagepng($im); // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagechar.php // ========== IMAGECHAR - END // SYNTAX: // bool imagechar(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color) return $return_imagechar; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECHAR // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECHARUP // ============================== PUBLIC // ============================== ABOUT // Draw a character vertically. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecharup() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecharup($image, $font, $x, $y, $char, $color) { $return_imagecharup = false; // ========== IMAGECHARUP - BEGIN // ===== ABOUT // Draw a character vertically // ===== DESCRIPTION // Draws the character char vertically at the specified coordinate on the given image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecharup( // GdImage $image, // GdFont|int $font, // int $x, // int $y, // string $char, // int $color // ): bool // ===== CODE $return_imagecharup = imagecharup( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $font, // GdFont|int font - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont(). $x, // int x - x-coordinate of the start. $y, // int y - y-coordinate of the start. $char, // string char - The character to draw. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The font parameter now accepts both an GdFont instance and an int; previously only int was accepted. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagecharup() example // [php] // // $im = imagecreate(100, 100); // // $string = 'Note that the first letter is a N'; // // $bg = imagecolorallocate($im, 255, 255, 255); // $black = imagecolorallocate($im, 0, 0, 0); // // // prints a black "Z" on a white background // imagecharup($im, 3, 10, 10, $string, $black); // // header('Content-type: image/png'); // imagepng($im); // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecharup.php // ========== IMAGECHARUP - END // SYNTAX: // bool imagecharup(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color) return $return_imagecharup; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECHARUP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORALLOCATE // ============================== PUBLIC // ============================== ABOUT // Allocate a color for an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorallocate() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorallocate($image, $red, $green, $blue) { $return_image_color_object = false; // ========== IMAGECOLORALLOCATE - BEGIN // ===== ABOUT // Allocate a color for an image // ===== DESCRIPTION // Returns a color identifier representing the color composed of the given RGB components. // imagecolorallocate() must be called to create each color that is to be used in the image represented by image. // Note: The first call to imagecolorallocate() fills the background color in palette-based images - images created using imagecreate(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorallocate( // GdImage $image, // int $red, // int $green, // int $blue // ): int|false // ===== CODE $return_image_color_object = imagecolorallocate( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue // int blue - Value of blue component. // These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. ); // Return Values // A color identifier or false if the allocation failed. // Warning: This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagecolorallocate() example // [php] // // $im = imagecreate(100, 100); // // // sets background to red // $background = imagecolorallocate($im, 255, 0, 0); // // // sets some colors // $white = imagecolorallocate($im, 255, 255, 255); // $black = imagecolorallocate($im, 0, 0, 0); // // // hexadecimal way // $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); // $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorallocate.php // ========== IMAGECOLORALLOCATE - END // SYNTAX: // int|false imagecolorallocate(GdImage $image, int $red, int $green, int $blue) return $return_image_color_object; // int|false } // ============================== END // PHP_IMAGE_GD_IMAGECOLORALLOCATE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORALLOCATEALPHA // ============================== PUBLIC // ============================== ABOUT // Allocate a color for an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorallocatealpha() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorallocatealpha($image, $red, $green, $blue, $alpha) { $return_image_color_object = false; // ========== IMAGECOLORALLOCATEALPHA - BEGIN // ===== ABOUT // Allocate a color for an image // ===== DESCRIPTION // imagecolorallocatealpha() behaves identically to imagecolorallocate() with the addition of the transparency parameter alpha. // ===== SUPPORTED // PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorallocatealpha( // GdImage $image, // int $red, // int $green, // int $blue, // int $alpha // ): int|false // ===== CODE $return_image_color_object = imagecolorallocatealpha( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue, // int blue - Value of blue component. $alpha // int alpha - A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. // The red, green and blue parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. ); // Return Values // A color identifier or false if the allocation failed. // Warning: This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Example of using imagecolorallocatealpha() // [php] // $size = 300; // $image=imagecreatetruecolor($size, $size); // // // something to get a white background with black border // $back = imagecolorallocate($image, 255, 255, 255); // $border = imagecolorallocate($image, 0, 0, 0); // imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back); // imagerectangle($image, 0, 0, $size - 1, $size - 1, $border); // // $yellow_x = 100; // $yellow_y = 75; // $red_x = 120; // $red_y = 165; // $blue_x = 187; // $blue_y = 125; // $radius = 150; // // // allocate colors with alpha values // $yellow = imagecolorallocatealpha($image, 255, 255, 0, 75); // $red = imagecolorallocatealpha($image, 255, 0, 0, 75); // $blue = imagecolorallocatealpha($image, 0, 0, 255, 75); // // // drawing 3 overlapped circle // imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow); // imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red); // imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue); // // // don't forget to output a correct header! // header('Content-Type: image/png'); // // // and finally, output the result // imagepng($image); // imagedestroy($image); // [/php] // The above example will output something similar to: // [result] // Output of example : Example of using imagecolorallocatealpha() // [/result] // [/example] // [example] // Example #2 Convert typical alpha values for use with imagecolorallocatealpha() // Usually alpha values of 0 designate fully transparent pixels, and the alpha channel has 8 bits. To convert such alpha values to be compatible with imagecolorallocatealpha(), some simple arithmetic is sufficient: // [php] // $alpha8 = 0; // fully transparent // var_dump(127 - ($alpha8 >> 1)); // $alpha8 = 255; // fully opaque // var_dump(127 - ($alpha8 >> 1)); // [/php] // The above example will output: // [result] // int(127) // int(0) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorallocatealpha.php // ========== IMAGECOLORALLOCATEALPHA - END // SYNTAX: // int|false imagecolorallocatealpha(GdImage $image, int $red, int $green, int $blue, int $alpha) return $return_image_color_object; // int|false } // ============================== END // PHP_IMAGE_GD_IMAGECOLORALLOCATEALPHA // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORAT // ============================== PUBLIC // ============================== ABOUT // Get the index of the color of a pixel. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorat() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorat($image, $x, $y) { $return_imagecolorat = false; // ========== IMAGECOLORAT - BEGIN // ===== ABOUT // Get the index of the color of a pixel // ===== DESCRIPTION // Returns the index of the color of the pixel at the specified location in the image specified by image. // If the image is a truecolor image, this function returns the RGB value of that pixel as integer. Use bitshifting and masking to access the distinct red, green and blue component values: // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorat(GdImage $image, int $x, int $y): int|false // ===== CODE $return_imagecolorat = imagecolorat( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x, // int x - x-coordinate of the point. $y // int y - y-coordinate of the point. ); // Return Values // Returns the index of the color or false on failure. // Warning: This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Access distinct RGB values // [php] // $im = imagecreatefrompng("php.png"); // $rgb = imagecolorat($im, 10, 15); // $r = ($rgb >> 16) & 0xFF; // $g = ($rgb >> 8) & 0xFF; // $b = $rgb & 0xFF; // // var_dump($r, $g, $b); // [/php] // The above example will output something similar to: // [result] // int(119) // int(123) // int(180) // [/result] // [/example] // [example] // Example #2 Human-readable RGB values using imagecolorsforindex() // [php] // $im = imagecreatefrompng("php.png"); // $rgb = imagecolorat($im, 10, 15); // // $colors = imagecolorsforindex($im, $rgb); // // var_dump($colors); // [/php] // The above example will output something similar to: // [result] // array(4) { // ["red"]=> // int(119) // ["green"]=> // int(123) // ["blue"]=> // int(180) // ["alpha"]=> // int(127) // } // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorat.php // ========== IMAGECOLORAT - END // SYNTAX: // int|false imagecolorat(GdImage $image, int $x, int $y) return $return_imagecolorat; // int|false } // ============================== END // PHP_IMAGE_GD_IMAGECOLORAT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORCLOSEST // ============================== PUBLIC // ============================== ABOUT // Get the index of the closest color to the specified color. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorclosest() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorclosest($image, $red, $green, $blue) { $return_imagecolorclosest = 0; // ========== IMAGECOLORCLOSEST - BEGIN // ===== ABOUT // Get the index of the closest color to the specified color // ===== DESCRIPTION // Returns the index of the color in the palette of the image which is "closest" to the specified RGB value. // The "distance" between the desired color and each color in the palette is calculated as if the RGB values represented points in three-dimensional space. // If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorclosest( // GdImage $image, // int $red, // int $green, // int $blue // ): int // ===== CODE $return_imagecolorclosest = imagecolorclosest( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue // int blue - Value of blue component. // The colors parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. ); // Return Values // Returns the index of the closest color, in the palette of the image, to the specified one // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Search for a set of colors in an image // [php] // // Start with an image and convert it to a palette-based image // $im = imagecreatefrompng('figures/imagecolorclosest.png'); // imagetruecolortopalette($im, false, 255); // // // Search colors (RGB) // $colors = array( // array(254, 145, 154), // array(153, 145, 188), // array(153, 90, 145), // array(255, 137, 92) // ); // // // Loop through each search and find the closest color in the palette. // // Return the search number, the search RGB and the converted RGB match // foreach($colors as $id => $rgb) // { // $result = imagecolorclosest($im, $rgb[0], $rgb[1], $rgb[2]); // $result = imagecolorsforindex($im, $result); // $result = "({$result['red']}, {$result['green']}, {$result['blue']})"; // // echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2]); Closest match: $result.\n"; // } // // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // #0: Search (254, 145, 154); Closest match: (252, 150, 148). // #1: Search (153, 145, 188); Closest match: (148, 150, 196). // #2: Search (153, 90, 145); Closest match: (148, 90, 156). // #3: Search (255, 137, 92); Closest match: (252, 150, 92). // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorclosest.php // ========== IMAGECOLORCLOSEST - END // SYNTAX: // int imagecolorclosest(GdImage $image, int $red, int $green, int $blue) return $return_imagecolorclosest; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORCLOSEST // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORCLOSESTALPHA // ============================== PUBLIC // ============================== ABOUT // Get the index of the closest color to the specified color + alpha. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorclosestalpha() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorclosestalpha($image, $red, $green, $blue, $alpha) { $return_imagecolorclosestalpha = 0; // ========== IMAGECOLORCLOSESTALPHA - BEGIN // ===== ABOUT // Get the index of the closest color to the specified color + alpha // ===== DESCRIPTION // Returns the index of the color in the palette of the image which is "closest" to the specified RGB value and alpha level. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorclosestalpha( // GdImage $image, // int $red, // int $green, // int $blue, // int $alpha // ): int // ===== CODE $return_imagecolorclosestalpha = imagecolorclosestalpha( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue, // int blue - Value of blue component. $alpha // int alpha - A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. // The colors parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. ); // Return Values // Returns the index of the closest color in the palette. // // [examples] // Examples // [example] // Example #1 Search for a set of colors in an image // [php] // // Start with an image and convert it to a palette-based image // $im = imagecreatefrompng('figures/imagecolorclosest.png'); // imagetruecolortopalette($im, false, 255); // // // Search colors (RGB) // $colors = array( // array(254, 145, 154, 50), // array(153, 145, 188, 127), // array(153, 90, 145, 0), // array(255, 137, 92, 84) // ); // // // Loop through each search and find the closest color in the palette. // // Return the search number, the search RGB and the converted RGB match // foreach($colors as $id => $rgb) // { // $result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]); // $result = imagecolorsforindex($im, $result); // $result = "({$result['red']}, {$result['green']}, {$result['blue']}, {$result['alpha']})"; // // echo "#$id: Search ($rgb[0], $rgb[1], $rgb[2], $rgb[3]); Closest match: $result.\n"; // } // // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // #0: Search (254, 145, 154, 50); Closest match: (252, 150, 148, 0). // #1: Search (153, 145, 188, 127); Closest match: (148, 150, 196, 0). // #2: Search (153, 90, 145, 0); Closest match: (148, 90, 156, 0). // #3: Search (255, 137, 92, 84); Closest match: (252, 150, 92, 0). // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorclosestalpha.php // ========== IMAGECOLORCLOSESTALPHA - END // SYNTAX: // int imagecolorclosestalpha(GdImage $image, int $red, int $green, int $blue, int $alpha) return $return_imagecolorclosestalpha; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORCLOSESTALPHA // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORCLOSESTHWB // ============================== PUBLIC // ============================== ABOUT // Get the index of the color which has the hue, white and blackness. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorclosesthwb() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorclosesthwb($image, $red, $green, $blue) { $return_imagecolorclosesthwb = 0; // ========== IMAGECOLORCLOSESTHWB - BEGIN // ===== ABOUT // Get the index of the color which has the hue, white and blackness // ===== DESCRIPTION // Get the index of the color which has the hue, white and blackness nearest the given color. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorclosesthwb( // GdImage $image, // int $red, // int $green, // int $blue // ): int // ===== CODE $return_imagecolorclosesthwb = imagecolorclosesthwb( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue // int blue - Value of blue component. ); // Return Values // Returns an integer with the index of the color which has the hue, white and blackness nearest the given color. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Example of using imagecolorclosesthwb() // [php] // $im = imagecreatefromgif('php.gif'); // // echo 'HWB: ' . imagecolorclosesthwb($im, 116, 115, 152); // // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // HWB: 33 // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorclosesthwb.php // ========== IMAGECOLORCLOSESTHWB - END // SYNTAX: // int imagecolorclosesthwb(GdImage $image, int $red, int $green, int $blue) return $return_imagecolorclosesthwb; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORCLOSESTHWB // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORDEALLOCATE // ============================== PUBLIC // ============================== ABOUT // De-allocate a color for an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolordeallocate() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolordeallocate($image, $color) { $return_imagecolordeallocate = false; // ========== IMAGECOLORDEALLOCATE - BEGIN // ===== ABOUT // De-allocate a color for an image // ===== DESCRIPTION // De-allocates a color previously allocated with imagecolorallocate() or imagecolorallocatealpha(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolordeallocate(GdImage $image, int $color): bool // ===== CODE $return_imagecolordeallocate = imagecolordeallocate( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $color // int color - The color identifier. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Using imagecolordeallocate() // [php] // $white = imagecolorallocate($im, 255, 255, 255); // imagecolordeallocate($im, $white); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolordeallocate.php // ========== IMAGECOLORDEALLOCATE - END // SYNTAX: // bool imagecolordeallocate(GdImage $image, int $color) return $return_imagecolordeallocate; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOLORDEALLOCATE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLOREXACT // ============================== PUBLIC // ============================== ABOUT // Get the index of the specified color. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorexact() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorexact($image, $red, $green, $blue) { $return_imagecolorexact = 0; // ========== IMAGECOLOREXACT - BEGIN // ===== ABOUT // Get the index of the specified color // ===== DESCRIPTION // Returns the index of the specified color in the palette of the image. // If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorexact( // GdImage $image, // int $red, // int $green, // int $blue // ): int // ===== CODE $return_imagecolorexact = imagecolorexact( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue // int blue - Value of blue component. ); // Return Values // Returns the index of the specified color in the palette, or -1 if the color does not exist. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Get colors from the GD logo // [php] // // Setup an image // $im = imagecreatefrompng('./gdlogo.png'); // // $colors = Array(); // $colors[] = imagecolorexact($im, 255, 0, 0); // $colors[] = imagecolorexact($im, 0, 0, 0); // $colors[] = imagecolorexact($im, 255, 255, 255); // $colors[] = imagecolorexact($im, 100, 255, 52); // // print_r($colors); // // // Free from memory // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // Array // ( // [0] => 16711680 // [1] => 0 // [2] => 16777215 // [3] => 6618932 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorexact.php // ========== IMAGECOLOREXACT - END // SYNTAX: // int imagecolorexact(GdImage $image, int $red, int $green, int $blue) return $return_imagecolorexact; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLOREXACT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLOREXACTALPHA // ============================== PUBLIC // ============================== ABOUT // Get the index of the specified color + alpha. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorexactalpha() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorexactalpha($image, $red, $green, $blue, $alpha) { $return_imagecolorexactalpha = 0; // ========== IMAGECOLOREXACTALPHA - BEGIN // ===== ABOUT // Get the index of the specified color + alpha // ===== DESCRIPTION // Returns the index of the specified color+alpha in the palette of the image. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorexactalpha( // GdImage $image, // int $red, // int $green, // int $blue, // int $alpha // ): int // ===== CODE $return_imagecolorexactalpha = imagecolorexactalpha( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue, // int blue - Value of blue component. $alpha // int alpha - A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. // The colors parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. ); // Return Values // Returns the index of the specified color+alpha in the palette of the image, or -1 if the color does not exist in the image's palette. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Get colors from the GD logo // [php] // // // Setup an image // $im = imagecreatefrompng('./gdlogo.png'); // // $colors = Array(); // $colors[] = imagecolorexactalpha($im, 255, 0, 0, 0); // $colors[] = imagecolorexactalpha($im, 0, 0, 0, 127); // $colors[] = imagecolorexactalpha($im, 255, 255, 255, 55); // $colors[] = imagecolorexactalpha($im, 100, 255, 52, 20); // // print_r($colors); // // // Free from memory // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // Array // ( // [0] => 16711680 // [1] => 2130706432 // [2] => 939524095 // [3] => 342163252 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorexactalpha.php // ========== IMAGECOLOREXACTALPHA - END // SYNTAX: // int imagecolorexactalpha(GdImage $image, int $red, int $green, int $blue, int $alpha) return $return_imagecolorexactalpha; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLOREXACTALPHA // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORMATCH // ============================== PUBLIC // ============================== ABOUT // Makes the colors of the palette version of an image more closely match the true color version. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolormatch() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolormatch($image1, $image2) { $return_imagecolormatch = false; // ========== IMAGECOLORMATCH - BEGIN // ===== ABOUT // Makes the colors of the palette version of an image more closely match the true color version // ===== DESCRIPTION // Makes the colors of the palette version of an image more closely match the true color version. // ===== SUPPORTED // PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolormatch(GdImage $image1, GdImage $image2): bool // ===== CODE $return_imagecolormatch = imagecolormatch( $image1, // GdImage image1 - A truecolor image object. $image2 // GdImage image2 - A palette image object pointing to an image that has the same size as image1. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image1 and image2 expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 imagecolormatch() example // [php] // // Setup the true color and palette images // $im1 = imagecreatefrompng('./gdlogo.png'); // $im2 = imagecreate(imagesx($im1), imagesy($im1)); // // // Add some colors to $im2 // $colors = Array(); // $colors[] = imagecolorallocate($im2, 255, 36, 74); // $colors[] = imagecolorallocate($im2, 40, 0, 240); // $colors[] = imagecolorallocate($im2, 82, 100, 255); // $colors[] = imagecolorallocate($im2, 84, 63, 44); // // // Match these colors with the true color image // imagecolormatch($im1, $im2); // // // Free from memory // imagedestroy($im1); // imagedestroy($im2); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolormatch.php // ========== IMAGECOLORMATCH - END // SYNTAX: // bool imagecolormatch(GdImage $image1, GdImage $image2) return $return_imagecolormatch; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOLORMATCH // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORRESOLVE // ============================== PUBLIC // ============================== ABOUT // Get the index of the specified color or its closest possible alternative. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorresolve() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorresolve($image, $red, $green, $blue) { $return_imagecolorresolve = 0; // ========== IMAGECOLORRESOLVE - BEGIN // ===== ABOUT // Get the index of the specified color or its closest possible alternative // ===== DESCRIPTION // This function is guaranteed to return a color index for a requested color, either the exact color or the closest possible alternative. // If you created the image from a file, only colors used in the image are resolved. Colors present only in the palette are not resolved. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorresolve( // GdImage $image, // int $red, // int $green, // int $blue // ): int // ===== CODE $return_imagecolorresolve = imagecolorresolve( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue // int blue - Value of green component. ); // Return Values // Returns a color index. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Using imagecoloresolve() to get colors from an image // [php] // // Load an image // $im = imagecreatefromgif('phplogo.gif'); // // // Get closest colors from the image // $colors = array(); // $colors[] = imagecolorresolve($im, 255, 255, 255); // $colors[] = imagecolorresolve($im, 0, 0, 200); // // // Output // print_r($colors); // // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // Array // ( // [0] => 89 // [1] => 85 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorresolve.php // ========== IMAGECOLORRESOLVE - END // SYNTAX: // int imagecolorresolve(GdImage $image, int $red, int $green, int $blue) return $return_imagecolorresolve; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORRESOLVE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORRESOLVEALPHA // ============================== PUBLIC // ============================== ABOUT // Get the index of the specified color + alpha or its closest possible alternative. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorresolvealpha() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorresolvealpha($image, $red, $green, $blue, $alpha) { $return_imagecolorresolvealpha = 0; // ========== IMAGECOLORRESOLVEALPHA - BEGIN // ===== ABOUT // Get the index of the specified color + alpha or its closest possible alternative // ===== DESCRIPTION // This function is guaranteed to return a color index for a requested color, either the exact color or the closest possible alternative. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorresolvealpha( // GdImage $image, // int $red, // int $green, // int $blue, // int $alpha // ): int // ===== CODE $return_imagecolorresolvealpha = imagecolorresolvealpha( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $red, // int red - Value of red component. $green, // int green - Value of green component. $blue, // int blue - Value of blue component. $alpha // int alpha - A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. // The colors parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. ); // Return Values // Returns a color index. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Using imagecoloresolvealpha() to get colors from an image // [php] // // Load an image // $im = imagecreatefromgif('phplogo.gif'); // // // Get closest colors from the image // $colors = array(); // $colors[] = imagecolorresolvealpha($im, 255, 255, 255, 0); // $colors[] = imagecolorresolvealpha($im, 0, 0, 200, 127); // // // Output // print_r($colors); // // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // Array // ( // [0] => 89 // [1] => 85 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorresolvealpha.php // ========== IMAGECOLORRESOLVEALPHA - END // SYNTAX: // int imagecolorresolvealpha(GdImage $image, int $red, int $green, int $blue, int $alpha) return $return_imagecolorresolvealpha; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORRESOLVEALPHA // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORSET // ============================== PUBLIC // ============================== ABOUT // Set the color for the specified palette index. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorset() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorset($image, $color, $red, $green, $blue, $alpha = 0) { $return_imagecolorset = false; // ========== IMAGECOLORSET - BEGIN // ===== ABOUT // Set the color for the specified palette index // ===== DESCRIPTION // This sets the specified index in the palette to the specified color. This is useful for creating flood-fill-like effects in palleted images without the overhead of performing the actual flood-fill. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorset( // GdImage $image, // int $color, // int $red, // int $green, // int $blue, // int $alpha = 0 // ): ?false // ===== CODE $return_imagecolorset = imagecolorset( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $color, // int color - An index in the palette. $red, // int red - Value of red component. $green, // int green - Value of green component. $blue, // int blue - Value of blue component. $alpha // int alpha - Value of alpha component. ); // Return Values // The function returns null on success, or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagecolorset() example // [php] // // Create a 300x100 image // $im = imagecreate(300, 100); // // // Set the background to be red // imagecolorallocate($im, 255, 0, 0); // // // Get the color index for the background // $bg = imagecolorat($im, 0, 0); // // // Set the backgrund to be blue // imagecolorset($im, $bg, 0, 0, 255); // // // Output the image to the browser // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorset.php // ========== IMAGECOLORSET - END // SYNTAX: // bool imagecolorset(GdImage $image, int $color, int $red, int $green, int $blue, int $alpha = 0) return $return_imagecolorset; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOLORSET // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORSFORINDEX // ============================== PUBLIC // ============================== ABOUT // Get the colors for an index. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorsforindex() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorsforindex($image, $color) { $return_imagecolorsforindex = null; // ========== IMAGECOLORSFORINDEX - BEGIN // ===== ABOUT // Get the colors for an index // ===== DESCRIPTION // Gets the color for a specified index. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorsforindex(GdImage $image, int $color): array // ===== CODE $return_imagecolorsforindex = imagecolorsforindex( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $color // int color - The color index. ); // Return Values // Returns an associative array with red, green, blue and alpha keys that contain the appropriate values for the specified color index. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - imagecolorsforindex() now throws a ValueError exception if color is out of range; previously, false was returned instead. // // [examples] // Examples // [example] // Example #1 imagecolorsforindex() example // [php] // // // open an image // $im = imagecreatefrompng('nexen.png'); // // // get a color // $start_x = 40; // $start_y = 50; // $color_index = imagecolorat($im, $start_x, $start_y); // // // make it human readable // $color_tran = imagecolorsforindex($im, $color_index); // // // what is it ? // print_r($color_tran); // // [/php] // The above example will output something similar to: // [result] // Array // ( // [red] => 226 // [green] => 222 // [blue] => 252 // [alpha] => 0 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorsforindex.php // ========== IMAGECOLORSFORINDEX - END // SYNTAX: // array imagecolorsforindex(GdImage $image, int $color) return $return_imagecolorsforindex; // array } // ============================== END // PHP_IMAGE_GD_IMAGECOLORSFORINDEX // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORSTOTAL // ============================== PUBLIC // ============================== ABOUT // Find out the number of colors in an image's palette. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolorstotal() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolorstotal($image) { $return_imagecolorstotal = 0; // ========== IMAGECOLORSTOTAL - BEGIN // ===== ABOUT // Find out the number of colors in an image's palette // ===== DESCRIPTION // Returns the number of colors in an image palette. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolorstotal(GdImage $image): int // ===== CODE $return_imagecolorstotal = imagecolorstotal( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Returns the number of colors in the specified image's palette or 0 for truecolor images. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Getting total number of colors in an image using imagecolorstotal() // [php] // // Create image instance // $im = imagecreatefromgif('php.gif'); // // echo 'Total colors in image: ' . imagecolorstotal($im); // // // Free image // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // Total colors in image: 128 // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolorstotal.php // ========== IMAGECOLORSTOTAL - END // SYNTAX: // int imagecolorstotal(GdImage $image) return $return_imagecolorstotal; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORSTOTAL // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOLORTRANSPARENT // ============================== PUBLIC // ============================== ABOUT // Define a color as transparent. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecolortransparent() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecolortransparent($image, $color = null) { $return_imagecolortransparent = 0; // ========== IMAGECOLORTRANSPARENT - BEGIN // ===== ABOUT // Define a color as transparent // ===== DESCRIPTION // Gets or sets the transparent color in the given image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecolortransparent(GdImage $image, ?int $color = null): int // ===== CODE $return_imagecolortransparent = imagecolortransparent( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // The identifier of the new (or current, if none is specified) transparent color is returned. If color is null, and the image has no transparent color, the returned identifier will be -1. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - color is now nullable. // // [examples] // Examples // [example] // Example #1 imagecolortransparent() example // [php] // // Create a 55x30 image // $im = imagecreatetruecolor(55, 30); // $red = imagecolorallocate($im, 255, 0, 0); // $black = imagecolorallocate($im, 0, 0, 0); // // // Make the background transparent // imagecolortransparent($im, $black); // // // Draw a red rectangle // imagefilledrectangle($im, 4, 4, 50, 25, $red); // // // Save the image // imagepng($im, './imagecolortransparent.png'); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: Transparency is copied only with imagecopymerge() and true color images, not with imagecopy() or pallete images. // Note: The transparent color is a property of the image, transparency is not a property of the color. Once you have set a color to be the transparent color, any regions of the image in that color that were drawn previously will be transparent. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecolortransparent.php // ========== IMAGECOLORTRANSPARENT - END // SYNTAX: // int imagecolortransparent(GdImage $image, int $color = null) return $return_imagecolortransparent; // int } // ============================== END // PHP_IMAGE_GD_IMAGECOLORTRANSPARENT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECONVOLUTION // ============================== OFFLINE // ============================== ABOUT // Apply a 3x3 convolution matrix, using coefficient and offset. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imageconvolution() - PHP_5 >= PHP_5_1_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imageconvolution($image, $matrix, $divisor, $offset) { $return_imageconvolution = false; // ========== IMAGECONVOLUTION - BEGIN // ===== ABOUT // Apply a 3x3 convolution matrix, using coefficient and offset // ===== DESCRIPTION // Applies a convolution matrix on the image, using the given coefficient and offset. // ===== SUPPORTED // PHP_5 >= PHP_5_1_0, PHP_7, PHP_8 // ===== SYNTAX // imageconvolution( // GdImage $image, // array $matrix, // float $divisor, // float $offset // ): bool // ===== CODE $return_imageconvolution = imageconvolution( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $matrix, // array matrix - A 3x3 matrix: an array of three arrays of three floats. $divisor, // float divisor - The divisor of the result of the convolution, used for normalization. $offset // float offset - Color offset. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Embossing the PHP.net logo // [php] // $image = imagecreatefromgif('http://www.php.net/images/php.gif'); // // $emboss = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1)); // imageconvolution($image, $emboss, 1, 127); // // header('Content-Type: image/png'); // imagepng($image, null, 9); // [/php] // [/example] // [example] // Example #2 Gaussian blur // [php] // $image = imagecreatetruecolor(180,40); // // // Writes the text and apply a gaussian blur on the image // imagestring($image, 5, 10, 8, 'Gaussian Blur Text', 0x00ff00); // $gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0)); // imageconvolution($image, $gaussian, 16, 0); // // // Rewrites the text for comparison // imagestring($image, 5, 10, 18, 'Gaussian Blur Text', 0x00ff00); // // header('Content-Type: image/png'); // imagepng($image, null, 9); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imageconvolution.php // ========== IMAGECONVOLUTION - END // SYNTAX: // bool imageconvolution(GdImage $image, array $matrix, float $divisor, float $offset) return $return_imageconvolution; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGECONVOLUTION // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOPY // ============================== PUBLIC // ============================== ABOUT // Copy part of an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecopy() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecopy($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_width, $src_height) { $return_imagecopy = false; // ========== IMAGECOPY - BEGIN // ===== ABOUT // Copy part of an image // ===== DESCRIPTION // Copy a part of src_image onto dst_image starting at the x,y coordinates src_x, src_y with a width of src_width and a height of src_height. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecopy( // GdImage $dst_image, // GdImage $src_image, // int $dst_x, // int $dst_y, // int $src_x, // int $src_y, // int $src_width, // int $src_height // ): bool // ===== CODE $return_imagecopy = imagecopy( $dst_image, // GdImage dst_image - Destination image resource. $src_image, // GdImage src_image - Source image resource. $dst_x, // int dst_x - x-coordinate of destination point. $dst_y, // int dst_y - y-coordinate of destination point. $src_x, // int src_x - x-coordinate of source point. $src_y, // int src_y - y-coordinate of source point. $src_width, // int src_width - Source width. $src_height // int src_height - Source height. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - dst_image and src_image expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 Cropping the PHP.net logo // [php] // // Create image instances // $src = imagecreatefromgif('php.gif'); // $dest = imagecreatetruecolor(80, 40); // // // Copy // imagecopy($dest, $src, 0, 0, 20, 13, 80, 40); // // // Output and free from memory // header('Content-Type: image/gif'); // imagegif($dest); // // imagedestroy($dest); // imagedestroy($src); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecopy.php // ========== IMAGECOPY - END // SYNTAX: // bool imagecopy(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height) return $return_imagecopy; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOPY // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOPYMERGE // ============================== PUBLIC // ============================== ABOUT // Copy and merge part of an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecopymerge() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecopymerge($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_width, $src_height, $pct) { $return_imagecopymerge = false; // ========== IMAGECOPYMERGE - BEGIN // ===== ABOUT // Copy and merge part of an image // ===== DESCRIPTION // Copy a part of src_image onto dst_image starting at the x,y coordinates src_x, src_y with a width of src_width and a height of src_height. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecopymerge( // GdImage $dst_image, // GdImage $src_image, // int $dst_x, // int $dst_y, // int $src_x, // int $src_y, // int $src_width, // int $src_height, // int $pct // ): bool // ===== CODE $return_imagecopymerge = imagecopymerge( $dst_image, // GdImage dst_image - Destination image resource. $src_image, // GdImage src_image - Source image resource. $dst_x, // int dst_x - x-coordinate of destination point. $dst_y, // int dst_y - y-coordinate of destination point. $src_x, // int src_x - x-coordinate of source point. $src_y, // int src_y - y-coordinate of source point. $src_width, // int src_width - Source width. $src_height, // int src_height - Source height. $pct // int pct - The two images will be merged according to pct which can range from 0 to 100. When pct = 0, no action is taken, when 100 this function behaves identically to imagecopy() for pallete images, except for ignoring alpha components, while it implements alpha transparency for true colour images. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - dst_image and src_image expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 Merging two copies of the PHP.net logo with 75% transparency // [php] // // Create image instances // $dest = imagecreatefromgif('php.gif'); // $src = imagecreatefromgif('php.gif'); // // // Copy and merge // imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75); // // // Output and free from memory // header('Content-Type: image/gif'); // imagegif($dest); // // imagedestroy($dest); // imagedestroy($src); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecopymerge.php // ========== IMAGECOPYMERGE - END // SYNTAX: // bool imagecopymerge(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct) return $return_imagecopymerge; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOPYMERGE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOPYMERGEGRAY // ============================== PUBLIC // ============================== ABOUT // Copy and merge part of an image with gray scale. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecopymergegray() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecopymergegray($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_width, $src_height, $pct) { $return_imagecopymergegray = false; // ========== IMAGECOPYMERGEGRAY - BEGIN // ===== ABOUT // Copy and merge part of an image with gray scale // ===== DESCRIPTION // imagecopymergegray() copy a part of src_image onto dst_image starting at the x,y coordinates src_x, src_y with a width of src_width and a height of src_height. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y. // This function is identical to imagecopymerge() except that when merging it preserves the hue of the source by converting the destination pixels to gray scale before the copy operation. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecopymergegray( // GdImage $dst_image, // GdImage $src_image, // int $dst_x, // int $dst_y, // int $src_x, // int $src_y, // int $src_width, // int $src_height, // int $pct // ): bool // ===== CODE $return_imagecopymergegray = imagecopymergegray( $dst_image, // GdImage dst_image - Destination image resource. $src_image, // GdImage src_image - Source image resource. $dst_x, // int dst_x - x-coordinate of destination point. $dst_y, // int dst_y - y-coordinate of destination point. $src_x, // int src_x - x-coordinate of source point. $src_y, // int src_y - y-coordinate of source point. $src_width, // int src_width - Source width. $src_height, // int src_height - Source height. $pct // int pct - The src_image will be changed to grayscale according to pct where 0 is fully grayscale and 100 is unchanged. When pct = 100 this function behaves identically to imagecopy() for pallete images, except for ignoring alpha components, while it implements alpha transparency for true colour images. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - dst_image and src_image expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 imagecopymergegray() usage // [php] // // Create image instances // $dest = imagecreatefromgif('php.gif'); // $src = imagecreatefromgif('php.gif'); // // // Copy and merge - Gray = 20% // imagecopymergegray($dest, $src, 10, 10, 0, 0, 100, 47, 20); // // // Output and free from memory // header('Content-Type: image/gif'); // imagegif($dest); // // imagedestroy($dest); // imagedestroy($src); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecopymergegray.php // ========== IMAGECOPYMERGEGRAY - END // SYNTAX: // bool imagecopymergegray(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct) return $return_imagecopymergegray; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOPYMERGEGRAY // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOPYRESAMPLED // ============================== PUBLIC // ============================== ABOUT // Copy and resize part of an image with resampling. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecopyresampled() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_width, $dst_height, $src_width, $src_height) { $return_imagecopyresampled = false; // ========== IMAGECOPYRESAMPLED - BEGIN // ===== ABOUT // Copy and resize part of an image with resampling // ===== DESCRIPTION // imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. // In other words, imagecopyresampled() will take a rectangular area from src_image of width src_width and height src_height at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_width and height dst_height at position (dst_x,dst_y). // If the source and destination coordinates and width and heights differ, appropriate stretching or shrinking of the image fragment will be performed. The coordinates refer to the upper left corner. This function can be used to copy regions within the same image (if dst_image is the same as src_image) but if the regions overlap the results will be unpredictable. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecopyresampled( // GdImage $dst_image, // GdImage $src_image, // int $dst_x, // int $dst_y, // int $src_x, // int $src_y, // int $dst_width, // int $dst_height, // int $src_width, // int $src_height // ): bool // ===== CODE $return_imagecopyresampled = imagecopyresampled( $dst_image, // GdImage dst_image - Destination image resource. $src_image, // GdImage src_image - Source image resource. $dst_x, // int dst_x - x-coordinate of destination point. $dst_y, // int dst_y - y-coordinate of destination point. $src_x, // int src_x - x-coordinate of source point. $src_y, // int src_y - y-coordinate of source point. $dst_width, // int dst_width - Destination width. $dst_height, // int dst_height - Destination height. $src_width, // int src_width - Source width. $src_height // int src_height - Source height. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - dst_image and src_image expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 Simple example // This example will resample an image to half its original size. // [php] // // The file // $filename = 'test.jpg'; // $percent = 0.5; // // // Content type // header('Content-Type: image/jpeg'); // // // Get new dimensions // list($width, $height) = getimagesize($filename); // $new_width = $width * $percent; // $new_height = $height * $percent; // // // Resample // $image_p = imagecreatetruecolor($new_width, $new_height); // $image = imagecreatefromjpeg($filename); // imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // // // Output // imagejpeg($image_p, null, 100); // [/php] // [/example] // [example] // Example #2 Resampling an image proportionally // This example will display an image with the maximum width, or height, of 200 pixels. // [php] // // The file // $filename = 'test.jpg'; // // // Set a maximum height and width // $width = 200; // $height = 200; // // // Content type // header('Content-Type: image/jpeg'); // // // Get new dimensions // list($width_orig, $height_orig) = getimagesize($filename); // // $ratio_orig = $width_orig/$height_orig; // // if ($width/$height > $ratio_orig) { // $width = $height*$ratio_orig; // } else { // $height = $width/$ratio_orig; // } // // // Resample // $image_p = imagecreatetruecolor($width, $height); // $image = imagecreatefromjpeg($filename); // imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // // // Output // imagejpeg($image_p, null, 100); // [/php] // [/example] // [/examples] // // Notes // Note: There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor(). // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecopyresampled.php // ========== IMAGECOPYRESAMPLED - END // SYNTAX: // bool imagecopyresampled(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height) return $return_imagecopyresampled; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOPYRESAMPLED // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECOPYRESIZED // ============================== PUBLIC // ============================== ABOUT // Copy and resize part of an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecopyresized() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_width, $dst_height, $src_width, $src_height) { $return_imagecopyresized = false; // ========== IMAGECOPYRESIZED - BEGIN // ===== ABOUT // Copy and resize part of an image // ===== DESCRIPTION // imagecopyresized() copies a rectangular portion of one image to another image. dst_image is the destination image, src_image is the source image identifier. // In other words, imagecopyresized() will take a rectangular area from src_image of width src_width and height src_height at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_width and height dst_height at position (dst_x,dst_y). // If the source and destination coordinates and width and heights differ, appropriate stretching or shrinking of the image fragment will be performed. The coordinates refer to the upper left corner. This function can be used to copy regions within the same image (if dst_image is the same as src_image) but if the regions overlap the results will be unpredictable. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecopyresized( // GdImage $dst_image, // GdImage $src_image, // int $dst_x, // int $dst_y, // int $src_x, // int $src_y, // int $dst_width, // int $dst_height, // int $src_width, // int $src_height // ): bool // ===== CODE $return_imagecopyresized = imagecopyresized( $dst_image, // GdImage dst_image - Destination image resource. $src_image, // GdImage src_image - Source image resource. $dst_x, // int dst_x - x-coordinate of destination point. $dst_y, // int dst_y - y-coordinate of destination point. $src_x, // int src_x - x-coordinate of source point. $src_y, // int src_y - y-coordinate of source point. $dst_width, // int dst_width - Destination width. $dst_height, // int dst_height - Destination height. $src_width, // int src_width - Source width. $src_height // int src_height - Source height. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - dst_image and src_image expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 Resizing an image // This example will display the image at half size. // [php] // // File and new size // $filename = 'test.jpg'; // $percent = 0.5; // // // Content type // header('Content-Type: image/jpeg'); // // // Get new sizes // list($width, $height) = getimagesize($filename); // $newwidth = $width * $percent; // $newheight = $height * $percent; // // // Load // $thumb = imagecreatetruecolor($newwidth, $newheight); // $source = imagecreatefromjpeg($filename); // // // Resize // imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // // // Output // imagejpeg($thumb); // [/php] // The image will be output at half size, though better quality could be obtained using imagecopyresampled(). // [/example] // [/examples] // // Notes // Note: There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor(). // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecopyresized.php // ========== IMAGECOPYRESIZED - END // SYNTAX: // bool imagecopyresized(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height) return $return_imagecopyresized; // bool } // ============================== END // PHP_IMAGE_GD_IMAGECOPYRESIZED // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATE // ============================== PUBLIC // ============================== ABOUT // Create a new palette based image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreate() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreate($width, $height) { $return_imagecreate = false; // ========== IMAGECREATE - BEGIN // ===== ABOUT // Create a new palette based image // ===== DESCRIPTION // imagecreate() returns an image identifier representing a blank image of specified size. // In general, we recommend the use of imagecreatetruecolor() instead of imagecreate() so that image processing occurs on the highest quality image possible. If you want to output a palette image, then imagetruecolortopalette() should be called immediately before saving the image with imagepng() or imagegif(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreate(int $width, int $height): GdImage|false // ===== CODE $return_imagecreate = imagecreate( $width, // int width - The image width. $height // int height - The image height. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Creating a new GD image stream and outputting an image. // [php] // header("Content-Type: image/png"); // $im = @imagecreate(110, 20) // or die("Cannot Initialize new GD image stream"); // $background_color = imagecolorallocate($im, 0, 0, 0); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreate.php // ========== IMAGECREATE - END // SYNTAX: // GdImage|false imagecreate(int $width, int $height) return $return_imagecreate; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMAVIF // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromavif() - PHP_8 >= PHP_8_1_0 // ============================== CODE /* function php_image_gd_imagecreatefromavif($filename) { $return_imagecreatefromavif = false; // ========== IMAGECREATEFROMAVIF - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromavif() returns an image object representing the image obtained from the given filename. // ===== SUPPORTED // PHP_8 >= PHP_8_1_0 // ===== SYNTAX // imagecreatefromavif(string $filename): GdImage|false // ===== CODE $return_imagecreatefromavif = imagecreatefromavif( $filename // string filename - Path to the AVIF raster image. ); // Return Values // Returns an image object on success, false on errors. // ===== LITERATURE_SOURCES // * PHP_NET (2023-07-31) // URL: https://www.php.net/manual/en/function.imagecreatefromavif.php // ========== IMAGECREATEFROMAVIF - END // SYNTAX: // GdImage|false imagecreatefromavif(string $filename) return $return_imagecreatefromavif; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMAVIF // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMBMP // ============================== OFFLINE // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefrombmp() - PHP_7 >= PHP_7_2_0, PHP_8 // ============================== CODE /* function php_image_gd_imagecreatefrombmp($filename) { $return_imagecreatefrombmp = false; // ========== IMAGECREATEFROMBMP - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefrombmp() returns an image identifier representing the image obtained from the given filename. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_7 >= PHP_7_2_0, PHP_8 // ===== SYNTAX // imagecreatefrombmp(string $filename): GdImage|false // ===== CODE $return_imagecreatefrombmp = imagecreatefrombmp( $filename // string filename - Path to the BMP image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Convert an BMP image to a PNG image using imagecreatefrombmp() // [php] // // Load the BMP file // $im = imagecreatefrombmp('./example.bmp'); // // // Convert it to a PNG file with default settings // imagepng($im, './example.png'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefrombmp.php // ========== IMAGECREATEFROMBMP - END // ========== IMAGECREATEFROMBMP - BEGIN // ===== ABOUT // NOT_TRUSTED_CODE - For old PHP_4 versions ImageCreateFromBMP(). // ===== DESCRIPTION // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // // fopen() - PHP_4, PHP_5, PHP_7, PHP_8 // unpack() - PHP_4, PHP_5, PHP_7, PHP_8 // fread() - PHP_4, PHP_5, PHP_7, PHP_8 // pow() - PHP_4, PHP_5, PHP_7, PHP_8 // ceil() - PHP_4, PHP_5, PHP_7, PHP_8 // floor() - PHP_4, PHP_5, PHP_7, PHP_8 // array() - PHP_4, PHP_5, PHP_7, PHP_8 // chr() - PHP_4, PHP_5, PHP_7, PHP_8 // imagecreatetruecolor() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // substr() - PHP_4, PHP_5, PHP_7, PHP_8 // imagesetpixel() - PHP_4, PHP_5, PHP_7, PHP_8 // fclose() - PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // ===== CODE // Fonction: ImageCreateFromBMP // Author: DHKold // Contact: admin@dhkold.com // Date: The 15th of June 2005 // Version: 2.0B // // if (!$file_object = fopen($directory, "rb")){return false;} // // $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($file_object, 14)); // if ($FILE['file_type'] != 19778){return false;} // // $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'. // '/Vcompression/Vsize_bitmap/Vhoriz_resolution'. // '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($file_object, 40)); // $BMP['colors'] = pow(2, $BMP['bits_per_pixel']); // if ($BMP['size_bitmap'] == 0){$BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];} // $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8; // $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); // $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4); // $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4); // $BMP['decal'] = 4 - (4 * $BMP['decal']); // if ($BMP['decal'] == 4){$BMP['decal'] = 0;} // // $PALETTE = array(); // if ($BMP['colors'] < 16777216) // { // $PALETTE = unpack('V' . $BMP['colors'], fread($file_object, $BMP['colors'] * 4)); // } // // $IMG = fread($file_object, $BMP['size_bitmap']); // $VIDE = chr(0); // // $res = imagecreatetruecolor($BMP['width'], $BMP['height']); // $P = 0; // $Y = $BMP['height'] - 1; // // while ($Y >= 0) // { // $X = 0; // // while ($X < $BMP['width']) // { // if ($BMP['bits_per_pixel'] == 24) // { // $COLOR = unpack("V", substr($IMG, $P, 3) . $VIDE); // } // elseif ($BMP['bits_per_pixel'] == 16) // { // $COLOR = unpack("n", substr($IMG, $P, 2)); // $COLOR[1] = $PALETTE[$COLOR[1] + 1]; // } // elseif ($BMP['bits_per_pixel'] == 8) // { // $COLOR = unpack("n", $VIDE . substr($IMG, $P, 1)); // $COLOR[1] = $PALETTE[$COLOR[1] + 1]; // } // elseif ($BMP['bits_per_pixel'] == 4) // { // $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1)); // // if ((($P * 2) % 2) == 0){$COLOR[1] = ($COLOR[1] >> 4);} // else{$COLOR[1] = ($COLOR[1] & 0x0F);} // // $COLOR[1] = $PALETTE[$COLOR[1] + 1]; // } // elseif ($BMP['bits_per_pixel'] == 1) // { // $COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1)); // // if ((($P * 8) % 8) == 0){$COLOR[1] = $COLOR[1] >> 7;} // elseif ((($P * 8) % 8) == 1){$COLOR[1] = ($COLOR[1] & 0x40) >> 6;} // elseif ((($P * 8) % 8) == 2){$COLOR[1] = ($COLOR[1] & 0x20) >> 5;} // elseif ((($P * 8) % 8) == 3){$COLOR[1] = ($COLOR[1] & 0x10) >> 4;} // elseif ((($P * 8) % 8) == 4){$COLOR[1] = ($COLOR[1] & 0x8) >> 3;} // elseif ((($P * 8) % 8) == 5){$COLOR[1] = ($COLOR[1] & 0x4) >> 2;} // elseif ((($P * 8) % 8) == 6){$COLOR[1] = ($COLOR[1] & 0x2) >> 1;} // elseif ((($P * 8) % 8) == 7){$COLOR[1] = ($COLOR[1] & 0x1);} // // $COLOR[1] = $PALETTE[$COLOR[1] + 1]; // } // else // { // return false; // } // // imagesetpixel($res, $X, $Y, $COLOR[1]); // $X++; // $P += $BMP['bytes_per_pixel']; // } // // $Y--; // $P += $BMP['decal']; // } // // fclose($file_object); // // $return_imagecreatefrombmp = $res; // ===== LITERATURE_SOURCES // * NOT_TRUSTED_CODE (2005-06-15) // Author: DHKold // Contact: admin@dhkold.com // Version: 2.0B // ========== IMAGECREATEFROMBMP - END // SYNTAX: // GdImage|false imagecreatefrombmp(string $filename) return $return_imagecreatefrombmp; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMBMP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMGD2 // ============================== PUBLIC // ============================== ABOUT // Create a new image from GD2 file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromgd2() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromgd2($filename) { $return_imagecreatefromgd2 = false; // ========== IMAGECREATEFROMGD2 - BEGIN // ===== ABOUT // Create a new image from GD2 file or URL // ===== DESCRIPTION // Create a new image from GD2 file or URL. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromgd2(string $filename): GdImage|false // ===== CODE $return_imagecreatefromgd2 = imagecreatefromgd2( $filename // string filename - Path to the GD2 image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 imagecreatefromgd2() example // [php] // // Load the gd2 image // $im = imagecreatefromgd2('./test.gd2'); // // // Apply an effect on the image, in this // // case negate the image // if(function_exists('imagefilter')) // { // imagefilter($im, IMG_FILTER_NEGATE); // } // // // Save the image // imagegd2($im, './test_updated.gd2'); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Warning: The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromgd2.php // ========== IMAGECREATEFROMGD2 - END // SYNTAX: // GdImage|false imagecreatefromgd2(string $filename) return $return_imagecreatefromgd2; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMGD2 // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMGD2PART // ============================== PUBLIC // ============================== ABOUT // Create a new image from a given part of GD2 file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromgd2part() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromgd2part($filename, $x, $y, $width, $height) { $return_imagecreatefromgd2part = false; // ========== IMAGECREATEFROMGD2PART - BEGIN // ===== ABOUT // Create a new image from a given part of GD2 file or URL // ===== DESCRIPTION // Create a new image from a given part of GD2 file or URL. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromgd2part( // string $filename, // int $x, // int $y, // int $width, // int $height // ): GdImage|false // ===== CODE $return_imagecreatefromgd2part = imagecreatefromgd2part( $filename, // string filename - Path to the GD2 image. $x, // int x - x-coordinate of source point. $y, // int y - y-coordinate of source point. $width, // int width - Source width. $height // int height - Source height. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 imagecreatefromgd2part() example // [php] // // For this example we need the image size before // $image = getimagesize('./test.gd2'); // // // Create the image instance now we got the image // // sizes // $im = imagecreatefromgd2part('./test.gd2', 4, 4, ($image[0] / 2) - 6, ($image[1] / 2) - 6); // // // Do an image operation, in this case we emboss the image // if(function_exists('imagefilter')) // { // imagefilter($im, IMG_FILTER_EMBOSS); // } // // // Save optimized image // imagegd2($im, './test_emboss.gd2'); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Warning: The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromgd2part.php // ========== IMAGECREATEFROMGD2PART - END // SYNTAX: // GdImage|false imagecreatefromgd2part(string $filename, int $x, int $y, int $width, int $height) return $return_imagecreatefromgd2part; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMGD2PART // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMGD // ============================== PUBLIC // ============================== ABOUT // Create a new image from GD file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromgd() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromgd($filename) { $return_imagecreatefromgd = false; // ========== IMAGECREATEFROMGD - BEGIN // ===== ABOUT // Create a new image from GD file or URL // ===== DESCRIPTION // Create a new image from GD file or URL. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromgd(string $filename): GdImage|false // ===== CODE $return_imagecreatefromgd = imagecreatefromgd( $filename // string filename - Path to the GD file. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 imagecreatefromgd() example // [php] // // Load the gd image // $im = @imagecreatefromgd('./test.gd'); // // // Test if the image was loaded // if(!$im) // { // die('Unable to load gd image!'); // } // // // Do image operations here // // // Save the image // imagegd($im, './test_updated.gd'); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Warning: The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromgd.php // ========== IMAGECREATEFROMGD - END // SYNTAX: // GdImage|false imagecreatefromgd(string $filename) return $return_imagecreatefromgd; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMGD // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMGIF // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromgif() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromgif($filename) { $return_imagecreatefromgif = false; // ========== IMAGECREATEFROMGIF - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromgif() returns an image identifier representing the image obtained from the given filename. // Caution: When reading GIF files into memory, only the first frame is returned in the image object. The size of the image is not necessarily what is reported by getimagesize(). // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromgif(string $filename): GdImage|false // ===== CODE $return_imagecreatefromgif = imagecreatefromgif( $filename // string filename - Path to the GIF image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Example to handle an error during loading of a GIF // [php] // function LoadGif($imgname) // { // // Attempt to open // $im = @imagecreatefromgif($imgname); // // // See if it failed // if(!$im) // { // // Create a blank image // $im = imagecreatetruecolor (150, 30); // $bgc = imagecolorallocate ($im, 255, 255, 255); // $tc = imagecolorallocate ($im, 0, 0, 0); // // imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); // // // Output an error message // imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); // } // // return $im; // } // // header('Content-Type: image/gif'); // // $img = LoadGif('bogus.image'); // // imagegif($img); // imagedestroy($img); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromgif.php // ========== IMAGECREATEFROMGIF - END // SYNTAX: // GdImage|false imagecreatefromgif(string $filename) return $return_imagecreatefromgif; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMGIF // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMJPEG // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromjpeg() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromjpeg($filename) { $return_imagecreatefromjpeg = false; // ========== IMAGECREATEFROMJPEG - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromjpeg(string $filename): GdImage|false // ===== CODE $return_imagecreatefromjpeg = imagecreatefromjpeg( $filename // string filename - Path to the JPEG image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Example to handle an error during loading of a JPEG // [php] // function LoadJpeg($imgname) // { // // Attempt to open // $im = @imagecreatefromjpeg($imgname); // // // See if it failed // if(!$im) // { // // Create a black image // $im = imagecreatetruecolor(150, 30); // $bgc = imagecolorallocate($im, 255, 255, 255); // $tc = imagecolorallocate($im, 0, 0, 0); // // imagefilledrectangle($im, 0, 0, 150, 30, $bgc); // // // Output an error message // imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); // } // // return $im; // } // // header('Content-Type: image/jpeg'); // // $img = LoadJpeg('bogus.image'); // // imagejpeg($img); // imagedestroy($img); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromjpeg.php // ========== IMAGECREATEFROMJPEG - END // SYNTAX: // GdImage|false imagecreatefromjpeg(string $filename) return $return_imagecreatefromjpeg; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMJPEG // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMPNG // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefrompng() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefrompng($filename) { $return_imagecreatefrompng = false; // ========== IMAGECREATEFROMPNG - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefrompng() returns an image identifier representing the image obtained from the given filename. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefrompng(string $filename): GdImage|false // ===== CODE $return_imagecreatefrompng = imagecreatefrompng( $filename // string filename - Path to the PNG image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Example to handle an error during loading of a PNG // [php] // function LoadPNG($imgname) // { // // Attempt to open // $im = @imagecreatefrompng($imgname); // // // See if it failed // if(!$im) // { // // Create a blank image // $im = imagecreatetruecolor(150, 30); // $bgc = imagecolorallocate($im, 255, 255, 255); // $tc = imagecolorallocate($im, 0, 0, 0); // // imagefilledrectangle($im, 0, 0, 150, 30, $bgc); // // // Output an error message // imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); // } // // return $im; // } // // header('Content-Type: image/png'); // // $img = LoadPNG('bogus.image'); // // imagepng($img); // imagedestroy($img); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefrompng.php // ========== IMAGECREATEFROMPNG - END // SYNTAX: // GdImage|false imagecreatefrompng(string $filename) return $return_imagecreatefrompng; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMPNG // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMSTRING // ============================== PUBLIC // ============================== ABOUT // Create a new image from the image stream in the string. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromstring() - PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromstring($data) { $return_imagecreatefromstring = false; // ========== IMAGECREATEFROMSTRING - BEGIN // ===== ABOUT // Create a new image from the image stream in the string // ===== DESCRIPTION // imagecreatefromstring() returns an image identifier representing the image obtained from the given data. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, BMP, WBMP, GD2, and WEBP. // ===== SUPPORTED // PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromstring(string $data): GdImage|false // ===== CODE $return_imagecreatefromstring = imagecreatefromstring( $data // string data - A string containing the image data. ); // Return Values // An image object will be returned on success. false is returned if the image type is unsupported, the data is not in a recognised format, or the image is corrupt and cannot be loaded. // // Errors/Exceptions // imagecreatefromstring() raises an E_WARNING level error, if the data is not in a recognized format. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // 7.3.0 - WEBP is supported now (if supported by the libgd in use). // // [examples] // Examples // [example] // Example #1 imagecreatefromstring() example // [php] // $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' // . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' // . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' // . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='; // $data = base64_decode($data); // // $im = imagecreatefromstring($data); // if ($im !== false) { // header('Content-Type: image/png'); // imagepng($im); // imagedestroy($im); // } // else { // echo 'An error occurred.'; // } // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromstring.php // ========== IMAGECREATEFROMSTRING - END // SYNTAX: // GdImage|false imagecreatefromstring(string $data) return $return_imagecreatefromstring; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMSTRING // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMTGA // ============================== OFFLINE // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromtga() - PHP_7 >= PHP_7_4_0, PHP_8 // ============================== CODE /* function php_image_gd_imagecreatefromtga($filename) { $return_imagecreatefromtga = false; // ========== IMAGECREATEFROMTGA - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromtga() returns an image object representing the image obtained from the given filename. // ===== SUPPORTED // PHP_7 >= PHP_7_4_0, PHP_8 // ===== SYNTAX // imagecreatefromtga(string $filename): GdImage|false // ===== CODE $return_imagecreatefromtga = imagecreatefromtga( $filename // string filename - Path to the Truevision TGA image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromtga.php // ========== IMAGECREATEFROMTGA - END // SYNTAX: // GdImage|false imagecreatefromtga(string $filename) return $return_imagecreatefromtga; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMTGA // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMWBMP // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromwbmp() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromwbmp($filename) { $return_imagecreatefromwbmp = false; // ========== IMAGECREATEFROMWBMP - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromwbmp() returns an image identifier representing the image obtained from the given filename. // Note: WBMP images are Wireless Bitmaps, not Windows Bitmaps. The latter can be loaded with imagecreatefrombmp(). // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromwbmp(string $filename): GdImage|false // ===== CODE $return_imagecreatefromwbmp = imagecreatefromwbmp( $filename // string filename - Path to the WBMP image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Example to handle an error during loading of a WBMP // [php] // function LoadWBMP($imgname) // { // // Attempt to open // $im = @imagecreatefromwbmp($imgname); // // // See if it failed // if(!$im) // { // // Create a blank image // $im = imagecreatetruecolor(150, 30); // $bgc = imagecolorallocate($im, 255, 255, 255); // $tc = imagecolorallocate($im, 0, 0, 0); // // imagefilledrectangle($im, 0, 0, 150, 30, $bgc); // // // Output an error message // imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); // } // // return $im; // } // // header('Content-Type: image/vnd.wap.wbmp'); // // $img = LoadWBMP('bogus.image'); // // imagewbmp($img); // imagedestroy($img); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromwbmp.php // ========== IMAGECREATEFROMWBMP - END // SYNTAX: // GdImage|false imagecreatefromwbmp(string $filename) return $return_imagecreatefromwbmp; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMWBMP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMWEBP // ============================== OFFLINE // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromwebp() - PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagecreatefromwebp($filename) { $return_imagecreatefromwebp = false; // ========== IMAGECREATEFROMWEBP - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromwebp() returns an image identifier representing the image obtained from the given filename. Note that animated WebP files cannot be read. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromwebp(string $filename): GdImage|false // ===== CODE $return_imagecreatefromwebp = imagecreatefromwebp( $filename // string filename - Path to the WebP image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Convert an WebP image to a jpeg image using imagecreatefromwebp() // [php] // // Load the WebP file // $im = imagecreatefromwebp('./example.webp'); // // // Convert it to a jpeg file with 100% quality // imagejpeg($im, './example.jpeg', 100); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromwebp.php // ========== IMAGECREATEFROMWEBP - END // SYNTAX: // GdImage|false imagecreatefromwebp(string $filename) return $return_imagecreatefromwebp; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMWEBP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMXBM // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromxbm() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromxbm($filename) { $return_imagecreatefromxbm = false; // ========== IMAGECREATEFROMXBM - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromxbm() returns an image identifier representing the image obtained from the given filename. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromxbm(string $filename): GdImage|false // ===== CODE $return_imagecreatefromxbm = imagecreatefromxbm( $filename // string filename - Path to the XBM image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Convert an XBM image to a png image using imagecreatefromxbm() // [php] // // Load the xbm file // $xbm = imagecreatefromxbm('./example.xbm'); // // // Convert it to a png file // imagepng($xbm, './example.png'); // imagedestroy($xbm); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromxbm.php // ========== IMAGECREATEFROMXBM - END // SYNTAX: // GdImage|false imagecreatefromxbm(string $filename) return $return_imagecreatefromxbm; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMXBM // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATEFROMXPM // ============================== PUBLIC // ============================== ABOUT // Create a new image from file or URL. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatefromxpm() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatefromxpm($filename) { $return_imagecreatefromxpm = false; // ========== IMAGECREATEFROMXPM - BEGIN // ===== ABOUT // Create a new image from file or URL // ===== DESCRIPTION // imagecreatefromxpm() returns an image identifier representing the image obtained from the given filename. // Tip: A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatefromxpm(string $filename): GdImage|false // ===== CODE $return_imagecreatefromxpm = imagecreatefromxpm( $filename // string filename - Path to the XPM image. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Creating an image instance using imagecreatefromxpm() // [php] // // Check for XPM support // if(!(imagetypes() & IMG_XPM)) // { // die('Support for xpm was not found!'); // } // // // Create the image instance // $xpm = imagecreatefromxpm('./example.xpm'); // // // Do image operations here // // // PHP has no support for writing xpm images // // so in this case we save the image as a // // jpeg file with 100% quality // imagejpeg($xpm, './example.jpg', 100); // imagedestroy($xpm); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatefromxpm.php // ========== IMAGECREATEFROMXPM - END // SYNTAX: // GdImage|false imagecreatefromxpm(string $filename) return $return_imagecreatefromxpm; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATEFROMXPM // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECREATETRUECOLOR // ============================== PUBLIC // ============================== ABOUT // Create a new true color image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecreatetruecolor() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagecreatetruecolor($width, $height) { $return_image_object = false; // ========== IMAGECREATETRUECOLOR - BEGIN // ===== ABOUT // Create a new true color image // ===== DESCRIPTION // imagecreatetruecolor() returns an image object representing a black image of the specified size. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagecreatetruecolor(int $width, int $height): GdImage|false // ===== CODE $return_image_object = imagecreatetruecolor( $width, // int width - Image width. $height // int height - Image height. ); // Return Values // Returns an image object on success, false on errors. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 Creating a new GD image stream and outputting an image. // [php] // header ('Content-Type: image/png'); // $im = @imagecreatetruecolor(120, 20) // or die('Cannot Initialize new GD image stream'); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecreatetruecolor.php // ========== IMAGECREATETRUECOLOR - END // SYNTAX: // GdImage|false imagecreatetruecolor(int $width, int $height) return $return_image_object; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGECREATETRUECOLOR // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECROP // ============================== OFFLINE // ============================== ABOUT // Crop an image to the given rectangle. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecrop() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagecrop($image, $rectangle) { $return_imagecrop = false; // ========== IMAGECROP - BEGIN // ===== ABOUT // Crop an image to the given rectangle // ===== DESCRIPTION // Crops an image to the given rectangular area and returns the resulting image. The given image is not modified. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imagecrop(GdImage $image, array $rectangle): GdImage|false // ===== CODE $return_imagecrop = imagecrop( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $rectangle // array rectangle - The cropping rectangle as array with keys x, y, width and height. ); // Return Values // Return cropped image object on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 imagecrop() example // This example shows how to crop an image to a square area. // [php] // $im = imagecreatefrompng('example.png'); // $size = min(imagesx($im), imagesy($im)); // $im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]); // if ($im2 !== FALSE) { // imagepng($im2, 'example-cropped.png'); // imagedestroy($im2); // } // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagecrop.php // ========== IMAGECROP - END // SYNTAX: // GdImage|false imagecrop(GdImage $image, array $rectangle) return $return_imagecrop; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGECROP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGECROPAUTO // ============================== OFFLINE // ============================== ABOUT // Crop an image automatically using one of the available modes. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagecropauto() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== USING CONSTANTS (1) // IMG_CROP_DEFAULT - imagecropauto() // ============================== CODE /* function php_image_gd_imagecropauto($image, $mode = IMG_CROP_DEFAULT, $threshold = 0.5, $color = -1) { $return_imagecropauto = false; // ========== IMAGECROPAUTO - BEGIN // ===== ABOUT // Crop an image automatically using one of the available modes // ===== DESCRIPTION // Automatically crops an image according to the given mode. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imagecropauto( // GdImage $image, // int $mode = IMG_CROP_DEFAULT, // float $threshold = 0.5, // int $color = -1 // ): GdImage|false // ===== CODE $return_imagecropauto = imagecropauto( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $mode, // int mode - One of the following constants: // IMG_CROP_DEFAULT - Same as IMG_CROP_TRANSPARENT. Before PHP 7.4.0, the bundled libgd fell back to IMG_CROP_SIDES, if the image had no transparent color. // IMG_CROP_TRANSPARENT - Crops out a transparent background. // IMG_CROP_BLACK - Crops out a black background. // IMG_CROP_WHITE - Crops out a white background. // IMG_CROP_SIDES - Uses the 4 corners of the image to attempt to detect the background to crop. // IMG_CROP_THRESHOLD - Crops an image using the given threshold and color. $threshold, // float threshold - Specifies the tolerance in percent to be used while comparing the image color and the color to crop. The method used to calculate the color difference is based on the color distance in the RGB(a) cube. // Used only in IMG_CROP_THRESHOLD mode. // Note: Before PHP 7.4.0, the bundled libgd used a somewhat different algorithm, so the same threshold yielded different results for system and bundled libgd. $color // int color - Either an RGB color value or a palette index. // Used only in IMG_CROP_THRESHOLD mode. ); // Return Values // Returns a cropped image object on success or false on failure. If the complete image was cropped, imagecrop() returns false. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // 7.4.0 - The behavior of imagecropauto() in the bundled libgd has been synced with that of system libgd: IMG_CROP_DEFAULT no longer falls back to IMG_CROP_SIDES and threshold-cropping now uses the same algorithm as system libgd. // 7.4.0 - The default value of mode has been changed to IMG_CROP_AUTO. Formerly, the default value has been -1 which corresponds to IMG_CROP_DEFAULT, but passing -1 is now deprecated. // // [examples] // Examples // [example] // Example #1 Proper handling of auto-cropping // As noted in the return value section, imagecropauto() returns false if the whole image was cropped. In this example we have an image object $im which should be automatically cropped only if there is something to crop; otherwise we want to proceed with the original image. // [php] // $cropped = imagecropauto($im, IMG_CROP_DEFAULT); // if ($cropped !== false) { // in case a new image object was returned // imagedestroy($im); // we destroy the original image // $im = $cropped; // and assign the cropped image to $im // } // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagecropauto.php // ========== IMAGECROPAUTO - END // SYNTAX: // GdImage|false imagecropauto(GdImage $image, int $mode = IMG_CROP_DEFAULT, float $threshold = 0.5, int $color = -1) return $return_imagecropauto; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGECROPAUTO // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEDASHEDLINE // ============================== PUBLIC // ============================== ABOUT // Draw a dashed line. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagedashedline() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagedashedline($image, $x1, $y1, $x2, $y2, $color) { $return_imagedashedline = false; // ========== IMAGEDASHEDLINE - BEGIN // ===== ABOUT // Draw a dashed line // ===== DESCRIPTION // This function is deprecated. Use combination of imagesetstyle() and imageline() instead. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagedashedline( // GdImage $image, // int $x1, // int $y1, // int $x2, // int $y2, // int $color // ): bool // ===== CODE $return_imagedashedline = imagedashedline( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x1, // int x1 - Upper left x coordinate. $y1, // int y1 - Upper left y coordinate 0, 0 is the top left corner of the image. $x2, // int x2 - Bottom right x coordinate. $y2, // int y2 - Bottom right y coordinate. $color // int color - The fill color. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagedashedline() example // [php] // // Create a 100x100 image // $im = imagecreatetruecolor(100, 100); // $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); // // // Draw a vertical dashed line // imagedashedline($im, 50, 25, 50, 75, $white); // // // Save the image // imagepng($im, './dashedline.png'); // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Alternative to imagedashedline() // [php] // // Create a 100x100 image // $im = imagecreatetruecolor(100, 100); // $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); // // // Define our style: First 4 pixels is white and the // // next 4 is transparent. This creates the dashed line effect // $style = Array( // $white, // $white, // $white, // $white, // IMG_COLOR_TRANSPARENT, // IMG_COLOR_TRANSPARENT, // IMG_COLOR_TRANSPARENT, // IMG_COLOR_TRANSPARENT // ); // // imagesetstyle($im, $style); // // // Draw the dashed line // imageline($im, 50, 25, 50, 75, IMG_COLOR_STYLED); // // // Save the image // imagepng($im, './imageline.png'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagedashedline.php // ========== IMAGEDASHEDLINE - END // SYNTAX: // bool imagedashedline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color) return $return_imagedashedline; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEDASHEDLINE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEDESTROY // ============================== PUBLIC // ============================== ABOUT // Destroy an image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagedestroy() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagedestroy($image) { $return_imagedestroy = false; // ========== IMAGEDESTROY - BEGIN // ===== ABOUT // Destroy an image // ===== DESCRIPTION // Note: This function has no effect. Prior to PHP 8.0.0, this function was used to close the resource. // Prior to PHP 8.0.0, imagedestroy() freed any memory associated with image image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagedestroy(GdImage $image): bool // ===== CODE $return_imagedestroy = imagedestroy( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - This function is a NOP now. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Using imagedestroy() prior to PHP 8.0.0 // [php] // // create a 100 x 100 image // $im = imagecreatetruecolor(100, 100); // // // alter or save the image // // // frees image from memory // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagedestroy.php // ========== IMAGEDESTROY - END // SYNTAX: // bool imagedestroy(GdImage $image) return $return_imagedestroy; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEDESTROY // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEELLIPSE // ============================== PUBLIC // ============================== ABOUT // Draw an ellipse. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageellipse() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageellipse($image, $center_x, $center_y, $width, $height, $color) { $return_imageellipse = false; // ========== IMAGEELLIPSE - BEGIN // ===== ABOUT // Draw an ellipse // ===== DESCRIPTION // Draws an ellipse centered at the specified coordinates. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageellipse( // GdImage $image, // int $center_x, // int $center_y, // int $width, // int $height, // int $color // ): bool // ===== CODE $return_imageellipse = imageellipse( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $center_x, // int center_x - x-coordinate of the center. $center_y, // int center_y - y-coordinate of the center. $width, // int width - The ellipse width. $height, // int height - The ellipse height. $color // int color - The color of the ellipse. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imageellipse() example // [php] // // // Create a blank image. // $image = imagecreatetruecolor(400, 300); // // // Select the background color. // $bg = imagecolorallocate($image, 0, 0, 0); // // // Fill the background with the color selected above. // imagefill($image, 0, 0, $bg); // // // Choose a color for the ellipse. // $col_ellipse = imagecolorallocate($image, 255, 255, 255); // // // Draw the ellipse. // imageellipse($image, 200, 150, 300, 200, $col_ellipse); // // // Output the image. // header("Content-type: image/png"); // imagepng($image); // // [/php] // [/example] // [/examples] // // Notes // Note: imageellipse() ignores imagesetthickness(). // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imageellipse.php // ========== IMAGEELLIPSE - END // SYNTAX: // bool imageellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color) return $return_imageellipse; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEELLIPSE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILL // ============================== PUBLIC // ============================== ABOUT // Flood fill. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefill() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefill($image, $x, $y, $color) { $return_imagefill = false; // ========== IMAGEFILL - BEGIN // ===== ABOUT // Flood fill // ===== DESCRIPTION // Performs a flood fill starting at the given coordinate (top left is 0, 0) with the given color in the image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefill( // GdImage $image, // int $x, // int $y, // int $color // ): bool // ===== CODE $return_imagefill = imagefill( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x, // int x - x-coordinate of start point. $y, // int y - y-coordinate of start point. $color // int color - The fill color. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagefill() example // [php] // // $im = imagecreatetruecolor(100, 100); // // // sets background to red // $red = imagecolorallocate($im, 255, 0, 0); // imagefill($im, 0, 0, $red); // // header('Content-type: image/png'); // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagefill.php // ========== IMAGEFILL - END // SYNTAX: // bool imagefill(GdImage $image, int $x, int $y, int $color) return $return_imagefill; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEFILL // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILLEDARC // ============================== PUBLIC // ============================== ABOUT // Draw a partial arc and fill it. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefilledarc() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefilledarc($image, $center_x, $center_y, $width, $height, $start_angle, $end_angle, $color, $style) { $return_imagefilledarc = false; // ========== IMAGEFILLEDARC - BEGIN // ===== ABOUT // Draw a partial arc and fill it // ===== DESCRIPTION // Draws a partial arc centered at the specified coordinate in the given image. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefilledarc( // GdImage $image, // int $center_x, // int $center_y, // int $width, // int $height, // int $start_angle, // int $end_angle, // int $color, // int $style // ): bool // ===== CODE $return_imagefilledarc = imagefilledarc( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $center_x, // int center_x - x-coordinate of the center. $center_y, // int center_y - y-coordinate of the center. $width, // int width - The arc width. $height, // int height - The arc height. $start_angle, // int start_angle - The arc start angle, in degrees. $end_angle, // int end_angle - The arc end angle, in degrees. 0° is located at the three-o'clock position, and the arc is drawn clockwise. $color, // int color - A color identifier created with imagecolorallocate(). $style // int style - A bitwise OR of the following possibilities: // 1. IMG_ARC_PIE // 2. IMG_ARC_CHORD // 3. IMG_ARC_NOFILL // 4. IMG_ARC_EDGED // IMG_ARC_PIE and IMG_ARC_CHORD are mutually exclusive; IMG_ARC_CHORD just connects the starting and ending angles with a straight line, while IMG_ARC_PIE produces a rounded edge. IMG_ARC_NOFILL indicates that the arc or chord should be outlined, not filled. IMG_ARC_EDGED, used together with IMG_ARC_NOFILL, indicates that the beginning and ending angles should be connected to the center - this is a good way to outline (rather than fill) a 'pie slice'. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Creating a 3D looking pie // [php] // // // create image // $image = imagecreatetruecolor(100, 100); // // // allocate some colors // $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); // $gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); // $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90); // $navy = imagecolorallocate($image, 0x00, 0x00, 0x80); // $darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50); // $red = imagecolorallocate($image, 0xFF, 0x00, 0x00); // $darkred = imagecolorallocate($image, 0x90, 0x00, 0x00); // // // make the 3D effect // for ($i = 60; $i > 50; $i--) { // imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE); // imagefilledarc($image, 50, $i, 100, 50, 45, 75 , $darkgray, IMG_ARC_PIE); // imagefilledarc($image, 50, $i, 100, 50, 75, 360 , $darkred, IMG_ARC_PIE); // } // // imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE); // imagefilledarc($image, 50, 50, 100, 50, 45, 75 , $gray, IMG_ARC_PIE); // imagefilledarc($image, 50, 50, 100, 50, 75, 360 , $red, IMG_ARC_PIE); // // // // flush image // header('Content-type: image/png'); // imagepng($image); // imagedestroy($image); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagefilledarc.php // ========== IMAGEFILLEDARC - END // SYNTAX: // bool imagefilledarc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color, int $style) return $return_imagefilledarc; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEFILLEDARC // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILLEDELLIPSE // ============================== PUBLIC // ============================== ABOUT // Draw a filled ellipse. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefilledellipse() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefilledellipse($image, $center_x, $center_y, $width, $height, $color) { $return_imagefilledellipse = false; // ========== IMAGEFILLEDELLIPSE - BEGIN // ===== ABOUT // Draw a filled ellipse // ===== DESCRIPTION // Draws an ellipse centered at the specified coordinate on the given image. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefilledellipse( // GdImage $image, // int $center_x, // int $center_y, // int $width, // int $height, // int $color // ): bool // ===== CODE $return_imagefilledellipse = imagefilledellipse( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $center_x, // int center_x - x-coordinate of the center. $center_y, // int center_y - y-coordinate of the center. $width, // int width - The ellipse width. $height, // int height - The ellipse height. $color // int color - The fill color. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagefilledellipse() example // [php] // // // create a blank image // $image = imagecreatetruecolor(400, 300); // // // fill the background color // $bg = imagecolorallocate($image, 0, 0, 0); // // // choose a color for the ellipse // $col_ellipse = imagecolorallocate($image, 255, 255, 255); // // // draw the white ellipse // imagefilledellipse($image, 200, 150, 300, 200, $col_ellipse); // // // output the picture // header("Content-type: image/png"); // imagepng($image); // // [/php] // [/example] // [/examples] // // Notes // Note: imagefilledellipse() ignores imagesetthickness(). // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagefilledellipse.php // ========== IMAGEFILLEDELLIPSE - END // SYNTAX: // bool imagefilledellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color) return $return_imagefilledellipse; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEFILLEDELLIPSE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILLEDPOLYGON // ============================== PUBLIC // ============================== ABOUT // Draw a filled polygon. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefilledpolygon() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefilledpolygon($image, $points, $num_points, $color) { $return_imagefilledpolygon = false; // ========== IMAGEFILLEDPOLYGON - BEGIN // ===== ABOUT // Draw a filled polygon // ===== DESCRIPTION // imagefilledpolygon() creates a filled polygon in the given image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // Signature as of PHP 8.0.0 (not supported with named arguments) // imagefilledpolygon(GdImage $image, array $points, int $color): bool // // Alternative signature (deprecated as of PHP 8.1.0) // imagefilledpolygon( // GdImage $image, // array $points, // int $num_points, // int $color // ): bool // ===== CODE $return_imagefilledpolygon = imagefilledpolygon( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $points, // array points - An array containing the x and y coordinates of the polygons vertices consecutively. $num_points, // int num_points - Total number of points (vertices), which must be at least 3. // If this parameter is omitted as per the second signature, points must have an even number of elements, and num_points is assumed to be count($points)/2. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The parameter num_points has been deprecated. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagefilledpolygon() example // [php] // // set up array of points for polygon // $values = array( // 40, 50, // Point 1 (x, y) // 20, 240, // Point 2 (x, y) // 60, 60, // Point 3 (x, y) // 240, 20, // Point 4 (x, y) // 50, 40, // Point 5 (x, y) // 10, 10 // Point 6 (x, y) // ); // // // create image // $image = imagecreatetruecolor(250, 250); // // // allocate colors // $bg = imagecolorallocate($image, 0, 0, 0); // $blue = imagecolorallocate($image, 0, 0, 255); // // // fill the background // imagefilledrectangle($image, 0, 0, 249, 249, $bg); // // // draw a polygon // imagefilledpolygon($image, $values, 6, $blue); // // // flush image // header('Content-type: image/png'); // imagepng($image); // imagedestroy($image); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagefilledpolygon.php // ========== IMAGEFILLEDPOLYGON - END // SYNTAX: // bool imagefilledpolygon(GdImage $image, array $points, int $num_points, int $color) return $return_imagefilledpolygon; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEFILLEDPOLYGON // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILLEDRECTANGLE // ============================== PUBLIC // ============================== ABOUT // Draw a filled rectangle. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefilledrectangle() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color) { $return_imagefilledrectangle = false; // ========== IMAGEFILLEDRECTANGLE - BEGIN // ===== ABOUT // Draw a filled rectangle // ===== DESCRIPTION // Creates a rectangle filled with color in the given image starting at point 1 and ending at point 2. 0, 0 is the top left corner of the image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefilledrectangle( // GdImage $image, // int $x1, // int $y1, // int $x2, // int $y2, // int $color // ): bool // ===== CODE $return_imagefilledrectangle = imagefilledrectangle( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x1, // int x1 - x-coordinate for point 1. $y1, // int y1 - y-coordinate for point 1. $x2, // int x2 - x-coordinate for point 2. $y2, // int y2 - y-coordinate for point 2. $color // int color - The fill color. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagefilledrectangle() usage // [php] // // Create a 55x30 image // $im = imagecreatetruecolor(55, 30); // $white = imagecolorallocate($im, 255, 255, 255); // // // Draw a white rectangle // imagefilledrectangle($im, 4, 4, 50, 25, $white); // // // Save the image // imagepng($im, './imagefilledrectangle.png'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagefilledrectangle.php // ========== IMAGEFILLEDRECTANGLE - END // SYNTAX: // bool imagefilledrectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color) return $return_imagefilledrectangle; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEFILLEDRECTANGLE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILLTOBORDER // ============================== PUBLIC // ============================== ABOUT // Flood fill to specific color. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefilltoborder() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefilltoborder($image, $x, $y, $border_color, $color) { $return_imagefilltoborder = false; // ========== IMAGEFILLTOBORDER - BEGIN // ===== ABOUT // Flood fill to specific color // ===== DESCRIPTION // imagefilltoborder() performs a flood fill whose border color is defined by border_color. The starting point for the fill is x, y (top left is 0, 0) and the region is filled with color color. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefilltoborder( // GdImage $image, // int $x, // int $y, // int $border_color, // int $color // ): bool // ===== CODE $return_imagefilltoborder = imagefilltoborder( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x, // int x - x-coordinate of start. $y, // int y - y-coordinate of start. $border_color, // int border_color - The border color. A color identifier created with imagecolorallocate(). $color // int color - The fill color. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Filling an ellipse with a color // [php] // // Create the image handle, set the background to white // $im = imagecreatetruecolor(100, 100); // imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 255, 255, 255)); // // // Draw an ellipse to fill with a black border // imageellipse($im, 50, 50, 50, 50, imagecolorallocate($im, 0, 0, 0)); // // // Set the border and fill colors // $border = imagecolorallocate($im, 0, 0, 0); // $fill = imagecolorallocate($im, 255, 0, 0); // // // Fill the selection // imagefilltoborder($im, 50, 50, $border, $fill); // // // Output and free memory // header('Content-type: image/png'); // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // The algorithm does not explicitly remember which pixels have already been set, but rather infers that from the color of the pixel, so it cannot distinguish between freshly set pixels and pixels that are already there. That means chosing any fill color that is already used in the image may yield undesired results. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagefilltoborder.php // ========== IMAGEFILLTOBORDER - END // SYNTAX: // bool imagefilltoborder(GdImage $image, int $x, int $y, int $border_color, int $color) return $return_imagefilltoborder; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEFILLTOBORDER // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFILTER // ============================== OFFLINE // ============================== ABOUT // Applies a filter to an image. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefilter() - PHP_5, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagefilter($image, $filter, $args) { $return_imagefilter = false; // ========== IMAGEFILTER - BEGIN // ===== ABOUT // Applies a filter to an image // ===== DESCRIPTION // imagefilter() applies the given filter filter on the image. // ===== SUPPORTED // PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefilter(GdImage $image, int $filter, array|int|float|bool ...$args): bool // ===== CODE $return_imagefilter = imagefilter( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $filter, // int filter - filter can be one of the following: // * IMG_FILTER_NEGATE : Reverses all colors of the image. // * IMG_FILTER_GRAYSCALE : Converts the image into grayscale by changing the red, green and blue components to their weighted sum using the same coefficients as the REC.601 luma (Y') calculation. The alpha components are retained. For palette images the result may differ due to palette limitations. // * IMG_FILTER_BRIGHTNESS : Changes the brightness of the image. Use args to set the level of brightness. The range for the brightness is -255 to 255. // * IMG_FILTER_CONTRAST : Changes the contrast of the image. Use args to set the level of contrast. // * IMG_FILTER_COLORIZE : Like IMG_FILTER_GRAYSCALE, except you can specify the color. Use args, arg2 and arg3 in the form of red, green, blue and arg4 for the alpha channel. The range for each color is 0 to 255. // * IMG_FILTER_EDGEDETECT : Uses edge detection to highlight the edges in the image. // * IMG_FILTER_EMBOSS : Embosses the image. // * IMG_FILTER_GAUSSIAN_BLUR : Blurs the image using the Gaussian method. // * IMG_FILTER_SELECTIVE_BLUR : Blurs the image. // * IMG_FILTER_MEAN_REMOVAL : Uses mean removal to achieve a "sketchy" effect. // * IMG_FILTER_SMOOTH : Makes the image smoother. Use args to set the level of smoothness. // * IMG_FILTER_PIXELATE : Applies pixelation effect to the image, use args to set the block size and arg2 to set the pixelation effect mode. // * IMG_FILTER_SCATTER : Applies scatter effect to the image, use args and arg2 to define the effect strength and additionally arg3 to only apply the on select pixel colors. $args // array|int|float|bool args - // * IMG_FILTER_BRIGHTNESS : Brightness level. // * IMG_FILTER_CONTRAST : Contrast level. // * IMG_FILTER_COLORIZE : Value of red component. // * IMG_FILTER_SMOOTH : Smoothness level. // * IMG_FILTER_PIXELATE : Block size in pixels. // * IMG_FILTER_SCATTER : Effect substraction level. This must not be higher or equal to the addition level set with arg2. // arg2 - // * IMG_FILTER_COLORIZE : Value of green component. // * IMG_FILTER_PIXELATE : Whether to use advanced pixelation effect or not (defaults to false). // * IMG_FILTER_SCATTER : Effect addition level. // arg3 - // * IMG_FILTER_COLORIZE : Value of blue component. // * IMG_FILTER_SCATTER : Optional array indexed color values to apply effect at. // arg4 - // * IMG_FILTER_COLORIZE : Alpha channel, A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 7.4.0 - Scatter support (IMG_FILTER_SCATTER) was added. // // [examples] // Examples // [example] // Example #1 imagefilter() grayscale example // [php] // $im = imagecreatefrompng('dave.png'); // // if($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) // { // echo 'Image converted to grayscale.'; // // imagepng($im, 'dave.png'); // } // else // { // echo 'Conversion to grayscale failed.'; // } // // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 imagefilter() brightness example // [php] // $im = imagecreatefrompng('sean.png'); // // if($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)) // { // echo 'Image brightness changed.'; // // imagepng($im, 'sean.png'); // imagedestroy($im); // } // else // { // echo 'Image brightness change failed.'; // } // [/php] // [/example] // [example] // Example #3 imagefilter() colorize example // [php] // $im = imagecreatefrompng('philip.png'); // // // R, G, B, so 0, 255, 0 is green // if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)) // { // echo 'Image successfully shaded green.'; // // imagepng($im, 'philip.png'); // imagedestroy($im); // } // else // { // echo 'Green shading failed.'; // } // [/php] // [/example] // [example] // Example #4 imagefilter() negate example // [php] // // Define our negate function so its portable for // // php versions without imagefilter() // function negate($im) // { // if(function_exists('imagefilter')) // { // return imagefilter($im, IMG_FILTER_NEGATE); // } // // for($x = 0; $x < imagesx($im); ++$x) // { // for($y = 0; $y < imagesy($im); ++$y) // { // $index = imagecolorat($im, $x, $y); // $rgb = imagecolorsforindex($index); // $color = imagecolorallocate($im, 255 - $rgb['red'], 255 - $rgb['green'], 255 - $rgb['blue']); // // imagesetpixel($im, $x, $y, $color); // } // } // // return(true); // } // // $im = imagecreatefromjpeg('kalle.jpg'); // // if($im && negate($im)) // { // echo 'Image successfully converted to negative colors.'; // // imagejpeg($im, 'kalle.jpg', 100); // imagedestroy($im); // } // else // { // echo 'Converting to negative colors failed.'; // } // [/php] // [/example] // [example] // Example #5 imagefilter() pixelate example // [php] // // Load the PHP logo, we need to create two instances // // to show the differences // $logo1 = imagecreatefrompng('./php.png'); // $logo2 = imagecreatefrompng('./php.png'); // // // Create the image instance we want to show the // // differences on // $output = imagecreatetruecolor(imagesx($logo1) * 2, imagesy($logo1)); // // // Apply pixelation to each instance, with a block // // size of 3 // imagefilter($logo1, IMG_FILTER_PIXELATE, 3); // imagefilter($logo2, IMG_FILTER_PIXELATE, 3, true); // // // Merge the differences onto the output image // imagecopy($output, $logo1, 0, 0, 0, 0, imagesx($logo1) - 1, imagesy($logo1) - 1); // imagecopy($output, $logo2, imagesx($logo2), 0, 0, 0, imagesx($logo2) - 1, imagesy($logo2) - 1); // imagedestroy($logo1); // imagedestroy($logo2); // // // Output the differences // header('Content-Type: image/png'); // imagepng($output); // imagedestroy($output); // [/php] // [/example] // [example] // Example #6 imagefilter() scatter example // [php] // Load the image // $logo = imagecreatefrompng('./php.png'); // // // Apply a very soft scatter effect to the image // imagefilter($logo, IMG_FILTER_SCATTER, 3, 5); // // // Output the image with the scatter effect // header('Content-Type: image/png'); // imagepng($logo); // imagedestroy($logo); // [/php] // [/example] // [/examples] // // Notes // Note: The result of IMG_FILTER_SCATTER is always random. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagefilter.php // ========== IMAGEFILTER - END // SYNTAX: // bool imagefilter(GdImage $image, int $filter, array|int|float|bool $args) return $return_imagefilter; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEFILTER // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFLIP // ============================== OFFLINE // ============================== ABOUT // Flips an image using a given mode. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imageflip() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imageflip($image, $mode) { $return_imageflip = false; // ========== IMAGEFLIP - BEGIN // ===== ABOUT // Flips an image using a given mode // ===== DESCRIPTION // Flips the image image using the given mode. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imageflip(GdImage $image, int $mode): bool // ===== CODE $return_imageflip = imageflip( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $mode // int mode - Flip mode, this can be one of the IMG_FLIP_* constants: // Constant - Meaning // IMG_FLIP_HORIZONTAL - Flips the image horizontally. // IMG_FLIP_VERTICAL - Flips the image vertically. // IMG_FLIP_BOTH - Flips the image both horizontally and vertically. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Flips an image vertically // This example uses the IMG_FLIP_VERTICAL constant. // [php] // // File // $filename = 'phplogo.png'; // // // Content type // header('Content-type: image/png'); // // // Load // $im = imagecreatefrompng($filename); // // // Flip it vertically // imageflip($im, IMG_FLIP_VERTICAL); // // // Output // imagejpeg($im); // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Flips the image horizontally // This example uses the IMG_FLIP_HORIZONTAL constant. // [php] // // File // $filename = 'phplogo.png'; // // // Content type // header('Content-type: image/png'); // // // Load // $im = imagecreatefrompng($filename); // // // Flip it horizontally // imageflip($im, IMG_FLIP_HORIZONTAL); // // // Output // imagejpeg($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imageflip.php // ========== IMAGEFLIP - END // SYNTAX: // bool imageflip(GdImage $image, int $mode) return $return_imageflip; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEFLIP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFONTHEIGHT // ============================== PUBLIC // ============================== ABOUT // Get font height. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefontheight() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefontheight($font) { $return_font_height = 0; // ========== IMAGEFONTHEIGHT - BEGIN // ===== ABOUT // Get font height // ===== DESCRIPTION // Returns the pixel height of a character in the specified font. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefontheight(GdFont|int $font): int // ===== CODE $return_font_height = imagefontheight( $font // GdFont|int font - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont(). ); // Return Values // Returns the pixel height of the font. // // Changelog // Version - Description // 8.1.0 - The font parameter now accepts both an GdFont instance and an int; previously only int was accepted. // // [examples] // Examples // [example] // Example #1 Using imagefontheight() on built-in fonts // [php] // echo 'Font height: ' . imagefontheight(4); // [/php] // The above example will output something similar to: // [result] // Font height: 16 // [/result] // [/example] // [example] // Example #2 Using imagefontheight() together with imageloadfont() // [php] // // Load a .gdf font // $font = imageloadfont('anonymous.gdf'); // // echo 'Font height: ' . imagefontheight($font); // [/php] // The above example will output something similar to: // [result] // Font height: 43 // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagefontheight.php // ========== IMAGEFONTHEIGHT - END // SYNTAX: // int imagefontheight(GdFont|int $font) return $return_font_height; // int } // ============================== END // PHP_IMAGE_GD_IMAGEFONTHEIGHT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFONTWIDTH // ============================== PUBLIC // ============================== ABOUT // Get font width. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefontwidth() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefontwidth($font) { $return_imagefontwidth = 0; // ========== IMAGEFONTWIDTH - BEGIN // ===== ABOUT // Get font width // ===== DESCRIPTION // Returns the pixel width of a character in font. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefontwidth(GdFont|int $font): int // ===== CODE $return_imagefontwidth = imagefontwidth( $font // GdFont|int font - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont(). ); // Return Values // Returns the pixel width of the font. // // Changelog // Version - Description // 8.1.0 - The font parameter now accepts both an GdFont instance and an int; previously only int was accepted. // // [examples] // Examples // [example] // Example #1 Using imagefontwidth() on built-in fonts // [php] // echo 'Font width: ' . imagefontwidth(4); // [/php] // The above example will output something similar to: // [result] // Font width: 8 // [/result] // [/example] // [example] // Example #2 Using imagefontwidth() together with imageloadfont() // [php] // // Load a .gdf font // $font = imageloadfont('anonymous.gdf'); // // echo 'Font width: ' . imagefontwidth($font); // [/php] // The above example will output something similar to: // [result] // Font width: 23 // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagefontwidth.php // ========== IMAGEFONTWIDTH - END // SYNTAX: // int imagefontwidth(GdFont|int $font) return $return_imagefontwidth; // int } // ============================== END // PHP_IMAGE_GD_IMAGEFONTWIDTH // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFTBBOX // ============================== PUBLIC // ============================== ABOUT // Give the bounding box of a text using fonts via freetype2. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageftbbox() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageftbbox($size, $angle, $font_filename, $string, $options = array()) { $return_imageftbbox = false; // ========== IMAGEFTBBOX - BEGIN // ===== ABOUT // Give the bounding box of a text using fonts via freetype2 // ===== DESCRIPTION // This function calculates and returns the bounding box in pixels for a FreeType text. // Note: Prior to PHP 8.0.0, imageftbbox() was an extended variant of imagettfbbox() which additionally supported the options. As of PHP 8.0.0, imagettfbbox() is an alias of imageftbbox(). // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageftbbox( // float $size, // float $angle, // string $font_filename, // string $string, // array $options = [] // ): array|false // ===== CODE $return_imageftbbox = imageftbbox( $size, // float size - The font size in points. $angle, // float angle - Angle in degrees in which string will be measured. $font_filename, // string font_filename - The name of the TrueType font file (can be a URL). Depending on which version of the GD library that PHP is using, it may attempt to search for files that do not begin with a leading '/' by appending '.ttf' to the filename and searching along a library-defined font path. $string, // string string - The string to be measured. $options // array options - Possible array indexes for options // Key (Type) - Meaning // linespacing (float) - Defines drawing linespacing ); // Return Values // imageftbbox() returns an array with 8 elements representing four points making the bounding box of the text: // 0 - lower left corner, X position // 1 - lower left corner, Y position // 2 - lower right corner, X position // 3 - lower right corner, Y position // 4 - upper right corner, X position // 5 - upper right corner, Y position // 6 - upper left corner, X position // 7 - upper left corner, Y position // The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner seeing the text horizontally. // On failure, false is returned. // // [examples] // Examples // [example] // Example #1 imageftbbox() example // [php] // // Create a 300x150 image // $im = imagecreatetruecolor(300, 150); // $black = imagecolorallocate($im, 0, 0, 0); // $white = imagecolorallocate($im, 255, 255, 255); // // // Set the background to be white // imagefilledrectangle($im, 0, 0, 299, 299, $white); // // // Path to our font file // $font = './arial.ttf'; // // // First we create our bounding box // $bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group'); // // // This is our cordinates for X and Y // $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5; // $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // // imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group'); // // // Output to browser // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR) // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imageftbbox.php // ========== IMAGEFTBBOX - END // SYNTAX: // array|false imageftbbox(float $size, float $angle, string $font_filename, string $string, array $options = array()) return $return_imageftbbox; // array|false } // ============================== END // PHP_IMAGE_GD_IMAGEFTBBOX // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEFTTEXT // ============================== PUBLIC // ============================== ABOUT // Write text to the image using fonts using FreeType 2. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagefttext() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagefttext($image, $size, $angle, $x, $y, $color, $font_filename, $text, $options = array()) { $return_imagefttext = false; // ========== IMAGEFTTEXT - BEGIN // ===== ABOUT // Write text to the image using fonts using FreeType 2 // ===== DESCRIPTION // Note: Prior to PHP 8.0.0, imagefttext() was an extended variant of imagettftext() which additionally supported the options. As of PHP 8.0.0, imagettftext() is an alias of imagefttext(). // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagefttext( // GdImage $image, // float $size, // float $angle, // int $x, // int $y, // int $color, // string $font_filename, // string $text, // array $options = [] // ): array|false // ===== CODE $return_imagefttext = imagefttext( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $size, // float size - The font size to use in points. $angle, // float angle - The angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text. $x, // int x - The coordinates given by x and y will define the basepoint of the first character (roughly the lower-left corner of the character). This is different from the imagestring(), where x and y define the upper-left corner of the first character. For example, "top left" is 0, 0. $y, // int y - The y-ordinate. This sets the position of the fonts baseline, not the very bottom of the character. $color, // int color - The index of the desired color for the text, see imagecolorexact(). $font_filename, // string font_filename - The path to the TrueType font you wish to use. // Depending on which version of the GD library PHP is using, when font_filename does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path. // In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems. // [php] // // Set the environment variable for GD // putenv('GDFONTPATH=' . realpath('.')); // // // Name the font to be used (note the lack of the .ttf extension) // $font = 'SomeFont'; // [/php] $text, // string text - Text to be inserted into image. $options // options - Possible array indexes for options // Key (Type) - Meaning // linespacing (float) - Defines drawing linespacing ); // Return Values // This function returns an array defining the four points of the box, starting in the lower left and moving counter-clockwise: // 0 - lower left x-coordinate // 1 - lower left y-coordinate // 2 - lower right x-coordinate // 3 - lower right y-coordinate // 4 - upper right x-coordinate // 5 - upper right y-coordinate // 6 - upper left x-coordinate // 7 - upper left y-coordinate // On failure, false is returned. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagefttext() example // [php] // // Create a 300x100 image // $im = imagecreatetruecolor(300, 100); // $red = imagecolorallocate($im, 0xFF, 0x00, 0x00); // $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // // // Make the background red // imagefilledrectangle($im, 0, 0, 299, 99, $red); // // // Path to our ttf font file // $font_file = './arial.ttf'; // // // Draw the text 'PHP Manual' using font size 13 // imagefttext($im, 13, 0, 105, 55, $black, $font_file, 'PHP Manual'); // // // Output image to the browser // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR) // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagefttext.php // ========== IMAGEFTTEXT - END // SYNTAX: // array|false imagefttext(GdImage $image, float $size, float $angle, int $x, int $y, int $color, string $font_filename, string $text, array $options = array()) return $return_imagefttext; // array|false } // ============================== END // PHP_IMAGE_GD_IMAGEFTTEXT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGAMMACORRECT // ============================== PUBLIC // ============================== ABOUT // Apply a gamma correction to a GD image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegammacorrect() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagegammacorrect($image, $input_gamma, $output_gamma) { $return_imagegammacorrect = false; // ========== IMAGEGAMMACORRECT - BEGIN // ===== ABOUT // Apply a gamma correction to a GD image // ===== DESCRIPTION // Applies gamma correction to the given gd image given an input and an output gamma. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagegammacorrect(GdImage $image, float $input_gamma, float $output_gamma): bool // ===== CODE $return_imagegammacorrect = imagegammacorrect( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $input_gamma, // float input_gamma - The input gamma. $output_gamma // float output_gamma - The output gamma. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagegammacorrect() usage // [php] // // Create image instance // $im = imagecreatefromgif('php.gif'); // // // Correct gamma, out = 1.537 // imagegammacorrect($im, 1.0, 1.537); // // // Save and free image // imagegif($im, './php_gamma_corrected.gif'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagegammacorrect.php // ========== IMAGEGAMMACORRECT - END // SYNTAX: // bool imagegammacorrect(GdImage $image, float $input_gamma, float $output_gamma) return $return_imagegammacorrect; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEGAMMACORRECT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGD2 // ============================== PUBLIC // ============================== ABOUT // Output GD2 image to browser or file. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegd2() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== USING CONSTANTS (1) // IMG_GD2_RAW - imagegd2() // ============================== CODE function php_image_gd_imagegd2($image, $file = null, $chunk_size = 128, $mode = IMG_GD2_RAW) { $return_imagegd2 = false; // ========== IMAGEGD2 - BEGIN // ===== ABOUT // Output GD2 image to browser or file // ===== DESCRIPTION // Outputs a GD2 image to the given file. // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagegd2( // GdImage $image, // ?string $file = null, // int $chunk_size = 128, // int $mode = IMG_GD2_RAW // ): bool // ===== CODE $return_imagegd2 = imagegd2( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // ?string file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. $chunk_size, // int chunk_size - Chunk size. $mode // int mode - Either IMG_GD2_RAW or IMG_GD2_COMPRESSED. Default is IMG_GD2_RAW. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.3 - file is now nullable. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Outputting a GD2 image // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // // // Output the image // imagegd2($im); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Saving a GD2 image // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // // // Save the gd2 image // // The file format for GD2 images is .gd2, see http://www.libgd.org/GdFileFormats // imagegd2($im, 'simple.gd2'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: The GD2 format is commonly used to allow fast loading of parts of images. Note that the GD2 format is only usable in GD2-compatible applications. // Warning: The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagegd2.php // ========== IMAGEGD2 - END // SYNTAX: // bool imagegd2(GdImage $image, string $file = null, int $chunk_size = 128, int $mode = IMG_GD2_RAW) return $return_imagegd2; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEGD2 // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGD // ============================== PUBLIC // ============================== ABOUT // Output GD image to browser or file. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegd() - PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagegd($image, $file = null) { $return_imagegd = false; // ========== IMAGEGD - BEGIN // ===== ABOUT // Output GD image to browser or file // ===== DESCRIPTION // Outputs a GD image to the given file. // ===== SUPPORTED // PHP_4 >= PHP_4_0_7, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagegd(GdImage $image, ?string $file = null): bool // ===== CODE $return_imagegd = imagegd( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file // ?string file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.3 - file is now nullable. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 7.2.0 - imagegd() now allows to output truecolor images. Formerly, these have been implicitly converted to palette. // // [examples] // Examples // [example] // Example #1 Outputting a GD image // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // // // Output the image // imagegd($im); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Saving a GD image // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // // // Save the gd image // // The file format for GD images is .gd, see http://www.libgd.org/GdFileFormats // imagegd($im, 'simple.gd'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: The GD format is commonly used to allow fast loading of parts of images. Note that the GD format is only usable in GD-compatible applications. // Warning: The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagegd.php // ========== IMAGEGD - END // SYNTAX: // bool imagegd(GdImage $image, string $file = null) return $return_imagegd; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEGD // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGETCLIP // ============================== OFFLINE // ============================== ABOUT // Get the clipping rectangle. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegetclip() - PHP_7 >= PHP_7_2_0, PHP_8 // ============================== CODE /* function php_image_gd_imagegetclip($image) { $return_imagegetclip = null; // ========== IMAGEGETCLIP - BEGIN // ===== ABOUT // Get the clipping rectangle // ===== DESCRIPTION // imagegetclip() retrieves the current clipping rectangle, i.e. the area beyond which no pixels will be drawn. // ===== SUPPORTED // PHP_7 >= PHP_7_2_0, PHP_8 // ===== SYNTAX // imagegetclip(GdImage $image): array // ===== CODE $return_imagegetclip = imagegetclip( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // The function returns an indexed array with the coordinates of the clipping rectangle which has the following entries: // * x-coordinate of the upper left corner // * y-coordinate of the upper left corner // * x-coordinate of the lower right corner // * y-coordinate of the lower right corner // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagegetclip() example // Setting and retrieving the clipping rectangle. // [php] // $im = imagecreate(100, 100); // imagesetclip($im, 10,10, 89,89); // print_r(imagegetclip($im)); // [/php] // The above example will output: // [result] // Array // ( // [0] => 10 // [1] => 10 // [2] => 89 // [3] => 89 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagegetclip.php // ========== IMAGEGETCLIP - END // SYNTAX: // array imagegetclip(GdImage $image) return $return_imagegetclip; // array } */ // ============================== END // PHP_IMAGE_GD_IMAGEGETCLIP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGETINTERPOLATION // ============================== OFFLINE // ============================== ABOUT // Get the interpolation method. // ============================== SUPPORT // PHP_8 // ============================== USING FUNCTIONS (1) // imagegetinterpolation() - PHP_8 // ============================== CODE /* function php_image_gd_imagegetinterpolation($image) { $return_imagegetinterpolation = 0; // ========== IMAGEGETINTERPOLATION - BEGIN // ===== ABOUT // Get the interpolation method // ===== DESCRIPTION // Gets the currently set interpolation method of the image. // ===== SUPPORTED // PHP_8 // ===== SYNTAX // imagegetinterpolation(GdImage $image): int // ===== CODE $return_imagegetinterpolation = imagegetinterpolation( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Returns the interpolation method. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // ===== LITERATURE_SOURCES // * PHP_NET (2023-09-11) // URL: https://www.php.net/manual/en/function.imagegetinterpolation.php // ========== IMAGEGETINTERPOLATION - END // SYNTAX: // int imagegetinterpolation(GdImage $image) return $return_imagegetinterpolation; // int } */ // ============================== END // PHP_IMAGE_GD_IMAGEGETINTERPOLATION // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGIF // ============================== PUBLIC // ============================== ABOUT // Output image to browser or file. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegif() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagegif($image, $file = null) { $return_imagegif = false; // ========== IMAGEGIF - BEGIN // ===== ABOUT // Output image to browser or file // ===== DESCRIPTION // imagegif() creates the GIF file in file from the image image. The image argument is the return from the imagecreate() or imagecreatefrom* function. // The image format will be GIF87a unless the image has been made transparent with imagecolortransparent(), in which case the image format will be GIF89a. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagegif(GdImage $image, resource|string|null $file = null): bool // ===== CODE $return_imagegif = imagegif( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Outputting an image using imagegif() // [php] // // Create a new image instance // $im = imagecreatetruecolor(100, 100); // // // Make the background white // imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF); // // // Draw a text string on the image // imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00); // // // Output the image to browser // header('Content-Type: image/gif'); // // imagegif($im); // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Converting a PNG image to GIF using imagegif() // [php] // // // Load the PNG // $png = imagecreatefrompng('./php.png'); // // // Save the image as a GIF // imagegif($png, './php.gif'); // // // Free from memory // imagedestroy($png); // // // We're done // echo 'Converted PNG image to GIF with success!'; // [/php] // [/example] // [/examples] // // Notes // Note: The following code snippet allows you to write more portable PHP applications by auto-detecting the type of GD support which is available. Replace the sequence header ("Content-Type: image/gif"); imagegif ($im); by the more flexible sequence: // [php] // // Create a new image instance // $im = imagecreatetruecolor(100, 100); // // // Do some image operations here // // // Handle output // if(function_exists('imagegif')) // { // // For GIF // header('Content-Type: image/gif'); // // imagegif($im); // } // elseif(function_exists('imagejpeg')) // { // // For JPEG // header('Content-Type: image/jpeg'); // // imagejpeg($im, NULL, 100); // } // elseif(function_exists('imagepng')) // { // // For PNG // header('Content-Type: image/png'); // // imagepng($im); // } // elseif(function_exists('imagewbmp')) // { // // For WBMP // header('Content-Type: image/vnd.wap.wbmp'); // // imagewbmp($im); // } // else // { // imagedestroy($im); // // die('No image support in this PHP server'); // } // // // If image support was found for one of these // // formats, then free it from memory // if($im) // { // imagedestroy($im); // } // [/php] // Note: You can use the function imagetypes() for checking the presence of the various supported image formats: // [php] // if(imagetypes() & IMG_GIF) // { // header('Content-Type: image/gif'); // imagegif($im); // } // elseif(imagetypes() & IMG_JPG) // { // // ... etc. // } // [/php] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagegif.php // ========== IMAGEGIF - END // SYNTAX: // bool imagegif(GdImage $image, resource|string|null $file = null) return $return_imagegif; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEGIF // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGRABSCREEN // ============================== OFFLINE // ============================== ABOUT // Captures the whole screen. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegrabscreen() - PHP_5 >= PHP_5_2_2, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagegrabscreen() { $return_imagegrabscreen = false; // ========== IMAGEGRABSCREEN - BEGIN // ===== ABOUT // Captures the whole screen // ===== DESCRIPTION // Grabs a screenshot of the whole screen. // Note: This function is only available on Windows. // ===== SUPPORTED // PHP_5 >= PHP_5_2_2, PHP_7, PHP_8 // ===== SYNTAX // imagegrabscreen(): GdImage|false // ===== CODE $return_imagegrabscreen = imagegrabscreen( // This function has no parameters. ); // Return Values // Returns an image object on success, false on failure. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // // [examples] // Examples // [example] // Example #1 imagegrabscreen() example // This example demonstrates how to take a screenshot of the current screen and save it as a png image. // [php] // $im = imagegrabscreen(); // imagepng($im, "myscreenshot.png"); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagegrabscreen.php // ========== IMAGEGRABSCREEN - END // SYNTAX: // GdImage|false imagegrabscreen() return $return_imagegrabscreen; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGEGRABSCREEN // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEGRABWINDOW // ============================== OFFLINE // ============================== ABOUT // Captures a window. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagegrabwindow() - PHP_5 >= PHP_5_2_2, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagegrabwindow($handle, $client_area = false) { $return_imagegrabwindow = false; // ========== IMAGEGRABWINDOW - BEGIN // ===== ABOUT // Captures a window // ===== DESCRIPTION // Grabs a window or its client area using a windows handle (HWND property in COM instance) // Note: This function is only available on Windows. // ===== SUPPORTED // PHP_5 >= PHP_5_2_2, PHP_7, PHP_8 // ===== SYNTAX // imagegrabwindow(int $handle, bool $client_area = false): GdImage|false // ===== CODE $return_imagegrabwindow = imagegrabwindow( $handle, // int handle - The HWND window ID. $client_area // bool client_area - Include the client area of the application window. ); // Return Values // Returns an image object on success, false on failure. // // Errors/Exceptions // E_NOTICE is issued if handle is invalid window handle. E_WARNING is issued if the Windows API is too old. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // 8.0.0 - client_area expects a bool now; previously it expected an int. // // [examples] // Examples // [example] // Example #1 imagegrabwindow() example // Capture a window (IE for example) // [php] // $browser = new COM("InternetExplorer.Application"); // $handle = $browser->HWND; // $browser->Visible = true; // $im = imagegrabwindow($handle); // $browser->Quit(); // imagepng($im, "iesnap.png"); // imagedestroy($im); // [/php] // Capture a window (IE for example) but with its content // [php] // $browser = new COM("InternetExplorer.Application"); // $handle = $browser->HWND; // $browser->Visible = true; // $browser->Navigate("http://www.libgd.org"); // // // Still working? // while ($browser->Busy) { // com_message_pump(4000); // } // $im = imagegrabwindow($handle, 0); // $browser->Quit(); // imagepng($im, "iesnap.png"); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagegrabwindow.php // ========== IMAGEGRABWINDOW - END // SYNTAX: // GdImage|false imagegrabwindow(int $handle, bool $client_area = false) return $return_imagegrabwindow; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGEGRABWINDOW // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEINTERLACE // ============================== PUBLIC // ============================== ABOUT // Enable or disable interlace. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageinterlace() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageinterlace($image, $enable = null) { $return_imageinterlace = false; // ========== IMAGEINTERLACE - BEGIN // ===== ABOUT // Enable or disable interlace // ===== DESCRIPTION // imageinterlace() turns the interlace bit on or off. // If the interlace bit is set and the image is used as a JPEG image, the image is created as a progressive JPEG. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageinterlace(GdImage $image, ?bool $enable = null): bool // ===== CODE $return_imageinterlace = imageinterlace( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $enable // bool interlace - If true, the image will be interlaced, if false the interlace bit is turned off. Passing null will result in the interlacing behavior not being changed. ); // Return Values // Returns true if the interlace bit is set for the image, false otherwise. // // Changelog // Version - Description // 8.0.5 - imageinterlace() returns a bool now; previously it returned an int (non-zero for interlaced images, zero otherwise). // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - enable expects a bool now; previously it expected an int. // // [examples] // Examples // [example] // Example #1 Turn on interlacing using imageinterlace() // [php] // // Create an image instance // $im = imagecreatefromgif('php.gif'); // // // Enable interlancing // imageinterlace($im, true); // // // Save the interlaced image // imagegif($im, './php_interlaced.gif'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imageinterlace.php // ========== IMAGEINTERLACE - END // SYNTAX: // bool imageinterlace(GdImage $image, bool $enable = null) return $return_imageinterlace; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEINTERLACE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEISTRUECOLOR // ============================== PUBLIC // ============================== ABOUT // Finds whether an image is a truecolor image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageistruecolor() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageistruecolor($image) { $return_imageistruecolor = false; // ========== IMAGEISTRUECOLOR - BEGIN // ===== ABOUT // Finds whether an image is a truecolor image // ===== DESCRIPTION // imageistruecolor() finds whether the image image is a truecolor image. // ===== SUPPORTED // PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageistruecolor(GdImage $image): bool // ===== CODE $return_imageistruecolor = imageistruecolor( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Returns true if the image is truecolor, false otherwise. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Simple detection of true color image instances using imageistruecolor() // [php] // // $im is an image instance // // // Check if image is a true color image or not // if(!imageistruecolor($im)) // { // // Create a new true color image instance // $tc = imagecreatetruecolor(imagesx($im), imagesy($im)); // // // Copy over the pixels // imagecopy($tc, $im, 0, 0, 0, 0, imagesx($im), imagesy($im)); // imagedestroy($im); // // $im = $tc; // $tc = NULL; // // // OR use imagepalettetotruecolor() // } // // // Continue working with image instance // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imageistruecolor.php // ========== IMAGEISTRUECOLOR - END // SYNTAX: // bool imageistruecolor(GdImage $image) return $return_imageistruecolor; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEISTRUECOLOR // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEJPEG // ============================== PUBLIC // ============================== ABOUT // Output image to browser or file. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagejpeg() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagejpeg($image, $file = null, $quality = -1) { $return_imagejpeg = false; // ========== IMAGEJPEG - BEGIN // ===== ABOUT // Output image to browser or file // ===== DESCRIPTION // imagejpeg() creates a JPEG file from the given image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagejpeg(GdImage $image, resource|string|null $file = null, int $quality = -1): bool // ===== CODE $return_imagejpeg = imagejpeg( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. $quality // int quality - quality is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default (-1) uses the default IJG quality value (about 75). ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Outputting a JPEG image to the browser // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Set the content type header - in this case image/jpeg // header('Content-Type: image/jpeg'); // // // Output the image // imagejpeg($im); // // // Free up memory // imagedestroy($im); // [/php] // The above example will output something similar to: // [result] // Output of example : Outputting a JPEG image // [/result] // [/example] // [example] // Example #2 Saving a JPEG image to a file // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Save the image as 'simpletext.jpg' // imagejpeg($im, 'simpletext.jpg'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [example] // Example #3 Outputting the image at 75% quality to the browser // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Set the content type header - in this case image/jpeg // header('Content-Type: image/jpeg'); // // // Skip the file parameter using NULL, then set the quality to 75% // imagejpeg($im, NULL, 75); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: If you want to output Progressive JPEGs, you need to set interlacing on with imageinterlace(). // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagejpeg.php // ========== IMAGEJPEG - END // SYNTAX: // bool imagejpeg(GdImage $image, resource|string|null $file = null, int $quality = -1) return $return_imagejpeg; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEJPEG // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGELAYEREFFECT // ============================== PUBLIC // ============================== ABOUT // Set the alpha blending flag to use layering effects. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagelayereffect() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagelayereffect($image, $effect) { $return_imagelayereffect = false; // ========== IMAGELAYEREFFECT - BEGIN // ===== ABOUT // Set the alpha blending flag to use layering effects // ===== DESCRIPTION // Set the alpha blending flag to use layering effects. // ===== SUPPORTED // PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagelayereffect(GdImage $image, int $effect): bool // ===== CODE $return_imagelayereffect = imagelayereffect( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $effect // int effect - One of the following constants: // IMG_EFFECT_REPLACE - Use pixel replacement (equivalent of passing true to imagealphablending()) // IMG_EFFECT_ALPHABLEND - Use normal pixel blending (equivalent of passing false to imagealphablending()) // IMG_EFFECT_NORMAL - Same as IMG_EFFECT_ALPHABLEND. // IMG_EFFECT_OVERLAY - Overlay has the effect that black background pixels will remain black, white background pixels will remain white, but grey background pixels will take the colour of the foreground pixel. // IMG_EFFECT_MULTIPLY - Overlays with a multiply effect. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 7.2.0 - Added IMG_EFFECT_MULTIPLY (requires system libgd >= 2.1.1 or the bundled libgd). // // [examples] // Examples // [example] // Example #1 imagelayereffect() example // [php] // // Setup an image // $im = imagecreatetruecolor(100, 100); // // // Set a background // imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 220, 220, 220)); // // // Apply the overlay alpha blending flag // imagelayereffect($im, IMG_EFFECT_OVERLAY); // // // Draw two grey ellipses // imagefilledellipse($im, 50, 50, 40, 40, imagecolorallocate($im, 100, 255, 100)); // imagefilledellipse($im, 50, 50, 50, 80, imagecolorallocate($im, 100, 100, 255)); // imagefilledellipse($im, 50, 50, 80, 50, imagecolorallocate($im, 255, 100, 100)); // // // Output // header('Content-type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagelayereffect.php // ========== IMAGELAYEREFFECT - END // SYNTAX: // bool imagelayereffect(GdImage $image, int $effect) return $return_imagelayereffect; // bool } // ============================== END // PHP_IMAGE_GD_IMAGELAYEREFFECT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGELINE // ============================== PUBLIC // ============================== ABOUT // Draw a line. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageline() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageline($image, $x1, $y1, $x2, $y2, $color) { $return_imageline = false; // ========== IMAGELINE - BEGIN // ===== ABOUT // Draw a line // ===== DESCRIPTION // Draws a line between the two given points. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageline( // GdImage $image, // int $x1, // int $y1, // int $x2, // int $y2, // int $color // ): bool // ===== CODE $return_imageline = imageline( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x1, // int x1 - x-coordinate for first point. $y1, // int y1 - y-coordinate for first point. $x2, // int x2 - x-coordinate for second point. $y2, // int y2 - y-coordinate for second point. $color // int color - The line color. A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Drawing a thick line // [php] // // function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1) // { // // this way it works well only for orthogonal lines // // imagesetthickness($image, $thick); // // return imageline($image, $x1, $y1, $x2, $y2, $color); // // if ($thick == 1) { // return imageline($image, $x1, $y1, $x2, $y2, $color); // } // $t = $thick / 2 - 0.5; // if ($x1 == $x2 || $y1 == $y2) { // return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color); // } // $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q // $a = $t / sqrt(1 + pow($k, 2)); // $points = array( // round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a), // round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a), // round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a), // round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a), // ); // imagefilledpolygon($image, $points, 4, $color); // return imagepolygon($image, $points, 4, $color); // } // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imageline.php // ========== IMAGELINE - END // SYNTAX: // bool imageline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color) return $return_imageline; // bool } // ============================== END // PHP_IMAGE_GD_IMAGELINE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGELOADFONT // ============================== PUBLIC // ============================== ABOUT // Load a new font. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imageloadfont() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imageloadfont($filename) { $return_imageloadfont = false; // ========== IMAGELOADFONT - BEGIN // ===== ABOUT // Load a new font // ===== DESCRIPTION // imageloadfont() loads a user-defined bitmap and returns its identifier. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imageloadfont(string $filename): GdFont|false // ===== CODE $return_imageloadfont = imageloadfont( $filename // string filename - The font file format is currently binary and architecture dependent. This means you should generate the font files on the same type of CPU as the machine you are running PHP on. // // Font file format // byte position (C data type) - description // byte 0-3 (int) - number of characters in the font // byte 4-7 (int) - value of first character in the font (often 32 for space) // byte 8-11 (int) - pixel width of each character // byte 12-15 (int) - pixel height of each character // byte 16- (char) - array with character data, one byte per pixel in each character, for a total of (nchars*width*height) bytes. ); // Return Values // Returns an GdFont instance, or false on failure. // // Changelog // Version - Description // 8.1.0 - Returns an GdFont instance now; previously, an int was returned. // // [examples] // Examples // [example] // Example #1 imageloadfont() usage example // [php] // // Create a new image instance // $im = imagecreatetruecolor(50, 20); // $black = imagecolorallocate($im, 0, 0, 0); // $white = imagecolorallocate($im, 255, 255, 255); // // // Make the background white // imagefilledrectangle($im, 0, 0, 49, 19, $white); // // // Load the gd font and write 'Hello' // $font = imageloadfont('./04b.gdf'); // imagestring($im, $font, 0, 0, 'Hello', $black); // // // Output to browser // header('Content-type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imageloadfont.php // ========== IMAGELOADFONT - END // SYNTAX: // GdFont|false imageloadfont(string $filename) return $return_imageloadfont; // GdFont|false } // ============================== END // PHP_IMAGE_GD_IMAGELOADFONT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEOPENPOLYGON // ============================== OFFLINE // ============================== ABOUT // Draws an open polygon. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imageopenpolygon() - PHP_7 >= PHP_7_2_0, PHP_8 // ============================== CODE /* function php_image_gd_imageopenpolygon($image, $points, $num_points, $color) { $return_imageopenpolygon = false; // ========== IMAGEOPENPOLYGON - BEGIN // ===== ABOUT // Draws an open polygon // ===== DESCRIPTION // imageopenpolygon() draws an open polygon on the given image. Contrary to imagepolygon(), no line is drawn between the last and the first point. // ===== SUPPORTED // PHP_7 >= PHP_7_2_0, PHP_8 // ===== SYNTAX // Signature as of PHP 8.0.0 (not supported with named arguments) // imageopenpolygon(GdImage $image, array $points, int $color): bool // // Alternative signature (deprecated as of PHP 8.1.0) // imageopenpolygon( // GdImage $image, // array $points, // int $num_points, // int $color // ): bool // ===== CODE $return_imageopenpolygon = imageopenpolygon( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $points, // array points - An array containing the polygon's vertices, e.g.: // points[0] = x0 // points[1] = y0 // points[2] = x1 // points[3] = y1 $num_points, // num_points num_points - Total number of points (vertices), which must be at least 3. // If this parameter is omitted as per the second signature, points must have an even number of elements, and num_points is assumed to be count($points)/2. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The parameter num_points has been deprecated. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imageopenpolygon() example // [php] // // Create a blank image // $image = imagecreatetruecolor(400, 300); // // // Allocate a color for the polygon // $col_poly = imagecolorallocate($image, 255, 255, 255); // // // Draw the polygon // imageopenpolygon($image, array( // 0, 0, // 100, 200, // 300, 200 // ), // 3, // $col_poly); // // // Output the picture to the browser // header('Content-type: image/png'); // // imagepng($image); // imagedestroy($image); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imageopenpolygon.php // ========== IMAGEOPENPOLYGON - END // SYNTAX: // bool imageopenpolygon(GdImage $image, array $points, int $num_points, int $color) return $return_imageopenpolygon; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEOPENPOLYGON // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEPALETTECOPY // ============================== PUBLIC // ============================== ABOUT // Copy the palette from one image to another. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagepalettecopy() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagepalettecopy($dst, $src) { // ========== IMAGEPALETTECOPY - BEGIN // ===== ABOUT // Copy the palette from one image to another // ===== DESCRIPTION // imagepalettecopy() copies the palette from the src image to the dst image. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagepalettecopy(GdImage $dst, GdImage $src): void // ===== CODE imagepalettecopy( $dst, // GdImage dst - The destination image object. $src // GdImage src - The source image object. ); // Return Values // No value is returned. // // Changelog // Version - Description // 8.0.0 - dst and src expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 imagepalettecopy() example // [php] // // Create two palette images // $palette1 = imagecreate(100, 100); // $palette2 = imagecreate(100, 100); // // // Allocate the background to be // // green in the first palette image // $green = imagecolorallocate($palette1, 0, 255, 0); // // // Copy the palette from image 1 to image 2 // imagepalettecopy($palette2, $palette1); // // // Since the palette is now copied we can use the // // green color allocated to image 1 without using // // imagecolorallocate() twice // imagefilledrectangle($palette2, 0, 0, 99, 99, $green); // // // Output image to the browser // header('Content-type: image/png'); // // imagepng($palette2); // imagedestroy($palette1); // imagedestroy($palette2); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagepalettecopy.php // ========== IMAGEPALETTECOPY - END // SYNTAX: // void imagepalettecopy(GdImage $dst, GdImage $src) // Return: void } // ============================== END // PHP_IMAGE_GD_IMAGEPALETTECOPY // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEPALETTETOTRUECOLOR // ============================== OFFLINE // ============================== ABOUT // Converts a palette based image to true color. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagepalettetotruecolor() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagepalettetotruecolor($image) { $return_imagepalettetotruecolor = false; // ========== IMAGEPALETTETOTRUECOLOR - BEGIN // ===== ABOUT // Converts a palette based image to true color // ===== DESCRIPTION // Converts a palette based image, created by functions like imagecreate() to a true color image, like imagecreatetruecolor(). // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imagepalettetotruecolor(GdImage $image): bool // ===== CODE $return_imagepalettetotruecolor = imagepalettetotruecolor( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Returns true if the convertion was complete, or if the source image already is a true color image, otherwise false is returned. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Converts any image object to true color // [php] // // Backwards compatiblity // if(!function_exists('imagepalettetotruecolor')) // { // function imagepalettetotruecolor(&$src) // { // if(imageistruecolor($src)) // { // return(true); // } // // $dst = imagecreatetruecolor(imagesx($src), imagesy($src)); // // imagecopy($dst, $src, 0, 0, 0, 0, imagesx($src), imagesy($src)); // imagedestroy($src); // // $src = $dst; // // return(true); // } // } // // // Helper closure // $typeof = function() use($im) // { // echo 'typeof($im) = ' . (imageistruecolor($im) ? 'true color' : 'palette'), PHP_EOL; // }; // // // Create a palette based image // $im = imagecreate(100, 100); // $typeof(); // // // Convert it to true color // imagepalettetotruecolor($im); // $typeof(); // // // Free the memory // imagedestroy($im); // [/php] // The above example will output: // [result] // typeof($im) = palette // typeof($im) = true color // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagepalettetotruecolor.php // ========== IMAGEPALETTETOTRUECOLOR - END // SYNTAX: // bool imagepalettetotruecolor(GdImage $image) return $return_imagepalettetotruecolor; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEPALETTETOTRUECOLOR // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEPNG // ============================== PUBLIC // ============================== ABOUT // Output a PNG image to either the browser or a file. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagepng() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagepng($image, $file = null, $quality = -1, $filters = -1) { $return_imagepng = false; // ========== IMAGEPNG - BEGIN // ===== ABOUT // Output a PNG image to either the browser or a file // ===== DESCRIPTION // Outputs or saves a PNG image from the given image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagepng( // GdImage $image, // resource|string|null $file = null, // int $quality = -1, // int $filters = -1 // ): bool // ===== CODE $return_imagepng = imagepng( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. // Note: null is invalid if the quality and filters arguments are not used. $quality, // int quality - Compression level: from 0 (no compression) to 9. The default (-1) uses the zlib compression default. For more information see the > zlib manual. $filters // int filters - Allows reducing the PNG file size. It is a bitmask field which may be set to any combination of the PNG_FILTER_XXX constants. PNG_NO_FILTER or PNG_ALL_FILTERS may also be used to respectively disable or activate all filters. The default value (-1) disables filtering. // Caution: The filters parameter is ignored by system libgd. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // [php] // $im = imagecreatefrompng("test.png"); // // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagepng.php // ========== IMAGEPNG - END // SYNTAX: // bool imagepng(GdImage $image, resource|string|null $file = null, int $quality = -1, int $filters = -1) return $return_imagepng; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEPNG // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEPOLYGON // ============================== PUBLIC // ============================== ABOUT // Draws a polygon. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagepolygon() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagepolygon($image, $points, $num_points, $color) { $return_imagepolygon = false; // ========== IMAGEPOLYGON - BEGIN // ===== ABOUT // Draws a polygon // ===== DESCRIPTION // imagepolygon() creates a polygon in the given image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // Signature as of PHP 8.0.0 (not supported with named arguments) // imagepolygon(GdImage $image, array $points, int $color): bool // // Alternative signature (deprecated as of PHP 8.1.0) // imagepolygon( // GdImage $image, // array $points, // int $num_points, // int $color // ): bool // ===== CODE $return_imagepolygon = imagepolygon( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $points, // array points - An array containing the polygon's vertices, e.g.: // points[0] = x0 // points[1] = y0 // points[2] = x1 // points[3] = y1 $num_points, // int num_points - Total number of points (vertices), which must be at least 3. // If this parameter is omitted as per the second signature, points must have an even number of elements, and num_points is assumed to be count($points)/2. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The parameter num_points has been deprecated. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagepolygon() example // [php] // // Create a blank image // $image = imagecreatetruecolor(400, 300); // // // Allocate a color for the polygon // $col_poly = imagecolorallocate($image, 255, 255, 255); // // // Draw the polygon // imagepolygon($image, array( // 0, 0, // 100, 200, // 300, 200 // ), // 3, // $col_poly); // // // Output the picture to the browser // header('Content-type: image/png'); // // imagepng($image); // imagedestroy($image); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagepolygon.php // ========== IMAGEPOLYGON - END // SYNTAX: // bool imagepolygon(GdImage $image, array $points, int $num_points, int $color) return $return_imagepolygon; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEPOLYGON // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGERECTANGLE // ============================== PUBLIC // ============================== ABOUT // Draw a rectangle. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagerectangle() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagerectangle($image, $x1, $y1, $x2, $y2, $color) { $return_imagerectangle = false; // ========== IMAGERECTANGLE - BEGIN // ===== ABOUT // Draw a rectangle // ===== DESCRIPTION // imagerectangle() creates a rectangle starting at the specified coordinates. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagerectangle( // GdImage $image, // int $x1, // int $y1, // int $x2, // int $y2, // int $color // ): bool // ===== CODE $return_imagerectangle = imagerectangle( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x1, // int x1 - Upper left x coordinate. $y1, // int y1 - Upper left y coordinate 0, 0 is the top left corner of the image. $x2, // int x2 - Bottom right x coordinate. $y2, // int y2 - Bottom right y coordinate. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Simple imagerectangle() example // [php] // // Create a 200 x 200 image // $canvas = imagecreatetruecolor(200, 200); // // // Allocate colors // $pink = imagecolorallocate($canvas, 255, 105, 180); // $white = imagecolorallocate($canvas, 255, 255, 255); // $green = imagecolorallocate($canvas, 132, 135, 28); // // // Draw three rectangles each with its own color // imagerectangle($canvas, 50, 50, 150, 150, $pink); // imagerectangle($canvas, 45, 60, 120, 100, $white); // imagerectangle($canvas, 100, 120, 75, 160, $green); // // // Output and free from memory // header('Content-Type: image/jpeg'); // // imagejpeg($canvas); // imagedestroy($canvas); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagerectangle.php // ========== IMAGERECTANGLE - END // SYNTAX: // bool imagerectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color) return $return_imagerectangle; // bool } // ============================== END // PHP_IMAGE_GD_IMAGERECTANGLE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGERESOLUTION // ============================== OFFLINE // ============================== ABOUT // Get or set the resolution of the image. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imageresolution() - PHP_7 >= PHP_7_2_0, PHP_8 // ============================== CODE /* function php_image_gd_imageresolution($image, $resolution_x = null, $resolution_y = null) { $return_imageresolution = false; // ========== IMAGERESOLUTION - BEGIN // ===== ABOUT // Get or set the resolution of the image // ===== DESCRIPTION // imageresolution() allows to set and get the resolution of an image in DPI (dots per inch). If the optional parameters are null, the current resolution is returned as an indexed array. If only resolution_x is not null, the horizontal and vertical resolution are set to this value. If none of the optional parameters are null, the horizontal and vertical resolution are set to these values, respectively. // The resolution is only used as meta information when images are read from and written to formats supporting this kind of information (curently PNG and JPEG). It does not affect any drawing operations. The default resolution for new images is 96 DPI. // ===== SUPPORTED // PHP_7 >= PHP_7_2_0, PHP_8 // ===== SYNTAX // imageresolution(GdImage $image, ?int $resolution_x = null, ?int $resolution_y = null): array|bool // ===== CODE $return_imageresolution = imageresolution( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $resolution_x, // int resolution_x - The horizontal resolution in DPI. $resolution_y // int resolution_y - The vertical resolution in DPI. ); // Return Values // When used as getter, it returns an indexed array of the horizontal and vertical resolution on success, or false on failure. When used as setter, it returns true on success, or false on failure. // // Changelog // Version - Description // 8.0.0 - resolution_x and resolution_y are now nullable. // // [examples] // Examples // [example] // Example #1 Setting and getting the resolution of an image // [php] // $im = imagecreatetruecolor(100, 100); // imageresolution($im, 200); // print_r(imageresolution($im)); // imageresolution($im, 300, 72); // print_r(imageresolution($im)); // [/php] // The above example will output: // [result] // Array // ( // [0] => 200 // [1] => 200 // ) // Array // ( // [0] => 300 // [1] => 72 // ) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imageresolution.php // ========== IMAGERESOLUTION - END // SYNTAX: // array|bool imageresolution(GdImage $image, int $resolution_x = null, int $resolution_y = null) return $return_imageresolution; // array|bool } */ // ============================== END // PHP_IMAGE_GD_IMAGERESOLUTION // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEROTATE // ============================== PUBLIC // ============================== ABOUT // Rotate an image with a given angle. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagerotate() - PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagerotate($image, $angle, $background_color) { $return_imagerotate = false; // ========== IMAGEROTATE - BEGIN // ===== ABOUT // Rotate an image with a given angle // ===== DESCRIPTION // Rotates the image image using the given angle in degrees. // The center of rotation is the center of the image, and the rotated image may have different dimensions than the original image. // ===== SUPPORTED // PHP_4 >= PHP_4_3_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagerotate(GdImage $image, float $angle, int $background_color): GdImage|false // ===== CODE $return_imagerotate = imagerotate( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $angle, // float angle - Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image anticlockwise. $background_color // int background_color - Specifies the color of the uncovered zone after the rotation ); // Return Values // Returns an image object for the rotated image, or false on failure. // // Changelog // Version - Description // 8.3.0 - The unused ignore_transparent has been completely removed. // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - The unused ignore_transparent expects a bool now; previously it expected an int. // // [examples] // Examples // [example] // Example #1 Rotate an image 180 degrees // This example rotates an image 180 degrees - upside down. // [php] // // File and rotation // $filename = 'test.jpg'; // $degrees = 180; // // // Content type // header('Content-type: image/jpeg'); // // // Load // $source = imagecreatefromjpeg($filename); // // // Rotate // $rotate = imagerotate($source, $degrees, 0); // // // Output // imagejpeg($rotate); // // // Free the memory // imagedestroy($source); // imagedestroy($rotate); // [/php] // [/example] // [/examples] // // Notes // Note: This function is affected by the interpolation method set by imagesetinterpolation(). // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagerotate.php // ========== IMAGEROTATE - END // SYNTAX: // GdImage|false imagerotate(GdImage $image, float $angle, int $background_color) return $return_imagerotate; // GdImage|false } // ============================== END // PHP_IMAGE_GD_IMAGEROTATE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESAVEALPHA // ============================== PUBLIC // ============================== ABOUT // Whether to retain full alpha channel information when saving images. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesavealpha() - PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesavealpha($image, $enable) { $return_imagesavealpha = false; // ========== IMAGESAVEALPHA - BEGIN // ===== ABOUT // Whether to retain full alpha channel information when saving images // ===== DESCRIPTION // imagesavealpha() sets the flag which determines whether to retain full alpha channel information (as opposed to single-color transparency) when saving images. This is only supported for image formats which support full alpha channel information, i.e. PNG, WebP and AVIF. // Note: imagesavealpha() is only meaningful for PNG images, since the full alpha channel is always saved for WebP and AVIF. It is not recommended to rely on this behavior, as it may change in the future. Thus, imagesavealpha() should be called deliberately also for WebP and AVIF images. // Alphablending has to be disabled (imagealphablending($im, false)) to retain the alpha-channel in the first place. // ===== SUPPORTED // PHP_4 >= PHP_4_3_2, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesavealpha(GdImage $image, bool $enable): bool // ===== CODE $return_imagesavealpha = imagesavealpha( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $enable // bool enable - Whether to save the alpha channel or not. Defaults to false. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Basic imagesavealpha() Usage // [php] // // Load a png image with alpha channel // $png = imagecreatefrompng('./alphachannel_example.png'); // // // Turn off alpha blending // imagealphablending($png, false); // // // Do desired operations // // // Set alpha flag // imagesavealpha($png, true); // // // Output image to browser // header('Content-Type: image/png'); // // imagepng($png); // imagedestroy($png); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagesavealpha.php // ========== IMAGESAVEALPHA - END // SYNTAX: // bool imagesavealpha(GdImage $image, bool $enable) return $return_imagesavealpha; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESAVEALPHA // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESCALE // ============================== OFFLINE // ============================== ABOUT // Scale an image using the given new width and height. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagescale() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== USING CONSTANTS (1) // IMG_BILINEAR_FIXED - imagescale() // ============================== CODE /* function php_image_gd_imagescale($image, $width, $height = -1, $mode = IMG_BILINEAR_FIXED) { $return_imagescale = false; // ========== IMAGESCALE - BEGIN // ===== ABOUT // Scale an image using the given new width and height // ===== DESCRIPTION // imagescale() scales an image using the given interpolation algorithm. // Note: Unlike many of other image functions, imagescale() does not modify the passed image; instead, a new image is returned. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imagescale( // GdImage $image, // int $width, // int $height = -1, // int $mode = IMG_BILINEAR_FIXED // ): GdImage|false // ===== CODE $return_imagescale = imagescale( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $width, // int width - The width to scale the image to. $height, // int height - The height to scale the image to. If omitted or negative, the aspect ratio will be preserved. $mode // int mode - One of IMG_NEAREST_NEIGHBOUR, IMG_BILINEAR_FIXED, IMG_BICUBIC, IMG_BICUBIC_FIXED or anything else (will use two pass). // Note: IMG_WEIGHTED4 is not yet supported. ); // Return Values // Return the scaled image object on success or false on failure. // // Changelog // Version - Description // 8.0.0 - On success, this function returns a GDImage instance now; previously, a resource was returned. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagescale.php // ========== IMAGESCALE - END // SYNTAX: // GdImage|false imagescale(GdImage $image, int $width, int $height = -1, int $mode = IMG_BILINEAR_FIXED) return $return_imagescale; // GdImage|false } */ // ============================== END // PHP_IMAGE_GD_IMAGESCALE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETBRUSH // ============================== PUBLIC // ============================== ABOUT // Set the brush image for line drawing. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesetbrush() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesetbrush($image, $brush) { $return_imagesetbrush = false; // ========== IMAGESETBRUSH - BEGIN // ===== ABOUT // Set the brush image for line drawing // ===== DESCRIPTION // imagesetbrush() sets the brush image to be used by all line drawing functions (such as imageline() and imagepolygon()) when drawing with the special colors IMG_COLOR_BRUSHED or IMG_COLOR_STYLEDBRUSHED. // Caution: You need not take special action when you are finished with a brush, but if you destroy the brush image (or let PHP destroy it), you must not use the IMG_COLOR_BRUSHED or IMG_COLOR_STYLEDBRUSHED colors until you have set a new brush image! // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesetbrush(GdImage $image, GdImage $brush): bool // ===== CODE $return_imagesetbrush = imagesetbrush( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $brush // GdImage brush - An image object. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image and brush expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 imagesetbrush() example // [php] // // Load a mini php logo // $php = imagecreatefrompng('./php.png'); // // // Create the main image, 100x100 // $im = imagecreatetruecolor(100, 100); // // // Fill the background with white // $white = imagecolorallocate($im, 255, 255, 255); // imagefilledrectangle($im, 0, 0, 299, 99, $white); // // // Set the brush // imagesetbrush($im, $php); // // // Draw a couple of brushes, each overlaying each // imageline($im, 50, 50, 50, 60, IMG_COLOR_BRUSHED); // // // Output image to the browser // header('Content-type: image/png'); // // imagepng($im); // imagedestroy($im); // imagedestroy($php); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagesetbrush.php // ========== IMAGESETBRUSH - END // SYNTAX: // bool imagesetbrush(GdImage $image, GdImage $brush) return $return_imagesetbrush; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESETBRUSH // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETCLIP // ============================== OFFLINE // ============================== ABOUT // Set the clipping rectangle. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesetclip() - PHP_7 >= PHP_7_2_0, PHP_8 // ============================== CODE /* function php_image_gd_imagesetclip($image, $x1, $y1, $x2, $y2) { $return_imagesetclip = false; // ========== IMAGESETCLIP - BEGIN // ===== ABOUT // Set the clipping rectangle // ===== DESCRIPTION // imagesetclip() sets the current clipping rectangle, i.e. the area beyond which no pixels will be drawn. // ===== SUPPORTED // PHP_7 >= PHP_7_2_0, PHP_8 // ===== SYNTAX // imagesetclip( // GdImage $image, // int $x1, // int $y1, // int $x2, // int $y2 // ): bool // ===== CODE $return_imagesetclip = imagesetclip( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x1, // int x1 - The x-coordinate of the upper left corner. $y1, // int y1 - The y-coordinate of the upper left corner. $x2, // int x2 - The x-coordinate of the lower right corner. $y2 // int y2 - The y-coordinate of the lower right corner. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // ===== LITERATURE_SOURCES // * PHP_NET (2023-09-11) // URL: https://www.php.net/manual/en/function.imagesetclip.php // ========== IMAGESETCLIP - END // SYNTAX: // bool imagesetclip(GdImage $image, int $x1, int $y1, int $x2, int $y2) return $return_imagesetclip; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGESETCLIP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETINTERPOLATION // ============================== OFFLINE // ============================== ABOUT // Set the interpolation method. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesetinterpolation() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== USING CONSTANTS (1) // IMG_BILINEAR_FIXED - imagesetinterpolation() // ============================== CODE /* function php_image_gd_imagesetinterpolation($image, $method = IMG_BILINEAR_FIXED) { $return_imagesetinterpolation = false; // ========== IMAGESETINTERPOLATION - BEGIN // ===== ABOUT // Set the interpolation method // ===== DESCRIPTION // Sets the interpolation method, setting an interpolation method affects the rendering of various functions in GD, such as the imagerotate() function. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // imagesetinterpolation(GdImage $image, int $method = IMG_BILINEAR_FIXED): bool // ===== CODE $return_imagesetinterpolation = imagesetinterpolation( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $method // int method - The interpolation method, which can be one of the following: // * IMG_BELL : Bell filter. // * IMG_BESSEL : Bessel filter. // * IMG_BICUBIC : Bicubic interpolation. // * IMG_BICUBIC_FIXED : Fixed point implementation of the bicubic interpolation. // * IMG_BILINEAR_FIXED : Fixed point implementation of the bilinear interpolation (default (also on image creation)). // * IMG_BLACKMAN : Blackman window function. // * IMG_BOX : Box blur filter. // * IMG_BSPLINE : Spline interpolation. // * IMG_CATMULLROM : Cubic Hermite spline interpolation. // * IMG_GAUSSIAN : Gaussian function. // * IMG_GENERALIZED_CUBIC : Generalized cubic spline fractal interpolation. // * IMG_HERMITE : Hermite interpolation. // * IMG_HAMMING : Hamming filter. // * IMG_HANNING : Hanning filter. // * IMG_MITCHELL : Mitchell filter. // * IMG_POWER : Power interpolation. // * IMG_QUADRATIC : Inverse quadratic interpolation. // * IMG_SINC : Sinc function. // * IMG_NEAREST_NEIGHBOUR : Nearest neighbour interpolation. // * IMG_WEIGHTED4 : Weighting filter. // * IMG_TRIANGLE : Triangle interpolation. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagesetinterpolation() example // [php] // // Load an image // $im = imagecreate(500, 500); // // // By default interpolation is IMG_BILINEAR_FIXED, switch // // to use the 'Mitchell' filter: // imagesetinterpolation($im, IMG_MITCHELL); // // // Continue to work with $im ... // [/php] // [/example] // [/examples] // // Notes // Changing the interpolation method affects the following functions when rendering: // * imageaffine() // * imagerotate() // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagesetinterpolation.php // ========== IMAGESETINTERPOLATION - END // SYNTAX: // bool imagesetinterpolation(GdImage $image, int $method = IMG_BILINEAR_FIXED) return $return_imagesetinterpolation; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGESETINTERPOLATION // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETPIXEL // ============================== PUBLIC // ============================== ABOUT // Set a single pixel. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesetpixel() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesetpixel($image, $x, $y, $color) { $return_imagesetpixel = false; // ========== IMAGESETPIXEL - BEGIN // ===== ABOUT // Set a single pixel // ===== DESCRIPTION // imagesetpixel() draws a pixel at the specified coordinate. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesetpixel( // GdImage $image, // int $x, // int $y, // int $color // ): bool // ===== CODE $return_imagesetpixel = imagesetpixel( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $x, // int x - x-coordinate. $y, // int y - y-coordinate. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagesetpixel() example // A random drawing that ends with a regular picture. // [php] // // $x = 200; // $y = 200; // // $gd = imagecreatetruecolor($x, $y); // // $corners[0] = array('x' => 100, 'y' => 10); // $corners[1] = array('x' => 0, 'y' => 190); // $corners[2] = array('x' => 200, 'y' => 190); // // $red = imagecolorallocate($gd, 255, 0, 0); // // for ($i = 0; $i < 100000; $i++) { // imagesetpixel($gd, round($x), round($y), $red); // $a = rand(0, 2); // $x = ($x + $corners[$a]['x']) / 2; // $y = ($y + $corners[$a]['y']) / 2; // } // // header('Content-Type: image/png'); // imagepng($gd); // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagesetpixel.php // ========== IMAGESETPIXEL - END // SYNTAX: // bool imagesetpixel(GdImage $image, int $x, int $y, int $color) return $return_imagesetpixel; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESETPIXEL // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETSTYLE // ============================== PUBLIC // ============================== ABOUT // Set the style for line drawing. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesetstyle() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesetstyle($image, $style) { $return_imagesetstyle = false; // ========== IMAGESETSTYLE - BEGIN // ===== ABOUT // Set the style for line drawing // ===== DESCRIPTION // imagesetstyle() sets the style to be used by all line drawing functions (such as imageline() and imagepolygon()) when drawing with the special color IMG_COLOR_STYLED or lines of images with color IMG_COLOR_STYLEDBRUSHED. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesetstyle(GdImage $image, array $style): bool // ===== CODE $return_imagesetstyle = imagesetstyle( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $style // array style - An array of pixel colors. You can use the IMG_COLOR_TRANSPARENT constant to add a transparent pixel. Note that style must not be an empty array. ); // Return Values // Returns true on success or false on failure. // // [examples] // Examples // [example] // Following example script draws a dashed line from upper left to lower right corner of the canvas: // Example #1 imagesetstyle() example // [php] // header("Content-type: image/jpeg"); // $im = imagecreatetruecolor(100, 100); // $w = imagecolorallocate($im, 255, 255, 255); // $red = imagecolorallocate($im, 255, 0, 0); // // // Draw a dashed line, 5 red pixels, 5 white pixels // $style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w); // imagesetstyle($im, $style); // imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED); // // // Draw a line of happy faces using imagesetbrush() with imagesetstyle // $style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red); // imagesetstyle($im, $style); // // $brush = imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.png"); // $w2 = imagecolorallocate($brush, 255, 255, 255); // imagecolortransparent($brush, $w2); // imagesetbrush($im, $brush); // imageline($im, 100, 0, 0, 100, IMG_COLOR_STYLEDBRUSHED); // // imagejpeg($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagesetstyle.php // ========== IMAGESETSTYLE - END // SYNTAX: // bool imagesetstyle(GdImage $image, array $style) return $return_imagesetstyle; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESETSTYLE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETTHICKNESS // ============================== PUBLIC // ============================== ABOUT // Set the thickness for line drawing. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesetthickness() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesetthickness($image, $thickness) { $return_imagesetthickness = false; // ========== IMAGESETTHICKNESS - BEGIN // ===== ABOUT // Set the thickness for line drawing // ===== DESCRIPTION // imagesetthickness() sets the thickness of the lines drawn when drawing rectangles, polygons, arcs etc. to thickness pixels. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesetthickness(GdImage $image, int $thickness): bool // ===== CODE $return_imagesetthickness = imagesetthickness( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $thickness // int thickness - Thickness, in pixels. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagesetthickness() example // [php] // // Create a 200x100 image // $im = imagecreatetruecolor(200, 100); // $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); // $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // // // Set the background to be white // imagefilledrectangle($im, 0, 0, 299, 99, $white); // // // Set the line thickness to 5 // imagesetthickness($im, 5); // // // Draw the rectangle // imagerectangle($im, 14, 14, 185, 85, $black); // // // Output image to the browser // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagesetthickness.php // ========== IMAGESETTHICKNESS - END // SYNTAX: // bool imagesetthickness(GdImage $image, int $thickness) return $return_imagesetthickness; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESETTHICKNESS // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESETTILE // ============================== PUBLIC // ============================== ABOUT // Set the tile image for filling. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesettile() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesettile($image, $tile) { $return_imagesettile = false; // ========== IMAGESETTILE - BEGIN // ===== ABOUT // Set the tile image for filling // ===== DESCRIPTION // imagesettile() sets the tile image to be used by all region filling functions (such as imagefill() and imagefilledpolygon()) when filling with the special color IMG_COLOR_TILED. // A tile is an image used to fill an area with a repeated pattern. Any GD image can be used as a tile, and by setting the transparent color index of the tile image with imagecolortransparent(), a tile allows certain parts of the underlying area to shine through can be created. // Caution: You need not take special action when you are finished with a tile, but if you destroy the tile image (or let PHP destroy it), you must not use the IMG_COLOR_TILED color until you have set a new tile image! // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesettile(GdImage $image, GdImage $tile): bool // ===== CODE $return_imagesettile = imagesettile( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $tile // GdImage tile - The image object to be used as a tile. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image and tile expect GdImage instances now; previously, resources were expected. // // [examples] // Examples // [example] // Example #1 imagesettile() example // [php] // // Load an external image // $zend = imagecreatefromgif('./zend.gif'); // // // Create a 200x200 image // $im = imagecreatetruecolor(200, 200); // // // Set the tile // imagesettile($im, $zend); // // // Make the image repeat // imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED); // // // Output image to the browser // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // imagedestroy($zend); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagesettile.php // ========== IMAGESETTILE - END // SYNTAX: // bool imagesettile(GdImage $image, GdImage $tile) return $return_imagesettile; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESETTILE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESTRING // ============================== PUBLIC // ============================== ABOUT // Draw a string horizontally. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagestring() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagestring($image, $font, $x, $y, $string, $color) { $return_imagestring = false; // ========== IMAGESTRING - BEGIN // ===== ABOUT // Draw a string horizontally // ===== DESCRIPTION // Draws a string at the given coordinates. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagestring( // GdImage $image, // GdFont|int $font, // int $x, // int $y, // string $string, // int $color // ): bool // ===== CODE $return_imagestring = imagestring( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $font, // GdFont|int font - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont(). $x, // int x - x-coordinate of the upper left corner. $y, // int y - y-coordinate of the upper left corner. $string, // string string - The string to be written. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The font parameter now accepts both an GdFont instance and an int; previously only int was accepted. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagestring() example // [php] // // Create a 100*30 image // $im = imagecreate(100, 30); // // // White background and blue text // $bg = imagecolorallocate($im, 255, 255, 255); // $textcolor = imagecolorallocate($im, 0, 0, 255); // // // Write the string at the top left // imagestring($im, 5, 0, 0, 'Hello world!', $textcolor); // // // Output the image // header('Content-type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagestring.php // ========== IMAGESTRING - END // SYNTAX: // bool imagestring(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color) return $return_imagestring; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESTRING // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESTRINGUP // ============================== PUBLIC // ============================== ABOUT // Draw a string vertically. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagestringup() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagestringup($image, $font, $x, $y, $string, $color) { $return_imagestringup = false; // ========== IMAGESTRINGUP - BEGIN // ===== ABOUT // Draw a string vertically // ===== DESCRIPTION // Draws a string vertically at the given coordinates. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagestringup( // GdImage $image, // GdFont|int $font, // int $x, // int $y, // string $string, // int $color // ): bool // ===== CODE $return_imagestringup = imagestringup( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $font, // GdFont|int font - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont(). $x, // int x - x-coordinate of the bottom left corner. $y, // int y - y-coordinate of the bottom left corner. $string, // string string - The string to be written. $color // int color - A color identifier created with imagecolorallocate(). ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.1.0 - The font parameter now accepts both an GdFont instance and an int; previously only int was accepted. // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 imagestringup() example // [php] // // create a 100*100 image // $im = imagecreatetruecolor(100, 100); // // // Write the text // $textcolor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); // imagestringup($im, 3, 40, 80, 'gd library', $textcolor); // // // Save the image // imagepng($im, './stringup.png'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-02) // URL: https://www.php.net/manual/en/function.imagestringup.php // ========== IMAGESTRINGUP - END // SYNTAX: // bool imagestringup(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color) return $return_imagestringup; // bool } // ============================== END // PHP_IMAGE_GD_IMAGESTRINGUP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESX // ============================== PUBLIC // ============================== ABOUT // Get image width. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesx() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesx($image) { $return_imagesx = 0; // ========== IMAGESX - BEGIN // ===== ABOUT // Get image width // ===== DESCRIPTION // Returns the width of the given image object. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesx(GdImage $image): int // ===== CODE $return_imagesx = imagesx( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Return the width of the image. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Using imagesx() // [php] // // // create a 300*200 image // $img = imagecreatetruecolor(300, 200); // // echo imagesx($img); // 300 // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagesx.php // ========== IMAGESX - END // SYNTAX: // int imagesx(GdImage $image) return $return_imagesx; // int } // ============================== END // PHP_IMAGE_GD_IMAGESX // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGESY // ============================== PUBLIC // ============================== ABOUT // Get image height. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagesy() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagesy($image) { $return_imagesy = 0; // ========== IMAGESY - BEGIN // ===== ABOUT // Get image height // ===== DESCRIPTION // Returns the height of the given image object. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagesy(GdImage $image): int // ===== CODE $return_imagesy = imagesy( $image // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). ); // Return Values // Return the height of the image. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Using imagesy() // [php] // // // create a 300*200 image // $img = imagecreatetruecolor(300, 200); // // echo imagesy($img); // 200 // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagesy.php // ========== IMAGESY - END // SYNTAX: // int imagesy(GdImage $image) return $return_imagesy; // int } // ============================== END // PHP_IMAGE_GD_IMAGESY // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGETRUECOLORTOPALETTE // ============================== PUBLIC // ============================== ABOUT // Convert a true color image to a palette image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagetruecolortopalette() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagetruecolortopalette($image, $dither, $num_colors) { $return_imagetruecolortopalette = false; // ========== IMAGETRUECOLORTOPALETTE - BEGIN // ===== ABOUT // Convert a true color image to a palette image // ===== DESCRIPTION // imagetruecolortopalette() converts a truecolor image to a palette image. The code for this function was originally drawn from the Independent JPEG Group library code, which is excellent. The code has been modified to preserve as much alpha channel information as possible in the resulting palette, in addition to preserving colors as well as possible. This does not work as well as might be hoped. It is usually best to simply produce a truecolor output image instead, which guarantees the highest output quality. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagetruecolortopalette(GdImage $image, bool $dither, int $num_colors): bool // ===== CODE $$return_imagetruecolortopalette = imagetruecolortopalette( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $dither, // bool dither - Indicates if the image should be dithered - if it is true then dithering will be used which will result in a more speckled image but with better color approximation. $num_colors // int num_colors - Sets the maximum number of colors that should be retained in the palette. ); // Return Values // Returns true on success or false on failure. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Converting a true color image to a palette-based image // [php] // // Create a new true color image // $im = imagecreatetruecolor(100, 100); // // // Convert to palette-based with no dithering and 255 colors // imagetruecolortopalette($im, false, 255); // // // Save the image // imagepng($im, './paletteimage.png'); // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.imagetruecolortopalette.php // ========== IMAGETRUECOLORTOPALETTE - END // SYNTAX: // bool imagetruecolortopalette(GdImage $image, bool $dither, int $num_colors) return $return_imagetruecolortopalette; // bool } // ============================== END // PHP_IMAGE_GD_IMAGETRUECOLORTOPALETTE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGETTFBBOX // ============================== PUBLIC // ============================== ABOUT // Give the bounding box of a text using TrueType fonts. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagettfbbox() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagettfbbox($size, $angle, $font_filename, $string) { $return_imagettfbbox = false; // ========== IMAGETTFBBOX - BEGIN // ===== ABOUT // Give the bounding box of a text using TrueType fonts // ===== DESCRIPTION // This function calculates and returns the bounding box in pixels for a TrueType text. // Note: Prior to PHP 8.0.0, imageftbbox() was an extended variant of imagettfbbox() which additionally supported the extrainfo. As of PHP 8.0.0, imagettfbbox() is an alias of imageftbbox(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagettfbbox( // float $size, // float $angle, // string $font_filename, // string $string, // array $options = [] // ): array|false // ===== CODE $return_imagettfbbox = imagettfbbox( $size, // float size - The font size in points. $angle, // float angle - Angle in degrees in which string will be measured. $font_filename, // string fontfile - The path to the TrueType font you wish to use. // Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path. // When using versions of the GD library lower than 2.0.18, a space character, rather than a semicolon, was used as the 'path separator' for different font files. Unintentional use of this feature will result in the warning message: Warning: Could not find/open font. For these affected versions, the only solution is moving the font to a path which does not contain spaces. // In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems. // [php] // // Set the environment variable for GD // putenv('GDFONTPATH=' . realpath('.')); // // // Name the font to be used (note the lack of the .ttf extension) // $font = 'SomeFont'; // [/php] // Note: Note that open_basedir does not apply to fontfile. $string // string string - The string to be measured. ); // Return Values // imagettfbbox() returns an array with 8 elements representing four points making the bounding box of the text on success and false on error. // key - contents // 0 - lower left corner, X position // 1 - lower left corner, Y position // 2 - lower right corner, X position // 3 - lower right corner, Y position // 4 - upper right corner, X position // 5 - upper right corner, Y position // 6 - upper left corner, X position // 7 - upper left corner, Y position // The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner seeing the text horizontally. // // Changelog // Version - Description // 8.0.0 - The options has been added. // // [examples] // Examples // [example] // Example #1 imagettfbbox() example // [php] // // Create a 300x150 image // $im = imagecreatetruecolor(300, 150); // $black = imagecolorallocate($im, 0, 0, 0); // $white = imagecolorallocate($im, 255, 255, 255); // // // Set the background to be white // imagefilledrectangle($im, 0, 0, 299, 299, $white); // // // Path to our font file // $font = './arial.ttf'; // // // First we create our bounding box for the first text // $bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion()); // // // This is our cordinates for X and Y // $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25; // $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // // // Write it // imagettftext($im, 10, 45, $x, $y, $black, $font, 'Powered by PHP ' . phpversion()); // // // Create the next bounding box for the second text // $bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version()); // // // Set the cordinates so its next to the first text // $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10; // $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // // // Write it // imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_version()); // // // Output to browser // header('Content-Type: image/png'); // // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR) // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagettfbbox.php // ========== IMAGETTFBBOX - END // SYNTAX: // array|false imagettfbbox(float $size, float $angle, string $font_filename, string $string) // * 8.0.0 - The options has been added. return $return_imagettfbbox; // array|false } // ============================== END // PHP_IMAGE_GD_IMAGETTFBBOX // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGETTFTEXT // ============================== PUBLIC // ============================== ABOUT // Write text to the image using TrueType fonts. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagettftext() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagettftext($image, $size, $angle, $x, $y, $color, $font_filename, $text) { $return_imagettftext = false; // ========== IMAGETTFTEXT - BEGIN // ===== ABOUT // Write text to the image using TrueType fonts // ===== DESCRIPTION // Writes the given text into the image using TrueType fonts. // Note: Prior to PHP 8.0.0, imagefttext() was an extended variant of imagettftext() which additionally supported the extrainfo. As of PHP 8.0.0, imagettftext() is an alias of imagefttext(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagettftext( // GdImage $image, // float $size, // float $angle, // int $x, // int $y, // int $color, // string $font_filename, // string $text, // array $options = [] // ): array|false // ===== CODE $return_imagettftext = imagettftext( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $size, // float size - The font size in points. $angle, // float angle - The angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text. $x, // int x - The coordinates given by x and y will define the basepoint of the first character (roughly the lower-left corner of the character). This is different from the imagestring(), where x and y define the upper-left corner of the first character. For example, "top left" is 0, 0. $y, // int y - The y-ordinate. This sets the position of the fonts baseline, not the very bottom of the character. $color, // int color - The color index. Using the negative of a color index has the effect of turning off antialiasing. See imagecolorallocate(). $font_filename, // string fontfile - The path to the TrueType font you wish to use. // Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path. // When using versions of the GD library lower than 2.0.18, a space character, rather than a semicolon, was used as the 'path separator' for different font files. Unintentional use of this feature will result in the warning message: Warning: Could not find/open font. For these affected versions, the only solution is moving the font to a path which does not contain spaces. // In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems. // [php] // // Set the environment variable for GD // putenv('GDFONTPATH=' . realpath('.')); // // // Name the font to be used (note the lack of the .ttf extension) // $font = 'SomeFont'; // [/php] // Note: Note that open_basedir does not apply to fontfile. $text // string text - The text string in UTF-8 encoding. // May include decimal numeric character references (of the form: €) to access characters in a font beyond position 127. The hexadecimal format (like ©) is supported. Strings in UTF-8 encoding can be passed directly. // Named entities, such as ©, are not supported. Consider using html_entity_decode() to decode these named entities into UTF-8 strings. // If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character. ); // Return Values // Returns an array with 8 elements representing four points making the bounding box of the text. The order of the points is lower left, lower right, upper right, upper left. The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner when you see the text horizontally. Returns false on error. // // Changelog // Version - Description // 8.0.0 - The options has been added. // // [examples] // Examples // [example] // Example #1 imagettftext() example // This example script will produce a white PNG 400x30 pixels, with the words "Testing..." in black (with grey shadow), in the font Arial. // [php] // // Set the content-type // header('Content-Type: image/png'); // // // Create the image // $im = imagecreatetruecolor(400, 30); // // // Create some colors // $white = imagecolorallocate($im, 255, 255, 255); // $grey = imagecolorallocate($im, 128, 128, 128); // $black = imagecolorallocate($im, 0, 0, 0); // imagefilledrectangle($im, 0, 0, 399, 29, $white); // // // The text to draw // $text = 'Testing...'; // // Replace path by your own font path // $font = 'arial.ttf'; // // // Add some shadow to the text // imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // // // Add the text // imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // // // Using imagepng() results in clearer text compared with imagejpeg() // imagepng($im); // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // Note: This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR) // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-03) // URL: https://www.php.net/manual/en/function.imagettftext.php // ========== IMAGETTFTEXT - END // SYNTAX: // array|false imagettftext(GdImage $image, float $size, float $angle, int $x, int $y, int $color, string $font_filename, string $text) // * 8.0.0 - The options has been added. return $return_imagettftext; // array|false } // ============================== END // PHP_IMAGE_GD_IMAGETTFTEXT // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGETYPES // ============================== PUBLIC // ============================== ABOUT // Return the image types supported by this PHP build. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagetypes() - PHP_4 >= PHP_4_0_2, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagetypes() { $return_imagetypes = 0; // ========== IMAGETYPES - BEGIN // ===== ABOUT // Return the image types supported by this PHP build // ===== DESCRIPTION // Returns the image types supported by the current PHP installation. // ===== SUPPORTED // PHP_4 >= PHP_4_0_2, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagetypes(): int // ===== CODE $return_imagetypes = imagetypes( // This function has no parameters. ); // Return Values // Returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_AVIF | IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP. // // Changelog // Version - Description // 8.1.0 - IMG_AVIF added. // 7.2.0 - IMG_BMP added. // 7.0.10 - IMG_WEBP added. // // [examples] // Examples // [example] // Example #1 Checking for PNG support // [php] // if (imagetypes() & IMG_PNG) { // echo "PNG Support is enabled"; // } // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagetypes.php // ========== IMAGETYPES - END // SYNTAX: // int imagetypes() return $return_imagetypes; // int } // ============================== END // PHP_IMAGE_GD_IMAGETYPES // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEWBMP // ============================== PUBLIC // ============================== ABOUT // Output image to browser or file. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // imagewbmp() - PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_imagewbmp($image, $file = null, $foreground_color = null) { $return_imagewbmp = false; // ========== IMAGEWBMP - BEGIN // ===== ABOUT // Output image to browser or file // ===== DESCRIPTION // imagewbmp() outputs or save a WBMP version of the given image. // ===== SUPPORTED // PHP_4 >= PHP_4_0_1, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagewbmp(GdImage $image, resource|string|null $file = null, ?int $foreground_color = null): bool // ===== CODE $return_imagewbmp = imagewbmp( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. $foreground_color // ?int foreground_color - You can set the foreground color with this parameter by setting an identifier obtained from imagecolorallocate(). The default foreground color is black. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - foreground_color is nullable now. // // [examples] // Examples // [example] // Example #1 Outputting a WBMP image // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Set the content type header - in this case image/vnd.wap.wbmp // // Hint: see image_type_to_mime_type() for content-types // header('Content-Type: image/vnd.wap.wbmp'); // // // Output the image // imagewbmp($im); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Saving the WBMP image // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Save the image // imagewbmp($im, 'simpletext.wbmp'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [example] // Example #3 Outputting the image with a different foreground // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Set the content type header - in this case image/vnd.wap.wbmp // // Hint: see image_type_to_mime_type() for content-types // header('Content-Type: image/vnd.wap.wbmp'); // // // Set a replacement foreground color // $foreground_color = imagecolorallocate($im, 255, 0, 0); // // imagewbmp($im, NULL, $foreground_color); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagewbmp.php // ========== IMAGEWBMP - END // SYNTAX: // bool imagewbmp(GdImage $image, resource|string|null $file = null, int $foreground_color = null) return $return_imagewbmp; // bool } // ============================== END // PHP_IMAGE_GD_IMAGEWBMP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEWEBP // ============================== OFFLINE // ============================== ABOUT // Output a WebP image to browser or file. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagewebp() - PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagewebp($image, $file = null, $quality = -1) { $return_imagewebp = false; // ========== IMAGEWEBP - BEGIN // ===== ABOUT // Output a WebP image to browser or file // ===== DESCRIPTION // Outputs or saves a WebP version of the given image. // ===== SUPPORTED // PHP_5 >= PHP_5_4_0, PHP_7, PHP_8 // ===== SYNTAX // imagewebp(GdImage $image, resource|string|null $file = null, int $quality = -1): bool // ===== CODE $return_imagewebp = imagewebp( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $file, // resource|string|null file - The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly. $quality // int quality - quality ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // // [examples] // Examples // [example] // Example #1 Saving an WebP file // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // // imagestring($im, 1, 5, 5, 'WebP with PHP', $text_color); // // // Save the image // imagewebp($im, 'php.webp'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagewebp.php // ========== IMAGEWEBP - END // SYNTAX: // bool imagewebp(GdImage $image, resource|string|null $file = null, int $quality = -1) return $return_imagewebp; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEWEBP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IMAGEXBM // ============================== OFFLINE // ============================== ABOUT // Output an XBM image to browser or file. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // imagexbm() - PHP_5, PHP_7, PHP_8 // ============================== CODE /* function php_image_gd_imagexbm($image, $filename, $foreground_color = null) { $return_imagexbm = false; // ========== IMAGEXBM - BEGIN // ===== ABOUT // Output an XBM image to browser or file // ===== DESCRIPTION // Outputs or save an XBM version of the given image. // Note: imagexbm() doesn't apply any padding, so the image width has to be a multiple of 8. This restriction does no longer apply as of PHP 7.0.9. // ===== SUPPORTED // PHP_5, PHP_7, PHP_8 // ===== SYNTAX // imagexbm(GdImage $image, ?string $filename, ?int $foreground_color = null): bool // ===== CODE $return_imagexbm = imagexbm( $image, // GdImage image - A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). $filename, // ?string filename - The path to save the file to, given as string. If null, the raw image stream will be output directly. // The filename (without the .xbm extension) is also used for the C identifiers of the XBM, whereby non alphanumeric characters of the current locale are substituted by underscores. If filename is set to null, image is used to build the C identifiers. $foreground_color // ?int foreground_color - You can set the foreground color with this parameter by setting an identifier obtained from imagecolorallocate(). The default foreground color is black. All other colors are treated as background. ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // Changelog // Version - Description // 8.0.0 - image expects a GdImage instance now; previously, a valid gd resource was expected. // 8.0.0 - foreground_color is now nullable. // 8.0.0 - The fourth parameter, which was unused, has been removed. // // [examples] // Examples // [example] // Example #1 Saving an XBM file // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Save the image // imagexbm($im, 'simpletext.xbm'); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [example] // Example #2 Saving an XBM file with a different foreground color // [php] // // Create a blank image and add some text // $im = imagecreatetruecolor(120, 20); // $text_color = imagecolorallocate($im, 233, 14, 91); // imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // // // Set a replacement foreground color // $foreground_color = imagecolorallocate($im, 255, 0, 0); // // // Save the image // imagexbm($im, NULL, $foreground_color); // // // Free up memory // imagedestroy($im); // [/php] // [/example] // [/examples] // // Notes // // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-01) // URL: https://www.php.net/manual/en/function.imagexbm.php // ========== IMAGEXBM - END // SYNTAX: // bool imagexbm(GdImage $image, string $filename, int $foreground_color = null) return $return_imagexbm; // bool } */ // ============================== END // PHP_IMAGE_GD_IMAGEXBM // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IPTCEMBED // ============================== PUBLIC // ============================== ABOUT // Embeds binary IPTC data into a JPEG image. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // iptcembed() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_iptcembed($iptc_data, $filename, $spool = 0) { $return_iptcembed = false; // ========== IPTCEMBED - BEGIN // ===== ABOUT // Embeds binary IPTC data into a JPEG image // ===== DESCRIPTION // Embeds binary IPTC data into a JPEG image. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // iptcembed(string $iptc_data, string $filename, int $spool = 0): string|bool // ===== CODE $return_iptcembed = iptcembed( $iptc_data, // string iptc_data - The data to be written. $filename, // string filename - Path to the JPEG image. $spool // int spool - Spool flag. If the spool flag is less than 2 then the JPEG will be returned as a string. Otherwise the JPEG will be printed to STDOUT. ); // Return Values // If spool is less than 2, the JPEG will be returned, or false on failure. Otherwise returns true on success or false on failure. // // [examples] // Examples // [example] // Example #1 Embedding IPTC data into a JPEG // [php] // // // iptc_make_tag() function by Thies C. Arntzen // function iptc_make_tag($rec, $data, $value) // { // $length = strlen($value); // $retval = chr(0x1C) . chr($rec) . chr($data); // // if($length < 0x8000) // { // $retval .= chr($length >> 8) . chr($length & 0xFF); // } // else // { // $retval .= chr(0x80) . // chr(0x04) . // chr(($length >> 24) & 0xFF) . // chr(($length >> 16) & 0xFF) . // chr(($length >> 8) & 0xFF) . // chr($length & 0xFF); // } // // return $retval . $value; // } // // // Path to jpeg file // $path = './phplogo.jpg'; // // // Set the IPTC tags // $iptc = array( // '2#120' => 'Test image', // '2#116' => 'Copyright 2008-2009, The PHP Group' // ); // // // Convert the IPTC tags into binary code // $data = ''; // // foreach($iptc as $tag => $string) // { // $tag = substr($tag, 2); // $data .= iptc_make_tag(2, $tag, $string); // } // // // Embed the IPTC data // $content = iptcembed($data, $path); // // // Write the new image data out to the file. // $fp = fopen($path, "wb"); // fwrite($fp, $content); // fclose($fp); // [/php] // [/example] // [/examples] // // Notes // Note: This function does not require the GD image library. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.iptcembed.php // ========== IPTCEMBED - END // SYNTAX: // string|bool iptcembed(string $iptc_data, string $filename, int $spool = 0) return $return_iptcembed; // string|bool } // ============================== END // PHP_IMAGE_GD_IPTCEMBED // ============================== // ============================== BEGIN // PHP_IMAGE_GD_IPTCPARSE // ============================== PUBLIC // ============================== ABOUT // Parse a binary IPTC block into single tags. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // iptcparse() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_image_gd_iptcparse($iptc_block) { $return_iptcparse = false; // ========== IPTCPARSE - BEGIN // ===== ABOUT // Parse a binary IPTC block into single tags // ===== DESCRIPTION // Parses an > IPTC block into its single tags. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // iptcparse(string $iptc_block): array|false // ===== CODE $return_iptcparse = iptcparse( $iptc_block // string iptc_block - A binary IPTC block. ); // Return Values // Returns an array using the tagmarker as an index and the value as the value. It returns false on error or if no IPTC data was found. // // [examples] // Examples // [example] // Example #1 iptcparse() used together with getimagesize() // [php] // $size = getimagesize('./test.jpg', $info); // if(isset($info['APP13'])) // { // $iptc = iptcparse($info['APP13']); // var_dump($iptc); // } // [/php] // [/example] // [/examples] // // Notes // Note: This function does not require the GD image library. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-04) // URL: https://www.php.net/manual/en/function.iptcparse.php // ========== IPTCPARSE - END // SYNTAX: // array|false iptcparse(string $iptc_block) return $return_iptcparse; // array|false } // ============================== END // PHP_IMAGE_GD_IPTCPARSE // ============================== // ============================== BEGIN // PHP_IMAGE_GD_JPEG2WBMP // ============================== OFFLINE // ============================== ABOUT // Convert JPEG image file to WBMP image file. // // Warning: This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. // ============================== SUPPORT // PHP_4 - PHP_7 // ============================== USING FUNCTIONS (1) // jpeg2wbmp() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ============================== CODE /* function php_image_gd_jpeg2wbmp($jpegname, $wbmpname, $dest_height, $dest_width, $threshold) { $return_jpeg2wbmp = false; // ========== JPEG2WBMP - BEGIN // ===== ABOUT // Convert JPEG image file to WBMP image file // Warning: This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. // ===== DESCRIPTION // Converts a JPEG file into a WBMP file. // ===== SUPPORTED // PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ===== SYNTAX // jpeg2wbmp( // string $jpegname, // string $wbmpname, // int $dest_height, // int $dest_width, // int $threshold // ): bool // ===== CODE $return_jpeg2wbmp = jpeg2wbmp( $jpegname, // string jpegname - Path to JPEG file. $wbmpname, // string wbmpname - Path to destination WBMP file. $dest_height, // int dest_height - Destination image height. $dest_width, // int dest_width - Destination image width. $threshold // int threshold - Threshold value, between 0 and 8 (inclusive). ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // [examples] // Examples // [example] // Example #1 jpeg2wbmp() example // [php] // // Path to the target jpeg // $path = './test.jpg'; // // // Get the image sizes // $image = getimagesize($path); // // // Convert image // jpeg2wbmp($path, './test.wbmp', $image[1], $image[0], 5); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2023-07-31) // URL: https://www.php.net/manual/en/function.jpeg2wbmp.php // ========== JPEG2WBMP - END // SYNTAX: // bool jpeg2wbmp(string $jpegname, string $wbmpname, int $dest_height, int $dest_width, int $threshold) return $return_jpeg2wbmp; // bool } */ // ============================== END // PHP_IMAGE_GD_JPEG2WBMP // ============================== // ============================== BEGIN // PHP_IMAGE_GD_PNG2WBMP // ============================== OFFLINE // ============================== ABOUT // Convert PNG image file to WBMP image file. // // Warning: This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. // ============================== SUPPORT // PHP_4 - PHP_7 // ============================== USING FUNCTIONS (1) // png2wbmp() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ============================== CODE /* function php_image_gd_png2wbmp($pngname, $wbmpname, $dest_height, $dest_width, $threshold) { $return_png2wbmp = false; // ========== PNG2WBMP - BEGIN // ===== ABOUT // Convert PNG image file to WBMP image file // Warning: This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. // ===== DESCRIPTION // Converts a PNG file into a WBMP file. // ===== SUPPORTED // PHP_4 >= PHP_4_0_5, PHP_5, PHP_7 // ===== SYNTAX // png2wbmp( // string $pngname, // string $wbmpname, // int $dest_height, // int $dest_width, // int $threshold // ): bool // ===== CODE $return_png2wbmp = png2wbmp( $pngname, // string pngname - Path to PNG file. $wbmpname, // string wbmpname - Path to destination WBMP file. $dest_height, // int dest_height - Destination image height. $dest_width, // int dest_width - Destination image width. $threshold // int threshold - Threshold value, between 0 and 8 (inclusive). ); // Return Values // Returns true on success or false on failure. // Caution: However, if libgd fails to output the image, this function returns true. // // [examples] // Examples // [example] // Example #1 png2wbmp() example // [php] // // Path to the target png // $path = './test.png'; // // // Get the image sizes // $image = getimagesize($path); // // // Convert image // png2wbmp($path, './test.wbmp', $image[1], $image[0], 7); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2023-07-31) // URL: https://www.php.net/manual/en/function.png2wbmp.php // ========== PNG2WBMP - END // SYNTAX: // bool png2wbmp(string $pngname, string $wbmpname, int $dest_height, int $dest_width, int $threshold) return $return_png2wbmp; // bool } */ // ============================== END // PHP_IMAGE_GD_PNG2WBMP // ============================== // ============================== END // PHP_IMAGE_GD // ==============================