function resize($source_name, $width = "", $height = "", $save_name = "")
 {
     $resource = NewMagickWand();
     MagickReadImage($resource, $source_name);
     $src_image_x = MagickGetImageWidth($resource);
     $src_image_y = MagickGetImageHeight($resource);
     $src_image_scale = $src_image_x / $src_image_y;
     if ($width && $height) {
         $new_image_x = $width;
         $new_image_y = $height;
     } else {
         if ($width) {
             $new_image_x = $width;
             $new_image_y = $new_image_x * ($src_image_y / $src_image_x);
         } else {
             $new_image_y = $height;
             $new_image_x = $new_image_y * ($src_image_x / $src_image_y);
         }
     }
     MagickResizeImage($resource, $new_image_x, $new_image_y, MW_BoxFilter, 1);
     if ($save_name) {
         MagickWriteImage($resource, $save_name);
     } else {
         header('Content-Type: image/jpeg');
         MagickEchoImageBlob($resource);
     }
     DestroymagickWand($resource);
 }
Esempio n. 2
0
 /**
  * 获取图片内容
  */
 public function getContent()
 {
     ob_start();
     MagickEchoImageBlob(self::$resource);
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
Esempio n. 3
0
 public function generateImg($img, $desFile = "")
 {
     MagickCommentImage($img, "Image Creator (MagickWand) By Windy2000");
     $type = MagickGetImageFormat($img);
     $frame_count = MagickGetNumberImages($img);
     if (empty($type)) {
         $type = $frame_count > 1 ? "GIF" : "JPG";
     }
     if (strpos("tile,gradient,caption,label,logo,netscape,rose", strtolower($type)) !== false) {
         $type = "PNG";
     }
     MagickSetFormat($img, $type);
     if (empty($desFile)) {
         //header("Content-Type: ".MagickGetMimeType($img));
         if ($frame_count > 1) {
             MagickEchoImagesBlob($img);
         } else {
             MagickEchoImageBlob($img);
         }
     } else {
         if ($frame_count > 1) {
             MagickWriteImages($img, $desFile, MagickTrue);
         } else {
             MagickWriteImage($img, $desFile);
         }
     }
     if (WandHasException($img)) {
         $this->Error($img);
     }
     $result = MagickGetExceptionType($img);
     DestroyMagickWand($img);
     return $result;
 }
Esempio n. 4
0
 function savefile($src_image_type, $src_image)
 {
     if ($this->save_file) {
         MagickWriteImage($src_image, $this->save_file);
     } else {
         switch ($src_image_type) {
             case 1:
                 header("Content-type: image/gif");
                 MagickEchoImageBlob($src_image);
                 break;
             case 2:
                 header("Content-type: image/jpeg");
                 MagickEchoImageBlob($src_image);
                 break;
             case 3:
                 header("Content-type: image/png");
                 MagickEchoImageBlob($src_image);
                 break;
             case 6:
                 header("Content-type: image/bmp");
                 MagickEchoImageBlob($src_image);
                 break;
             default:
                 header("Content-type: image/jpeg");
                 MagickEchoImageBlob($src_image);
                 break;
         }
     }
 }