/**
  * Get a resized thumbnail from the given image
  * @param Image image source image for the thumbnail
  * @param int width width to calculate the thumbnail's width
  * @param int height height to calculate the thumbnail's height
  * @return Image Image instance of the thumbnail
  */
 protected function createThumbnail(Image $image, $width, $height)
 {
     $imageWidth = $image->getWidth();
     $imageHeight = $image->getHeight();
     if ($imageWidth > $imageHeight) {
         $this->calculateNewSize($imageWidth, $imageHeight, $width, $height);
     } else {
         $this->calculateNewSize($imageHeight, $imageWidth, $height, $width);
     }
     return $image->resize($width, $height);
 }
 /**
  * Get a cropped thumbnail from the given image
  * @param Image image source image for the thumbnail
  * @param int width width to calculate the thumbnail's width
  * @param int height height to calculate the thumbnail's height
  * @return Image Image instance of the thumbnail
  */
 protected function createThumbnail(Image $image, $thumbnailWidth, $thumbnailHeight)
 {
     $x = 0;
     $y = 0;
     $width = $thumbnailWidth;
     $height = $thumbnailHeight;
     if ($image->getWidth() > $image->getHeight()) {
         $this->calculateNewSize($image->getWidth(), $image->getHeight(), $width, $height, $x, $y);
     } else {
         $this->calculateNewSize($image->getHeight(), $image->getWidth(), $height, $width, $y, $x);
     }
     $thumbnail = $image->resize($width, $height);
     $thumbnail = $thumbnail->crop($x, $y, $thumbnailWidth, $thumbnailHeight);
     return $thumbnail;
 }
示例#3
0
 public function testResize()
 {
     $image = new Image($this->testImage);
     $resizeWidth = $this->testImageWidth / 2;
     $resizeHeight = $this->testImageHeight / 2;
     $resizedImage = $image->resize($resizeWidth, $resizeHeight);
     $this->assertNotNull($resizedImage, 'resizedimage is null');
     $resuzedImageWidth = $resizedImage->getWidth();
     $this->assertEquals($resizeWidth, $resuzedImageWidth, 'width is not the requested width');
     $resizedImageHeight = $resizedImage->getHeight();
     $this->assertEquals($resizeHeight, $resizedImageHeight, 'height is not the requested height');
 }