convertToPaletteImage() публичный Метод

Convert a true color image to a palette image with 256 colors and preserve transparency
public convertToPaletteImage ( ) : static
Результат static
Пример #1
0
 /**
  * Tests the convertToPaletteImage() method from a true color image.
  */
 public function testConvertToPaletteImageFromTrueColor()
 {
     $image = imagecreatetruecolor(100, 100);
     for ($x = 0; $x < 100; ++$x) {
         for ($y = 0; $y < 100; ++$y) {
             imagefilledrectangle($image, $x, $y, $x + 1, $y + 1, imagecolorallocatealpha($image, $x, $y, 0, 0));
         }
     }
     // Bottom right pixel transparent
     imagealphablending($image, false);
     imagefilledrectangle($image, 99, 99, 100, 100, imagecolorallocatealpha($image, 0, 0, 0, 127));
     $image = new GdImage($image);
     $image->convertToPaletteImage();
     $this->assertInternalType('resource', $image->getResource());
     $this->assertFalse(imageistruecolor($image->getResource()));
     $this->assertEquals(256, imagecolorstotal($image->getResource()));
     $this->assertEquals(127, imagecolorsforindex($image->getResource(), imagecolorat($image->getResource(), 99, 99))['alpha'], 'Bottom right pixel should be transparent');
 }