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.
Example #1
0
 /**
  * Save the GD image to a file
  *
  * @param GdImage $gdImage The target GD image
  * @param integer $x       The target X coordinate
  * @param integer $y       The target Y coordinate
  * @param integer $width   The target width
  * @param integer $height  The target height
  *
  * @return static
  */
 public function copyTo(self $gdImage, $x, $y, $width, $height)
 {
     imagecopyresampled($gdImage->getResource(), $this->gdResource, $x, $y, 0, 0, $width, $height, imagesx($this->gdResource), imagesy($this->gdResource));
     return $this;
 }
Example #2
0
 /**
  * Tests the isSemitransparent() method.
  */
 public function testIsSemitransparent()
 {
     $image = imagecreatetruecolor(100, 100);
     imagealphablending($image, false);
     $image = new GdImage($image);
     imagefill($image->getResource(), 0, 0, imagecolorallocatealpha($image->getResource(), 0, 0, 0, 0));
     $this->assertFalse($image->isSemitransparent());
     imagefill($image->getResource(), 0, 0, imagecolorallocatealpha($image->getResource(), 0, 0, 0, 127));
     $this->assertFalse($image->isSemitransparent());
     imagefill($image->getResource(), 0, 0, imagecolorallocatealpha($image->getResource(), 0, 0, 0, 126));
     $this->assertTrue($image->isSemitransparent());
     imagefill($image->getResource(), 0, 0, imagecolorallocatealpha($image->getResource(), 0, 0, 0, 1));
     $this->assertTrue($image->isSemitransparent());
     imagefill($image->getResource(), 0, 0, imagecolorallocatealpha($image->getResource(), 0, 0, 0, 0));
     $this->assertFalse($image->isSemitransparent());
 }