예제 #1
0
 /**
  * Returns a cropped image
  *
  * @param GDImage_Image $img
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @param smart_coordinate $width
  * @param smart_coordinate $height
  * @return GDImage_Image
  */
 function execute($img, $left, $top, $width, $height)
 {
     $width = GDImage_Coordinate::fix($width, $img->getWidth(), $width);
     $height = GDImage_Coordinate::fix($height, $img->getHeight(), $height);
     $left = GDImage_Coordinate::fix($left, $img->getWidth(), $width);
     $top = GDImage_Coordinate::fix($top, $img->getHeight(), $height);
     if ($left < 0) {
         $width = $left + $width;
         $left = 0;
     }
     if ($width > $img->getWidth() - $left) {
         $width = $img->getWidth() - $left;
     }
     if ($top < 0) {
         $height = $top + $height;
         $top = 0;
     }
     if ($height > $img->getHeight() - $top) {
         $height = $img->getHeight() - $top;
     }
     if ($width <= 0 || $height <= 0) {
         JError::raiseError(500, JText::_('JLIB_GDIMAGE_ERROR_CAN_NOT_CROP_OUTSIDE'));
         return false;
     }
     $new = $img->doCreate($width, $height);
     if ($img->isTransparent() || $img instanceof GDImage_PaletteImage) {
         $new->copyTransparencyFrom($img);
         imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height);
     } else {
         $new->alphaBlending(false);
         $new->saveAlpha(true);
         imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height);
     }
     return $new;
 }
예제 #2
0
 /**
  * Prepares and corrects smart coordinates
  *
  * @param GDImage_Image $img
  * @param smart_coordinate $width
  * @param smart_coordinate $height
  * @param string $fit
  * @return array
  */
 protected function prepareDimensions($img, $width, $height, $fit)
 {
     list($width, $height) = GDImage_Coordinate::fixForResize($img, $width, $height);
     if ($width === 0 || $height === 0) {
         return array('width' => 0, 'height' => 0);
     }
     if ($fit == null) {
         $fit = 'inside';
     }
     $dim = array();
     if ($fit == 'fill') {
         $dim['width'] = $width;
         $dim['height'] = $height;
     } elseif ($fit == 'inside' || $fit == 'outside') {
         $rx = $img->getWidth() / $width;
         $ry = $img->getHeight() / $height;
         if ($fit == 'inside') {
             $ratio = $rx > $ry ? $rx : $ry;
         } else {
             $ratio = $rx < $ry ? $rx : $ry;
         }
         $dim['width'] = round($img->getWidth() / $ratio);
         $dim['height'] = round($img->getHeight() / $ratio);
     } else {
         JError::raiseError(500, JText::sprintf('JLIB_GDIMAGE_ERROR_INVALID_FIT', $fit));
         return false;
     }
     return $dim;
 }
예제 #3
0
 /**
  * Writes text to the image's canvas
  *
  * @param GDImage_Image $img
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @param string $text
  * @param integer $angle 
  * @return GDImage_Image
  */
 function writeText($image, $x, $y, $text, $angle = 0)
 {
     if ($image->isTrueColor()) {
         $image->alphaBlending(true);
     }
     $box = imageftbbox($this->size, $angle, $this->face, $text);
     $obox = array('left' => min($box[0], $box[2], $box[4], $box[6]), 'top' => min($box[1], $box[3], $box[5], $box[7]), 'right' => max($box[0], $box[2], $box[4], $box[6]) - 1, 'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1);
     $obox['width'] = abs($obox['left']) + abs($obox['right']);
     $obox['height'] = abs($obox['top']) + abs($obox['bottom']);
     $x = GDImage_Coordinate::fix($x, $image->getWidth(), $obox['width']);
     $y = GDImage_Coordinate::fix($y, $image->getHeight(), $obox['height']);
     $fixed_x = $x - $obox['left'];
     $fixed_y = $y - $obox['top'];
     imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text);
 }
예제 #4
0
 /**
  * Returns a merged image
  *
  * @param GDImage_Image $base
  * @param GDImage_Image $overlay
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @param numeric $pct
  * @return GDImage_Image
  */
 function execute($base, $overlay, $left, $top, $pct)
 {
     $x = GDImage_Coordinate::fix($left, $base->getWidth(), $overlay->getWidth());
     $y = GDImage_Coordinate::fix($top, $base->getHeight(), $overlay->getHeight());
     $result = $base->asTrueColor();
     $result->alphaBlending(true);
     $result->saveAlpha(true);
     if ($pct <= 0) {
         return $result;
     }
     if ($pct < 100) {
         imagecopymerge($result->getHandle(), $overlay->getHandle(), $x, $y, 0, 0, $overlay->getWidth(), $overlay->getHeight(), $pct);
     } else {
         imagecopy($result->getHandle(), $overlay->getHandle(), $x, $y, 0, 0, $overlay->getWidth(), $overlay->getHeight());
     }
     return $result;
 }