コード例 #1
0
 /**
  * Returns rotated image
  *
  * @param GDImage_Image $image
  * @param numeric $angle
  * @param int $bgColor
  * @param bool $ignoreTransparent
  * @return GDImage_Image
  */
 function execute($image, $angle, $bgColor, $ignoreTransparent)
 {
     $angle = -floatval($angle);
     if ($angle < 0) {
         $angle = 360 + $angle;
     }
     $angle = $angle % 360;
     if ($angle == 0) {
         return $image->copy();
     }
     $image = $image->asTrueColor();
     if ($bgColor === null) {
         $bgColor = $image->getTransparentColor();
         if ($bgColor == -1) {
             $bgColor = $image->allocateColorAlpha(255, 255, 255, 127);
             imagecolortransparent($image->getHandle(), $bgColor);
         }
     }
     return new GDImage_TrueColorImage(imagerotate($image->getHandle(), $angle, $bgColor, $ignoreTransparent));
 }
コード例 #2
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;
 }
コード例 #3
0
 /**
  * Applies a mask on the copy of source image
  *
  * @param GDImage_Image $image
  * @param GDImage_Image $mask
  * @param smart_coordinate $left
  * @param smart_coordinate $top
  * @return GDImage_Image
  */
 function execute($image, $mask, $left = 0, $top = 0)
 {
     $left = WideImage_Coordinate::fix($left, $image->getWidth(), $mask->getWidth());
     $top = WideImage_Coordinate::fix($top, $image->getHeight(), $mask->getHeight());
     $width = $image->getWidth();
     $mask_width = $mask->getWidth();
     $height = $image->getHeight();
     $mask_height = $mask->getHeight();
     $result = $image->asTrueColor();
     $result->alphaBlending(false);
     $result->saveAlpha(true);
     $srcTransparentColor = $result->getTransparentColor();
     if ($srcTransparentColor >= 0) {
         $destTransparentColor = $srcTransparentColor;
     } else {
         $destTransparentColor = $result->allocateColorAlpha(255, 255, 255, 127);
     }
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $mx = $x - $left;
             $my = $y - $top;
             if ($mx >= 0 && $mx < $mask_width && $my >= 0 && $my < $mask_height) {
                 $srcColor = $image->getColorAt($x, $y);
                 if ($srcColor == $srcTransparentColor) {
                     $destColor = $destTransparentColor;
                 } else {
                     $maskRGB = $mask->getRGBAt($mx, $my);
                     if ($maskRGB['red'] == 0) {
                         $destColor = $destTransparentColor;
                     } elseif ($srcColor >= 0) {
                         $imageRGB = $image->getRGBAt($x, $y);
                         $level = $maskRGB['red'] / 255 * (1 - $imageRGB['alpha'] / 127);
                         $imageRGB['alpha'] = 127 - round($level * 127);
                         if ($imageRGB['alpha'] == 127) {
                             $destColor = $destTransparentColor;
                         } else {
                             $destColor = $result->allocateColorAlpha($imageRGB);
                         }
                     } else {
                         $destColor = $destTransparentColor;
                     }
                 }
                 $result->setColorAt($x, $y, $destColor);
             }
         }
     }
     return $result;
 }
コード例 #4
0
 /**
  * @param GDImage_Image $image
  * @param int $radius
  * @param int $color
  * @param int $smoothness
  * @return GDImage_Image
  */
 function execute($image, $radius, $color, $smoothness, $corners)
 {
     if ($smoothness < 1) {
         $sample_ratio = 1;
     } elseif ($smoothness > 16) {
         $sample_ratio = 16;
     } else {
         $sample_ratio = $smoothness;
     }
     $corner = GDImage::createTrueColorImage($radius * $sample_ratio, $radius * $sample_ratio);
     if ($color === null) {
         imagepalettecopy($corner->getHandle(), $image->getHandle());
         $bg_color = $corner->allocateColor(0, 0, 0);
         $corner->fill(0, 0, $bg_color);
         $fg_color = $corner->allocateColor(255, 255, 255);
         $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color);
         $corner = $corner->resize($radius, $radius);
         $result = $image->asTrueColor();
         $tc = $result->getTransparentColor();
         if ($tc == -1) {
             $tc = $result->allocateColorAlpha(255, 255, 255, 127);
             imagecolortransparent($result->getHandle(), $tc);
             $result->setTransparentColor($tc);
         }
         if ($corners & GDImage::SIDE_TOP_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_TOP) {
             $result = $result->applyMask($corner, -1, -1);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_TOP_RIGHT || $corners & GDImage::SIDE_TOP || $corners & GDImage::SIDE_RIGHT) {
             $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_RIGHT || $corners & GDImage::SIDE_RIGHT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->applyMask($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         return $result;
     } else {
         $bg_color = $color;
         $corner->fill(0, 0, $bg_color);
         $fg_color = $corner->allocateColorAlpha(127, 127, 127, 127);
         $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color);
         $corner = $corner->resize($radius, $radius);
         $result = $image->copy();
         if ($corners & GDImage::SIDE_TOP_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_TOP) {
             $result = $image->merge($corner, -1, -1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_TOP_RIGHT || $corners & GDImage::SIDE_TOP || $corners & GDImage::SIDE_RIGHT) {
             $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_RIGHT || $corners & GDImage::SIDE_RIGHT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->merge($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         return $result;
     }
 }
コード例 #5
0
 /**
  * (non-PHPdoc)
  * @see GDImage_Image#copyNoAlpha()
  */
 function copyNoAlpha()
 {
     return GDImage_Image::loadFromString($this->asString('png'));
 }
コード例 #6
0
 /**
  * Copies this image onto another image
  * 
  * @param GDImage_Image $dest
  * @param int $left
  * @param int $top
  **/
 function copyTo($dest, $left = 0, $top = 0)
 {
     imageCopy($dest->getHandle(), $this->handle, $left, $top, 0, 0, $this->getWidth(), $this->getHeight());
 }
コード例 #7
0
 /**
  * (non-PHPdoc)
  * @see GDImage_Image#copyNoAlpha()
  */
 function copyNoAlpha()
 {
     $prev = $this->saveAlpha(false);
     $result = GDImage_Image::loadFromString($this->asString('png'));
     $this->saveAlpha($prev);
     //$result->releaseHandle();
     return $result;
 }
コード例 #8
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;
 }
コード例 #9
0
 /**
  * Fix a coordinate for a resize (limits by image weight and height)
  * 
  * @param GDImage_Image $img
  * @param int $width Width of the image
  * @param int $height Height of the image
  * @return array An array(width, height), fixed for resizing
  */
 static function fixForResize($img, $width, $height)
 {
     if ($width === null && $height === null) {
         return array($img->getWidth(), $img->getHeight());
     }
     if ($width !== null) {
         $width = self::fix($width, $img->getWidth());
     }
     if ($height !== null) {
         $height = self::fix($height, $img->getHeight());
     }
     if ($width === null) {
         $width = floor($img->getWidth() * $height / $img->getHeight());
     }
     if ($height === null) {
         $height = floor($img->getHeight() * $width / $img->getWidth());
     }
     return array($width, $height);
 }