Exemplo n.º 1
1
 /**
  * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio.
  * Use in templates with $CroppedImage
  * 
  * @param Image_Backend $backend
  * @param integer $width Width to crop to
  * @param integer $height Height to crop to
  * @return Image_Backend
  */
 public function generateCroppedImage(Image_Backend $backend, $width, $height)
 {
     return $backend->croppedResize($width, $height);
 }
 /**
  * Generate a resized copy of this image with the given width & height.
  * Use in templates with $ResizedImage.
  * 
  * @param Image_Backend $backend
  * @param integer $width Width to resize to
  * @param integer $height Height to resize to
  * @return Image_Backend
  */
 public function generateaddWatermark(Image_Backend $backend, $watermark)
 {
     if (!$backend) {
         user_error("Image::generateFormattedImage - generateResizedImage is being called by legacy code" . " or Image::\$backend is not set.", E_USER_WARNING);
     } else {
         return $backend->addWatermark($watermark);
     }
 }
 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;
     }
 }
Exemplo n.º 4
0
 /**
  * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio.
  * Use in templates with $CroppedImage
  *
  * @param Image_Backend $backend
  * @param integer $width Width to crop to
  * @param integer $height Height to crop to
  * @return Image_Backend
  * @deprecated 4.0 Use generateFill instead
  */
 public function generateCroppedImage(Image_Backend $backend, $width, $height)
 {
     Deprecation::notice('4.0', 'Use generateFill instead');
     return $backend->croppedResize($width, $height);
 }
 public function generateColourOverlayImage(Image_Backend $backend, $colour, $opacity)
 {
     return $backend->colourOverlay($colour, $opacity);
 }
 /**
  * Resize this Image by both width and height, using padded resize. Use in templates with $SetSize.
  * @return GD
  */
 public function generateTransparentPad(Image_Backend $backend, $width, $height)
 {
     if (!$backend) {
         user_error("Image::generateTransparentFormattedImage - generateTransparentPad is being called by legacy code" . " or Image::\$backend is not set.", E_USER_WARNING);
     } else {
         return $backend->transparentPaddedResize($width, $height);
     }
 }
 public function generateCroppedOffsetImage(Image_Backend $backend, $offsetX, $offsetY, $width, $height)
 {
     // ATTENTION! GD_Backend::crop wants TOP/y as first argument (instead of x)
     return $backend->crop($offsetY, $offsetX, $width, $height);
 }
 /**
  * 
  * 
  * @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);
         }
     }
 }
 public function generateWatermarkedImage(Image_Backend $backend, $watermark, $position, $transparency)
 {
     return $backend->watermark($watermark, $position, $transparency);
 }
 public function generateGreyscaleImage(Image_Backend $gd, $r, $g, $b)
 {
     return $gd->greyscale($r, $g, $b);
 }
 /**
  * Resize the image by preserving aspect ratio, keeping the image inside the
  * $width and $height then cropping to the exact $width and $height.
  *
  * @param Image_Backend $backend
  * @param int           $width The width to size to
  * @param int           $height The width to size to
  *
  * @return Image_Backend
  */
 public function generateRatioCrop(Image_Backend $backend, $width, $height)
 {
     $this->owner->generateFormattedImage('SetRatioSize', $width, $height);
     return $backend->croppedResize($width, $height);
 }
Exemplo n.º 12
0
 /**
  * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio.
  * Use in templates with $CroppedImage
  *
  * @param Image_Backend $backend
  * @param integer $width Width to crop to
  * @param integer $height Height to crop to
  * @return Image_Backend
  * @deprecated 4.0 Generate methods are no longer applicable
  */
 public function generateCroppedImage(Image_Backend $backend, $width, $height)
 {
     Deprecation::notice('4.0', 'Generate methods are no longer applicable');
     return $backend->croppedResize($width, $height);
 }
 /**
  * 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);
             }
         }
     }
 }