Ejemplo n.º 1
0
 public function testGif()
 {
     $image = new Image(TEST_DIR . 'images/sample-gif.gif');
     $this->assertEquals(500, $image->getWidth());
     $this->assertEquals(281, $image->getHeight());
     $this->assertEquals(IMAGETYPE_GIF, $image->getType());
 }
Ejemplo n.º 2
0
 public function testAddRectangle()
 {
     $image = Image::createBlank(500, 200);
     // Blank image
     $rectangle = new Rectangle(200, 100, "#ff0000", "#000000", 5);
     // A 200x100 red rectangle with a 5-pixel thick black border
     $editor = new Editor();
     $editor->edit($image)->fill("#cccccc")->addRectangle($rectangle, 10, 10)->save(TEST_DIR . "tmp/bordered.png");
     $this->assertEquals('4a8a40ec01c5fc2e11167d80a712d5fe', md5_file(TEST_DIR . 'tmp/bordered.png'));
 }
Ejemplo n.º 3
0
 /**
  * Crop image from center
  * @param $newWidth
  * @param $newHeight
  * @param null $crop_start_x
  * @param null $crop_start_y
  * @return Editor Instance of Editor
  */
 public function crop($newWidth, $newHeight, $crop_start_x = null, $crop_start_y = null)
 {
     if (null === $crop_start_x) {
         $crop_start_x = $this->image->getWidth() / 2 - $newWidth / 2;
         // Center the crop rectangle in the x axis
     }
     if (null === $crop_start_y) {
         $crop_start_y = $this->image->getHeight() / 2 - $newHeight / 2;
         // Center the crop rectangle in the y axis
     }
     // Now crop from center to exact requested size
     $newImage = Image::createBlank($newWidth, $newHeight);
     // Preserve PNG transparency
     $newImage->fullAlphaMode(true);
     imagecopyresampled($newImage->getImageResource(), $this->image->getImageResource(), $dst_x = 0, $dst_y = 0, $crop_start_x, $crop_start_y, $newWidth, $newHeight, $src_w = $newWidth, $src_h = $newHeight);
     // Free memory
     imagedestroy($this->image->getImageResource());
     // Assign new resource
     $this->image->setImageResource($newImage->getImageResource());
     $this->image->setWidth($newWidth);
     $this->image->setHeight($newHeight);
     return $this;
 }