public function generateMaybeCroppedImage(Image_Backend $backend, $width, $height)
 {
     if ($width > 0 && $height > 0) {
         return $backend->croppedResize($width, $height);
     } elseif ($width > 0) {
         return $backend->resizeByWidth($width);
     } elseif ($height > 0) {
         return $backend->resizeByHeight($height);
     } else {
         return $backend;
     }
 }
 /**
  * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth.
  *
  * @param Image_Backend $backend
  * @param int $width The width to set
  * @return Image_Backend
  * @deprecated 4.0 Use generateScaleWidth instead
  */
 public function generateSetWidth(Image_Backend $backend, $width)
 {
     Deprecation::notice('4.0', 'Use generateScaleWidth instead');
     return $backend->resizeByWidth($width);
 }
Beispiel #3
0
 /**
  * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth.
  * 
  * @param Image_Backend $backend
  * @param type $width The width to set
  * @return Image_Backend
  */
 public function generateSetWidth(Image_Backend $backend, $width)
 {
     return $backend->resizeByWidth($width);
 }
 /**
  * 
  * 
  * @param Image_Backend $backend
  * @param integer $width Width to crop to
  * @param integer $height Height to crop to
  * @return Image_Backend
  */
 public function generateCroppedFocusedImage(Image_Backend $backend, $width, $height, $cropAxis, $cropOffset)
 {
     if ($cropAxis == 'x') {
         //Generate image
         return $backend->resizeByHeight($height)->crop(0, $cropOffset, $width, $height);
     } else {
         if ($cropAxis == 'y') {
             //Generate image
             return $backend->resizeByWidth($width)->crop($cropOffset, 0, $width, $height);
         } else {
             //Generate image without cropping
             return $backend->resize($width, $height);
         }
     }
 }
Beispiel #5
0
 /**
  * Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth.
  *
  * @param Image_Backend $backend
  * @param int $width The width to set
  * @return Image_Backend
  * @deprecated 4.0 Generate methods are no longer applicable
  */
 public function generateSetWidth(Image_Backend $backend, $width)
 {
     Deprecation::notice('4.0', 'Generate methods are no longer applicable');
     return $backend->resizeByWidth($width);
 }
 /**
  * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio and focus point.
  * Use in templates with $CroppedFocusedImage
  * 
  * @param Image_Backend $backend
  * @param integer $width Width to crop to
  * @param integer $height Height to crop to
  * @return Image_Backend
  */
 public function generateCroppedFocusedImage(Image_Backend $backend, $width, $height)
 {
     $width = round($width);
     $height = round($height);
     $top = 0;
     $left = 0;
     $originalWidth = $this->owner->width;
     $originalHeight = $this->owner->height;
     if ($this->owner->width > 0 && $this->owner->height > 0) {
         //Can't divide by zero
         //Which is over by more?
         $widthRatio = $originalWidth / $width;
         $heightRatio = $originalHeight / $height;
         //Calculate offset required
         if ($widthRatio > $heightRatio) {
             //Left and/or right of image will be lost
             //target center in px
             $croppedCenterX = floor($width / 2);
             //X axis focus point of scaled image in px
             $focusFactorX = ($this->owner->FocusX + 1) / 2;
             //i.e .333 = one third along
             $scaledImageWidth = floor($originalWidth / $heightRatio);
             $focusX = floor($focusFactorX * $scaledImageWidth);
             //Calculate difference beetween focus point and center
             $focusOffsetX = $focusX - $croppedCenterX;
             //Reduce offset if necessary so image remains filled
             $xRemainder = $scaledImageWidth - $focusX;
             $croppedXRemainder = $width - $croppedCenterX;
             if ($xRemainder < $croppedXRemainder) {
                 $focusOffsetX -= $croppedXRemainder - $xRemainder;
             }
             if ($focusOffsetX < 0) {
                 $focusOffsetX = 0;
             }
             //Set horizontal crop start point
             $left = $focusOffsetX;
             //Generate image
             return $backend->resizeByHeight($height)->crop($top, $left, $width, $height);
         } else {
             if ($widthRatio < $heightRatio) {
                 //Top and/or bottom of image will be lost
                 //Container center in px
                 $croppedCenterY = floor($height / 2);
                 //Focus point of resize image in px
                 $focusFactorY = ($this->owner->FocusY + 1) / 2;
                 // zero is bottom of image, 1 is top
                 $scaledImageHeight = floor($originalHeight / $widthRatio);
                 $focusY = $scaledImageHeight - floor($focusFactorY * $scaledImageHeight);
                 //Calculate difference beetween focus point and center
                 $focusOffsetY = $focusY - $croppedCenterY;
                 //Reduce offset if necessary so image remains filled
                 $yRemainder = $scaledImageHeight - $focusY;
                 $croppedYRemainder = $height - $croppedCenterY;
                 if ($yRemainder < $croppedYRemainder) {
                     $focusOffsetY -= $croppedYRemainder - $yRemainder;
                 }
                 if ($focusOffsetY < 0) {
                     $focusOffsetY = 0;
                 }
                 //Set vertical crop start point
                 $top = $focusOffsetY;
                 //Generate image
                 return $backend->resizeByWidth($width)->crop($top, $left, $width, $height);
             } else {
                 //Generate image without cropping
                 return $backend->resize($width, $height);
             }
         }
     }
 }