Exemple #1
0
 public function draw($resource, $x, $y)
 {
     if (!$this->_color) {
         $this->_color = Rgb::createBlack();
     }
     imagettftext($resource, $this->_size, $this->_angle, $x, $y, imagecolorallocatealpha($resource, $this->_color->getRed(), $this->_color->getGreen(), $this->_color->getBlue(), $this->_color->getAlpha()), $this->_font, $this->_text);
     return $this;
 }
 public function filter($resource)
 {
     if (!is_resource($resource) || 'gd' !== get_resource_type($resource)) {
         throw new \Exception('Resource must be given');
     }
     $width = imagesx($resource);
     $height = imagesy($resource);
     $greyscaleImageResource = imagecreatetruecolor($width, $height);
     // prepare greyscale palette
     for ($c = 0; $c < 256; $c++) {
         $palette[$c] = imagecolorallocate($greyscaleImageResource, $c, $c, $c);
     }
     // set pixels
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             $rgb = imagecolorat($resource, $x, $y);
             $grey = Yiq::getYFromRgbArray(Rgb::fromIntAsArray($rgb));
             imagesetpixel($greyscaleImageResource, $x, $y, $palette[$grey]);
         }
     }
     return $greyscaleImageResource;
 }
Exemple #3
0
 public function testCrop()
 {
     $image = $this->_factory->openImage(__DIR__ . '/test.png');
     $image->crop(10, 10, 10, 10);
     $this->assertEquals(10, imagesx($image->getResource()));
     $this->assertEquals(10, imagesy($image->getResource()));
     $this->assertEquals(array(0, 0, 255, 0), Rgb::fromInt(imagecolorat($image->getResource(), 5, 5))->toArray());
 }
Exemple #4
0
 /**
  * 
  * @param type $angle
  * @param array $backgroundColor
  */
 public function rotate($angle, $backgroundColor = null)
 {
     $backgroundColor = $backgroundColor ? Rgb::normalize($backgroundColor) : new Rgb(0, 0, 0, 127);
     // create color
     $backgroundColorId = imageColorAllocateAlpha($this->_resource, $backgroundColor->getRed(), $backgroundColor->getGreen(), $backgroundColor->getBlue(), $backgroundColor->getAlpha());
     // rotate image
     $rotatedImageResource = imagerotate($this->_resource, $angle, $backgroundColorId, true);
     imagealphablending($rotatedImageResource, false);
     imagesavealpha($rotatedImageResource, true);
     $this->loadResource($rotatedImageResource);
     return $this;
 }