コード例 #1
0
ファイル: ImgLib.php プロジェクト: sinkcup/choose-api
 public static function makeGifFromZip($zip_file_path, $delay)
 {
     $dir = $zip_file_path . 'dir/';
     $zip = new ZipArchive();
     $res = $zip->open($zip_file_path);
     if ($res === TRUE) {
         $zip->extractTo($dir);
         $zip->close();
     }
     $files = glob($dir . '/*');
     ksort($files);
     $mw = NewMagickWand();
     for ($i = 0, $l = count($files); $i < $l; $i++) {
         $rw = NewMagickWand();
         MagickReadImage($rw, $files[$i]);
         MagickSetImageDelay($rw, intval($delay) / 10);
         //magickwand比较特殊,>用的不是毫秒,所以毫秒需要转成1/100秒
         MagickAddImage($mw, $rw);
         DestroyMagickWand($rw);
     }
     MagickSetFormat($mw, 'gif');
     $gif_file_path = $zip_file_path . '.gif';
     MagickWriteImages($mw, $gif_file_path, true);
     DestroyMagickWand($mw);
     //todo 删除目录
     return $gif_file_path;
 }
コード例 #2
0
 public function convertToJpg($srcFile, $desFile = "", $quality = 60)
 {
     if (empty($desFile)) {
         $desFile = str_replace(substr(strrchr($srcFile, "."), 1), "", $srcFile) . "jpg";
     }
     $img = $this->getImgWand($srcFile);
     if (MagickGetNumberImages($img) > 1) {
         MagickResetIterator($img);
         MagickNextImage($img);
         $frame = $this->getImgWand();
         MagickAddImage($frame, $img);
         DestroyMagickWand($img);
         $img = $frame;
     }
     MagickSetFormat($img, 'JPG');
     MagickSetImageCompression($img, MW_JPEGCompression);
     MagickSetImageCompressionQuality($img, $quality);
     $this->generateImg($img, $desFile);
     return $desFile;
 }
コード例 #3
0
ファイル: demo.php プロジェクト: nateirwin/custom-historic
    DrawSetFontSize($txt_wnd, $font_size);
    $logo_width =& checkWandError(MagickGetStringWidth($mgck_wnd, $txt_wnd, $logo), $mgck_wnd, __LINE__);
    $welcome_msg_width =& checkWandError(MagickGetStringWidth($mgck_wnd, $txt_wnd, $welcome_msg), $mgck_wnd, __LINE__);
    if ($logo_width < $width && $welcome_msg_width < $width) {
        break;
    }
    $font_size--;
}
$pre_morph_wnd =& checkWandError(MagickGetImage($mgck_wnd), $mgck_wnd, __LINE__);
addText($txt_wnd, $white, $font_size, $logo);
drawNewImage($pre_morph_wnd, $txt_wnd, $width, $height, $bg_color, __LINE__);
ClearDrawingWand($txt_wnd);
addText($txt_wnd, $white, $font_size, $welcome_msg);
drawNewImage($pre_morph_wnd, $txt_wnd, $width, $height, $bg_color, __LINE__);
MagickSetFirstIterator($mgck_wnd);
checkWandError(MagickAddImage($pre_morph_wnd, $mgck_wnd), $pre_morph_wnd, __LINE__);
addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, __LINE__);
DestroymagickWand($pre_morph_wnd);
DestroyDrawingWand($drw_wnd);
DestroyDrawingWand($txt_wnd);
checkWandError(MagickSetFormat($mgck_wnd, 'GIF'), $mgck_wnd, __LINE__);
header('Content-Type: ' . MagickGetMimeType($mgck_wnd));
MagickEchoImagesBlob($mgck_wnd);
DestroymagickWand($mgck_wnd);
/* ********** Function Declarations ********** */
/**
 * Function checkWandError() compares the value of $result, which should be
 * the result of any MagickWand API function, to explicit FALSE, and if it is
 * FALSE, checks if $wand for contains an error condition (in case the API
 * function is just returning FALSE as a normal return value).
 *