Exemple #1
0
 public function testImageInitialState()
 {
     $image = new Image('./module/Image/test/image.png', '');
     //$this->assertFalse($image->getSource());
     $this->assertEquals($image->getWidth(), 1499);
     $this->assertEquals($image->getHeight(), 803);
     $this->assertEquals($image->getMime(), 'image/png');
     $this->assertNull($image->getOutputFormat());
     $image->getSource();
     $this->assertEquals($image->getOutputFormat(), 'png');
 }
Exemple #2
0
 /**
  * (non-PHPdoc)
  * @param Image $image
  * @see \Image\Filter\ImageFilterInterface::filter()
  */
 public function filter(Image $image)
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $tempimage = imagecreatetruecolor($width, $height);
     if (!imagecopyresampled($tempimage, $image->getSource(), 0, 0, 0, 0, $width, $height, $image->getWidth(), $image->getHeight())) {
         return false;
     }
     imagedestroy($image->getSource());
     $image->setSource($tempimage);
     $image->setWidth($width);
     $image->setHeight($height);
     return true;
 }
Exemple #3
0
 /**
  *
  * @param Image $image
  * @return boolean
  */
 protected function dimensionsScale(Image $image)
 {
     $aspect = $image->getHeight() / $image->getWidth();
     $width = $this->getWidth();
     $height = $this->getHeight();
     $upscale = $this->getUpscale();
     // Calculate one of the dimensions from the other target dimension,
     // ensuring the same aspect ratio as the source dimensions. If one of the
     // target dimensions is missing, that is the one that is calculated. If both
     // are specified then the dimension calculated is the one that would not be
     // calculated to be bigger than its target.
     if ($width && !$height || $width && $height && $aspect < $height / $width) {
         $height = (int) round($width * $aspect);
     } else {
         $width = (int) round($height / $aspect);
     }
     // Don't upscale if the option isn't enabled.
     if (!$upscale && ($width >= $image->getWidth() || $height >= $image->getHeight())) {
         return false;
     }
     $this->setWidth($width);
     $this->setHeight($height);
     return true;
 }
Exemple #4
0
 /**
  *
  * @param Image $image
  */
 private function crop($image)
 {
     $scale = max($this->getWidth() / $image->getWidth(), $this->getHeight() / $image->getHeight());
     $x = ($image->getWidth() * $scale - $this->getWidth()) / 2;
     $y = ($image->getHeight() * $scale - $this->getHeight()) / 2;
     if ($this->getValign()) {
         switch ($this->getValign()) {
             case 'top':
                 $y = 0;
                 break;
             case 'bottom':
                 $y = $image->getHeight() * $scale - $this->getHeight();
                 break;
         }
     }
     if ($this->getAlign()) {
         $x = ($image->getWidth() * $scale - $this->getWidth()) / 2;
     }
     $options = array('offsetX' => $x, 'pffsetY' => $y, 'width' => $this->getWidth(), 'height' => $this->getHeight());
     $filter = new Crop();
     $filter->setOptions($options);
     return $filter->filter($image);
 }
Exemple #5
0
 /**
  *
  * @param Image $image
  * @see \Image\Filter\Resize::filter()
  */
 public function filter(Image $image)
 {
     $aspect = $image->getHeight() / $this->getWidth();
     if (empty($this->getHeight())) {
         $this->setHeight($this->getWidth() / $aspect);
     }
     if (empty($this->getWidth())) {
         $this->setWidth($this->getHeight() * $aspect);
     }
     $tempimage = imagecreatetruecolor($this->getWidth(), $this->getHeight());
     if (!imagecopyresampled($tempimage, $image->getSource(), 0, 0, $this->getOffsetX(), $this->getOffsetY(), $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight())) {
         return false;
     }
     imagedestroy($image->getSource());
     $image->setSource($tempimage);
     $image->setWidth($this->getWidth());
     $image->setHeight($this->getHeight());
     return true;
 }