Exemplo n.º 1
0
 public function getImgWand($resource = "", $size = array())
 {
     $result = NewMagickWand();
     if (count($size) == 2) {
         MagickSetWandSize($result, $size[0], $size[1]);
     }
     if (IsMagickWand($resource)) {
         $result = CloneMagickWand($resource);
     } elseif (is_array($resource) && count($resource) == 3) {
         MagickNewImage($result, $resource[1], $resource[2], $resource[0]);
     } elseif (!empty($resource)) {
         MagickReadImage($result, $resource);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * 读取图片
  * @param string $image 图片路径
  */
 public function setImage($image)
 {
     if (is_string($image)) {
         $opts = array('http' => array('timeout' => 5));
         $context = stream_context_create($opts);
         $times = 0;
         do {
             self::$fd = fopen($image, 'r', $include_path = false, $context);
             if (++$times >= 3) {
                 break;
             }
         } while (self::$fd === false);
         MagickReadImageFile(self::$resource, self::$fd);
         self::$resourcek = CloneMagickWand(self::$resource);
     } else {
         if (is_array($image)) {
             MagickNewImage(self::$resource, $image['width'], $image['height'], $image['backgroundColor']);
             MagickSetFormat(self::$resource, $image['format']);
         }
     }
 }
 /**
  * Get canvas
  *
  * @param integer $width
  * @param integer $height
  * @param Asido_Color &$color
  * @return Asido_TMP
  * @access protected
  */
 function __canvas($width, $height, &$color)
 {
     $t = new Asido_TMP();
     $t->target = NewMagickWand();
     list($r, $g, $b) = $color->get();
     MagickNewImage($t->target, $width, $height, sprintf("#%02x%02x%02x", $r, $g, $b));
     $t->image_width = $width;
     $t->image_height = $height;
     return $t;
 }
Exemplo n.º 4
0
 function createThumb($objWidth, $objHeight, $nmw = "")
 {
     $srcImage = $this->src_image_name;
     if (!IsMagickWand($nmw)) {
         $nmw = NewMagickWand();
         MagickReadImage($nmw, $srcImage);
     }
     $srcImageWidth = MagickGetImageWidth($nmw);
     $srcImageHeight = MagickGetImageHeight($nmw);
     if ($objWidth == 0 || $objHeight == 0) {
         $objWidth = $srcImageWidth;
         $objHeight = $srcImageHeight;
     }
     if ($objWidth < $objHeight) {
         $mu = $srcImageWidth / $objWidth;
         $objHeight = ceil($srcImageHeight / $mu);
     } else {
         $mu = $srcImageHeight / $objHeight;
         $objWidth = ceil($srcImageWidth / $mu);
     }
     MagickScaleImage($nmw, $objWidth, $objHeight);
     $ndw = NewDrawingWand();
     DrawComposite($ndw, MW_AddCompositeOp, 0, 0, $objWidth, $objHeight, $nmw);
     $res = NewMagickWand();
     MagickNewImage($res, $objWidth, $objHeight);
     MagickDrawImage($res, $ndw);
     MagickSetImageFormat($res, MagickGetImageFormat($nmw));
     return $res;
 }
Exemplo n.º 5
0
/**
 * Function drawNewImage() creates a new image, using MagickNewImage(), of
 * $width * $height area, filled with $bg_color (a PixelWand, or ImageMagick
 * color string) color.
 *
 * It then uses MagickDrawImage() to draw the commands contained in the
 * DrawingWand $drw_wnd on the newly reated image.
 *
 * @param resource    MagickWand resource
 * @param resource    DrawingWand resource
 * @param int         width of new image
 * @param int         height of new image
 * @param mixed       PixelWand resource or imagemagick color string
 * @param int         Always __LINE__ (script current line number predefined
 *                        PHP constant)
 *
 * @return void
 */
function drawNewImage($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $line)
{
    $line = 'program line ' . $line . ', function line ';
    checkWandError(MagickNewImage($mgck_wnd, $width, $height, $bg_color), $mgck_wnd, $line . __LINE__);
    checkWandError(MagickDrawImage($mgck_wnd, $drw_wnd), $mgck_wnd, $line . __LINE__);
}