gesavealpha sets the flag which determines whether to retain * full alpha channel information (as opposed to single-color transparency) * when saving PNG images. * * Alphablending has to be disabled (imagealphablending($im, false)) * to retain the alpha-channel in the first place. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param bool $saveflag Whether to save the alpha channel or not. Defaults to FALSE. * @throws ImageException * */ function imagesavealpha($image, bool $saveflag): void { error_clear_last(); $result = \imagesavealpha($image, $saveflag); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * imagescale scales an image using the given * interpolation algorithm. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param int $new_width The width to scale the image to. * @param int $new_height The height to scale the image to. If omitted or negative, the aspect * ratio will be preserved. * @param int $mode One of IMG_NEAREST_NEIGHBOUR, * IMG_BILINEAR_FIXED, * IMG_BICUBIC, * IMG_BICUBIC_FIXED or anything else (will use two * pass). * * * IMG_WEIGHTED4 is not yet supported. * * * @return resource Return the scaled image resource on success. * @throws ImageException * */ function imagescale($image, int $new_width, int $new_height = -1, int $mode = IMG_BILINEAR_FIXED) { error_clear_last(); $result = \imagescale($image, $new_width, $new_height, $mode); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * 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. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param resource $brush An image resource. * @throws ImageException * */ function imagesetbrush($image, $brush): void { error_clear_last(); $result = \imagesetbrush($image, $brush); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * imagesetclip sets the current clipping rectangle, i.e. * the area beyond which no pixels will be drawn. * * @param resource $im An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param int $x1 The x-coordinate of the upper left corner. * @param int $y1 The y-coordinate of the upper left corner. * @param int $x2 The x-coordinate of the lower right corner. * @param int $y2 The y-coordinate of the lower right corner. * @throws ImageException * */ function imagesetclip($im, int $x1, int $y1, int $x2, int $y2): void { error_clear_last(); $result = \imagesetclip($im, $x1, $y1, $x2, $y2); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Sets the interpolation method, setting an interpolation method affects the rendering * of various functions in GD, such as the imagerotate function. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param 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. * * * * @throws ImageException * */ function imagesetinterpolation($image, int $method = IMG_BILINEAR_FIXED): void { error_clear_last(); $result = \imagesetinterpolation($image, $method); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * imagesetpixel draws a pixel at the specified * coordinate. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param int $x x-coordinate. * @param int $y y-coordinate. * @param int $color A color identifier created with imagecolorallocate. * @throws ImageException * */ function imagesetpixel($image, int $x, int $y, int $color): void { error_clear_last(); $result = \imagesetpixel($image, $x, $y, $color); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * 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. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param 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. * @throws ImageException * */ function imagesetstyle($image, array $style): void { error_clear_last(); $result = \imagesetstyle($image, $style); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * imagesetthickness sets the thickness of the lines * drawn when drawing rectangles, polygons, arcs etc. to * thickness pixels. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param int $thickness Thickness, in pixels. * @throws ImageException * */ function imagesetthickness($image, int $thickness): void { error_clear_last(); $result = \imagesetthickness($image, $thickness); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * 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. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param resource $tile The image resource to be used as a tile. * @throws ImageException * */ function imagesettile($image, $tile): void { error_clear_last(); $result = \imagesettile($image, $tile); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Draws a string at the given coordinates. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param int $font Can be 1, 2, 3, 4, 5 for built-in * fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your * own font identifiers registered with imageloadfont. * @param int $x x-coordinate of the upper left corner. * @param int $y y-coordinate of the upper left corner. * @param string $string The string to be written. * @param int $color A color identifier created with imagecolorallocate. * @throws ImageException * */ function imagestring($image, int $font, int $x, int $y, string $string, int $color): void { error_clear_last(); $result = \imagestring($image, $font, $x, $y, $string, $color); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Draws a string vertically at the given * coordinates. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param int $font Can be 1, 2, 3, 4, 5 for built-in * fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your * own font identifiers registered with imageloadfont. * @param int $x x-coordinate of the bottom left corner. * @param int $y y-coordinate of the bottom left corner. * @param string $string The string to be written. * @param int $color A color identifier created with imagecolorallocate. * @throws ImageException * */ function imagestringup($image, int $font, int $x, int $y, string $string, int $color): void { error_clear_last(); $result = \imagestringup($image, $font, $x, $y, $string, $color); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Returns the width of the given image resource. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @return int Return the width of the images. * @throws ImageException * */ function imagesx($image): int { error_clear_last(); $result = \imagesx($image); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * Returns the height of the given image resource. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @return int Return the height of the images. * @throws ImageException * */ function imagesy($image): int { error_clear_last(); $result = \imagesy($image); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * 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. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param 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. * @param int $ncolors Sets the maximum number of colors that should be retained in the palette. * @throws ImageException * */ function imagetruecolortopalette($image, bool $dither, int $ncolors): void { error_clear_last(); $result = \imagetruecolortopalette($image, $dither, $ncolors); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * This function calculates and returns the bounding box in pixels * for a TrueType text. * * @param float $size The font size in points. * @param float $angle Angle in degrees in which text will be measured. * @param 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. * * * ]]> * * * Note that open_basedir does * not apply to fontfile. * @param string $text The string to be measured. * @return array 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. * @throws ImageException * */ function imagettfbbox(float $size, float $angle, string $fontfile, string $text): array { error_clear_last(); $result = \imagettfbbox($size, $angle, $fontfile, $text); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * Writes the given text into the image using TrueType * fonts. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param float $size The font size in points. * @param 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. * @param 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. * @param int $y The y-ordinate. This sets the position of the fonts baseline, not the * very bottom of the character. * @param int $color The color index. Using the negative of a color index has the effect of * turning off antialiasing. See imagecolorallocate. * @param 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. * * * ]]> * * * Note that open_basedir does * not apply to fontfile. * @param 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 array 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. * @throws ImageException * */ function imagettftext($image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text): array { error_clear_last(); $result = \imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * imagewbmp outputs or save a WBMP * version of the given image. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly. * @param int $foreground You can set the foreground color with this parameter by setting an * identifier obtained from imagecolorallocate. * The default foreground color is black. * @throws ImageException * */ function imagewbmp($image, $to = null, int $foreground = null): void { error_clear_last(); if ($foreground !== null) { $result = \imagewbmp($image, $to, $foreground); } else { $result = \imagewbmp($image, $to); } if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Outputs or saves a WebP version of the given image. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param mixed $to The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly. * @param int $quality quality ranges from 0 (worst * quality, smaller file) to 100 (best quality, biggest file). * @throws ImageException * */ function imagewebp($image, $to = null, int $quality = 80): void { error_clear_last(); $result = \imagewebp($image, $to, $quality); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Outputs or save an XBM version of the given * image. * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. * @param string|null $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. * @param int $foreground 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. * @throws ImageException * */ function imagexbm($image, ?string $filename, int $foreground = null): void { error_clear_last(); if ($foreground !== null) { $result = \imagexbm($image, $filename, $foreground); } else { $result = \imagexbm($image, $filename); } if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Embeds binary IPTC data into a JPEG image. * * @param string $iptcdata The data to be written. * @param string $jpeg_file_name Path to the JPEG image. * @param 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 string|bool If spool is less than 2, the JPEG will be returned. Otherwise returns TRUE on success. * @throws ImageException * */ function iptcembed(string $iptcdata, string $jpeg_file_name, int $spool = 0) { error_clear_last(); $result = \iptcembed($iptcdata, $jpeg_file_name, $spool); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * Parses an IPTC block into its single tags. * * @param string $iptcblock A binary IPTC block. * @return array 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. * @throws ImageException * */ function iptcparse(string $iptcblock): array { error_clear_last(); $result = \iptcparse($iptcblock); if ($result === false) { throw ImageException::createFromPhpError(); } return $result; } /** * Converts a JPEG file into a WBMP file. * * @param string $jpegname Path to JPEG file. * @param string $wbmpname Path to destination WBMP file. * @param int $dest_height Destination image height. * @param int $dest_width Destination image width. * @param int $threshold Threshold value, between 0 and 8 (inclusive). * @throws ImageException * */ function jpeg2wbmp(string $jpegname, string $wbmpname, int $dest_height, int $dest_width, int $threshold): void { error_clear_last(); $result = \jpeg2wbmp($jpegname, $wbmpname, $dest_height, $dest_width, $threshold); if ($result === false) { throw ImageException::createFromPhpError(); } } /** * Converts a PNG file into a WBMP file. * * @param string $pngname Path to PNG file. * @param string $wbmpname Path to destination WBMP file. * @param int $dest_height Destination image height. * @param int $dest_width Destination image width. * @param int $threshold Threshold value, between 0 and 8 (inclusive). * @throws ImageException * */ function png2wbmp(string $pngname, string $wbmpname, int $dest_height, int $dest_width, int $threshold): void { error_clear_last(); $result = \png2wbmp($pngname, $wbmpname, $dest_height, $dest_width, $threshold); if ($result === false) { throw ImageException::createFromPhpError(); } }