PHP Class Contao\GdImage

The class handles GD images. Usage: $source = GdImage::fromFile($objFile); $target = GdImage::fromDimensions(100, 100); $source->copyTo($target, 0, 0, 100, 100); $target->convertToPaletteImage() ->saveToFile('image.jpg');
Deprecation: Deprecated since Contao 4.3, to be removed in Contao 5.0. Use the Imagine library instead.
Show file Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$gdResource resource The GD resource handle

Public Methods

Method Description
__construct ( resource $gdResource ) Create a new object to handle a GD image
__destruct ( ) Destroy the GD resource to free memory
convertToPaletteImage ( ) : static Convert a true color image to a palette image with 256 colors and preserve transparency
copyTo ( self $gdImage, integer $x, integer $y, integer $width, integer $height ) : static Save the GD image to a file
countColors ( integer $max = null ) : integer Count the number of colors in the image
fromDimensions ( integer $width, integer $height ) : static Get the GD image object for the specified dimensions
fromFile ( contao\File $file ) : static Get the GD image object from an image file
getResource ( ) : resource Get the GD resource handle
isSemitransparent ( ) : boolean Detect if the image contains semitransparent pixels
saveToFile ( string $path ) : static Save the GD image to a file
setResource ( resource $gdResource ) : static Set the GD resource handle

Method Details

__construct() public method

Create a new object to handle a GD image
public __construct ( resource $gdResource )
$gdResource resource The GD resource handle

__destruct() public method

Destroy the GD resource to free memory
public __destruct ( )

convertToPaletteImage() public method

Convert a true color image to a palette image with 256 colors and preserve transparency
public convertToPaletteImage ( ) : static
return static

copyTo() public method

Save the GD image to a file
public copyTo ( self $gdImage, integer $x, integer $y, integer $width, integer $height ) : static
$gdImage self The target GD image
$x integer The target X coordinate
$y integer The target Y coordinate
$width integer The target width
$height integer The target height
return static

countColors() public method

Count the number of colors in the image
public countColors ( integer $max = null ) : integer
$max integer Stop parsing the image if more colors than $max were found
return integer The number of image colors

fromDimensions() public static method

Get the GD image object for the specified dimensions
public static fromDimensions ( integer $width, integer $height ) : static
$width integer The image width
$height integer The image height
return static The GD image object

fromFile() public static method

Get the GD image object from an image file
public static fromFile ( contao\File $file ) : static
$file contao\File The file object
return static The GD image object

getResource() public method

Get the GD resource handle
public getResource ( ) : resource
return resource The GD resource handle

isSemitransparent() public method

Detect if the image contains semitransparent pixels
public isSemitransparent ( ) : boolean
return boolean True if the image contains semitransparent pixels

saveToFile() public method

Save the GD image to a file
public saveToFile ( string $path ) : static
$path string The image path
return static

setResource() public method

Set the GD resource handle
public setResource ( resource $gdResource ) : static
$gdResource resource The GD resource handle
return static

Property Details

$gdResource protected property

The GD resource handle
protected resource $gdResource
return resource