function addText($source_name, $string, $save_name = "", $font_height = 30, $text_align = "center", $color = "#ff0000", $font = "Arial", $Antialias = true)
 {
     $resource = NewMagickWand();
     $drw_wnd = NewDrawingWand();
     MagickReadImage($resource, $source_name);
     //MagickResizeImage( $resource, 160, 120 ,MW_BoxFilter,1);
     DrawSetFillColor($drw_wnd, $color);
     DrawSetFontSize($drw_wnd, $font_height);
     DrawSetFont($drw_wnd, $font);
     DrawSetTextAntialias($drw_wnd, $Antialias);
     $src_image_x = MagickGetImageWidth($resource);
     $src_image_y = MagickGetImageHeight($resource);
     $string_width = MagickGetStringWidth($resource, $drw_wnd, $string, FALSE);
     $string_height = MagickGetStringHeight($resource, $drw_wnd, $string, FALSE);
     switch ($text_align) {
         case "center":
             $text_x = $src_image_x / 2 - $string_width / 2;
             $text_y = $src_image_y / 2 - $string_height / 2;
             break;
         default:
             break;
     }
     DrawAnnotation($drw_wnd, $text_x, $text_y, $string);
     MagickDrawImage($resource, $drw_wnd);
     if ($save_name) {
         MagickWriteImage($resource, $save_name);
     } else {
         header('Content-Type: image/jpeg');
         MagickEchoImageBlob($resource);
     }
     DestroyDrawingWand($drw_wnd);
     DestroymagickWand($resource);
 }
Пример #2
0
 /**
  * 画一条线
  * @param int $sx     起始坐标x
  * @param int $sy     起始坐标y
  * @param int $ex     终止坐标y
  * @param int $ey     终止坐标y
  * @param int $border 线条宽度
  */
 public function drawLine($sx, $sy, $ex, $ey, $property = array())
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $color = NewPixelWand(isset($property['color']) ? $property['color'] : 'black');
     $fillColor = NewPixelWand(isset($property['fillColor']) ? $property['fillColor'] : 'none');
     $backgroundColor = NewPixelWand(isset($property['fillColor']) ? $property['backgroundColor'] : 'none');
     $picWand = NewMagickWand();
     MagickNewImage($picWand, $width, $height, $backgroundColor);
     $drawWand = NewDrawingWand();
     DrawSetFillColor($drawWand, $fillColor);
     DrawSetStrokeWidth($drawWand, isset($property['borderWidth']) ? $property['borderWidth'] : 1);
     DrawSetStrokeColor($drawWand, $color);
     if (isset($property['stroke'])) {
         DrawSetStrokeDashArray($drawWand, $property['stroke']);
     }
     DrawLine($drawWand, $sx, $sy, $ex, $ey);
     MagickDrawImage($picWand, $drawWand);
     return MagickCompositeImage(self::$resource, $picWand, MW_OverCompositeOp, $x, $y);
 }
Пример #3
0
 public function fixSize(&$img, $fix_width = 0, $fix_height = 0, $fix_top = 0, $fix_left = 0, $bgcolor = "white", $fix_mode = false)
 {
     if ($fix_width == 0 && $fix_height == 0) {
         return;
     }
     $width = MagickGetImageWidth($img);
     $height = MagickGetImageHeight($img);
     if ($fix_mode) {
         $fix_width += $width;
         $fix_height += $height;
     } else {
         if ($fix_width == 0) {
             $fix_width = $width;
         }
         if ($fix_height == 0) {
             $fix_height = $height;
         }
     }
     $result = NewMagickWand();
     MagickResetIterator($img);
     while (MagickNextImage($img)) {
         $drawWand = NewDrawingWand();
         DrawComposite($drawWand, MW_AddCompositeOp, $fix_left, $fix_top, $width, $height, $img);
         $frame = $this->getImgWand(array($bgcolor, $fix_width, $fix_height));
         MagickDrawImage($frame, $drawWand);
         MagickSetImageDelay($frame, MagickGetImageDelay($img));
         MagickAddImage($result, $frame);
     }
     $this->destoryWand($img, $imgTemp, $drawWand);
     $img = $result;
     return;
 }
Пример #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;
 }
Пример #5
0
$x_radius = $y_radius = 10;
$font_size = 30;
$swirl_deg_start = 0;
$swirl_deg_end = 360;
$swirl_deg_int = 60;
$swirl_delay = 10;
$num_morph_frames = 5;
$morph_delay = 20;
$logo = 'MagickWand for PHP';
$welcome_msg = 'The future awaits...';
$mgck_wnd = NewMagickWand();
$bg_color = NewPixelWand();
$white = NewPixelWand('white');
$pxl_wnd = NewPixelWand();
$drw_wnd = NewDrawingWand();
$txt_wnd = NewDrawingWand();
for ($i = 0; $i < $noise_frames; $i++) {
    checkWandError(MagickNewImage($mgck_wnd, $width, $height, $bg_color), $mgck_wnd, __LINE__);
    checkWandError(MagickAddNoiseImage($mgck_wnd, MW_LaplacianNoise), $mgck_wnd, __LINE__);
    checkWandError(MagickSetImageDelay($mgck_wnd, $noise_delay), $mgck_wnd, __LINE__);
}
$pre_morph_wnd =& checkWandError(MagickGetImage($mgck_wnd), $mgck_wnd, __LINE__);
$red = mt_rand(0, 255);
$green = mt_rand(0, 255);
$blue = mt_rand(0, 255);
checkWandError(PixelSetColor($pxl_wnd, "rgb({$red}, {$green}, {$blue})"), $pxl_wnd, __LINE__);
DrawSetFillColor($drw_wnd, $pxl_wnd);
DrawRoundRectangle($drw_wnd, $x1, $y1, $x2, $y2, $x_radius, $y_radius);
drawNewImageSetDelay($pre_morph_wnd, $drw_wnd, $width, $height, $bg_color, $morph_delay, __LINE__);
addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, __LINE__);
DestroyMagickWand($pre_morph_wnd);