Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public function __destruct()
 {
     if (is_resource(self::$resource)) {
         fclose(self::$fd);
         DestroyMagickWand(self::$resource);
     }
 }
Ejemplo n.º 3
0
/**
 * liberty_magickwand_panorama_image - strictly speaking, this belongs in one of the image processing plugin files, but we'll leave it here for the moment
 *
 * @param array $pFileHash File hash - souce_file is required
 * @param array $pOptions
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function liberty_magickwand_panorama_image(&$pFileHash, $pOptions = array())
{
    $magickWand = NewMagickWand();
    $pFileHash['error'] = NULL;
    if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) {
        if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand))) {
            // calculate border width
            $iwidth = round(MagickGetImageWidth($magickWand));
            $iheight = round(MagickGetImageHeight($magickWand));
            $aspect = $iwidth / $iheight;
            $metaHash = array('width' => $iwidth, 'height' => $iheight, 'aspect' => $aspect);
            // store original file information that we can adjust the viewer
            LibertyMime::storeMetaData($pFileHash['attachment_id'], 'PANO', $metaHash);
            // we need to pad the image if the aspect ratio is not 2:1 (give it a wee bit of leeway that we don't add annoying borders if not really needed)
            if ($aspect > 2.1 || $aspect < 1.9) {
                $bwidth = $bheight = 0;
                if ($aspect > 2) {
                    $bheight = round(($iwidth / 2 - $iheight) / 2);
                } else {
                    $bwidth = round(($iheight / 2 - $iwidth) / 2);
                }
                // if the ratio has nothing to do with a panorama image - i.e. gives us a negative number here, we won't generate a panorama image
                if ($bheight > 0) {
                    $pixelWand = NewPixelWand();
                    PixelSetColor($pixelWand, !empty($pOptions['background']) ? $pOptions['background'] : 'black');
                    if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickBorderImage($magickWand, $pixelWand, $bwidth, $bheight), $magickWand))) {
                        if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickWriteImage($magickWand, $pFileHash['source_file']), $magickWand))) {
                            // yay!
                        }
                    }
                    DestroyPixelWand($pixelWand);
                }
            }
        }
    }
    DestroyMagickWand($magickWand);
    return empty($pFileHash['error']);
}
 /**
  * Destroy the target for the provided temporary object
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  * @abstract
  */
 function __destroy_target(&$tmp)
 {
     return DestroyMagickWand($tmp->target);
 }
Ejemplo n.º 5
0
/**
 * liberty_magickwand_convert_colorspace
 * 
 * @param array $pFileHash
 * @param string $pColorSpace - target color space, only 'grayscale' is currently supported
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function liberty_magickwand_convert_colorspace_image(&$pFileHash, $pColorSpace)
{
    $ret = FALSE;
    if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) {
        $magickWand = NewMagickWand();
        if ($error = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand)) {
            bit_error_log("MagickReadImage Failed:{$error} ( {$pFileHash['source_file']} )");
        } else {
            MagickRemoveImageProfile($magickWand, "ICC");
            switch (strtolower($pColorSpace)) {
                case 'grayscale':
                    if (MagickGetImageColorspace($magickWand) == MW_GRAYColorspace) {
                        $ret = TRUE;
                    } else {
                        MagickSetImageColorspace($magickWand, MW_GRAYColorspace);
                        if (empty($pFileHash['dest_file'])) {
                            $pFileHash['dest_file'] = STORAGE_PKG_PATH . $pFileHash['dest_branch'] . $pFileHash['name'];
                        }
                        if ($error = liberty_magickwand_check_error(MagickWriteImage($magickWand, $pFileHash['dest_file']), $magickWand)) {
                            bit_error_log("MagickWriteImage Failed:{$error} ( {$pFileHash['source_file']} )");
                        } else {
                            $ret = TRUE;
                        }
                    }
                    break;
            }
        }
        DestroyMagickWand($magickWand);
    }
    return $ret;
}
Ejemplo n.º 6
0
 /**
  * Imports the given file using the MagickWand extension if possible. (Internal only)
  * @param SloodleModulePresenter $presenter An object representing the Presenter we are importing into.
  * @param string $srcfile Full path of the PDF file we are importing
  * @param string $destpath Folder path to which the imported files will be added.
  * @param string $viewurl URL of the folder in which the imported files will be viewed
  * @param string $destfile Name for the output files (excluding extension, such as .jpg). The page numbers will be appended automatically, before the extension
  * @param string $destfileext Extension for destination files, not including the dot. (e.g. "jpg" or "png").
  * @param string $destname Basic name to use for each imported slide. The page numbers will be appended automatically.
  * @param integer $position The position within the Presentation to add the new slides. Optional. Default is to put them at the end.
  * @return integer|bool If successful, an integer indicating the number of slides loaded is displayed. If the import does not (or cannot) work, then boolean false is returned.
  * @access private
  */
 function _import_MagickWand($presenter, $srcfile, $destpath, $viewurl, $destfile, $destfileext, $destname, $position = -1)
 {
     global $CFG;
     // Only continue if the MagickWand extension is loaded (this is done by the check_compatibility function)
     if (!extension_loaded('magickwand')) {
         return false;
     }
     // Load the PDF file
     sloodle_debug('Loading PDF file... ');
     $mwand = NewMagickWand();
     if (!MagickReadImage($mwand, $srcfile)) {
         sloodle_debug('failed.<br/>');
         return false;
     }
     sloodle_debug('OK.<br/>');
     // Quick validation - position should start at 1. (-ve numbers mean "at the end")
     if ($position == 0) {
         $position = 1;
     }
     // Go through each page
     sloodle_debug('Preparing to iterate through pages of document...<br/>');
     MagickSetFirstIterator($mwand);
     $pagenum = 0;
     $page_position = -1;
     do {
         // Determine this page's position in the Presentation
         if ($position > 0) {
             $page_position = $position + $pagenum;
         }
         $pagenum++;
         // Construct the file and slide names for this page
         $page_filename = "{$destpath}/{$destfile}-{$pagenum}.{$destfileext}";
         // Where it gets uploaded to
         $page_slidesource = "{$viewurl}/{$destfile}-{$pagenum}.{$destfileext}";
         // The URL to access it publicly
         $page_slidename = "{$destname} ({$pagenum})";
         // Output the file
         sloodle_debug(" Writing page {$pagenum} to file...");
         if (!MagickWriteImage($mwand, $page_filename)) {
             sloodle_debug('failed.<br/>');
         } else {
             sloodle_debug('OK.<br/>');
         }
         // Add the entry to the Presenter
         sloodle_debug("  Adding slide \"{$page_slidename}\" to presentation at position {$page_position}... ");
         if (!$presenter->add_entry($page_slidesource, 'image', $page_slidename, $page_position)) {
             sloodle_debug('failed.<br/>');
         } else {
             sloodle_debug('OK.<br/>');
         }
     } while (MagickNextImage($mwand));
     sloodle_debug('Finished.<br/>');
     DestroyMagickWand($mwand);
     return $pagenum;
 }
Ejemplo n.º 7
0
 function resize_file_MagicWand(&$file, $create)
 {
     $image = NewMagickWand();
     MagickReadImage($image, $this->upload->path . '/' . $this->orgFileName);
     MagickResizeImage($image, $this->newWidth, $this->newHeight, MW_MitchellFilter, 1);
     MagickSetImageCompressionQuality($image, $this->quality);
     //Set the extension of the new file
     $ext = $this->GetNewfileExtension();
     if (file_exists($this->upload->path . '/' . $file->name . "." . $ext) and $file->name . "." . $ext != $file->fileName and $this->upload->nameConflict == "uniq") {
         $file->setFileName($this->upload->createUniqName($file->name . "." . $ext));
     }
     if ($create == "image") {
         $fileName = $file->name . "." . $ext;
         @unlink($this->upload->path . '/' . $this->orgFileName);
         MagickWriteImage($image, $this->upload->path . '/' . $fileName);
         $file->setFileName($fileName);
     } else {
         if ($this->pathThumb == "") {
             $this->pathThumb = $this->upload->path;
         }
         if ($this->naming == "suffix") {
             $fileName = $file->name . $this->suffix . "." . $ext;
         } else {
             $fileName = $this->suffix . $file->name . "." . $ext;
         }
         MagickWriteImage($image, $this->pathThumb . '/' . $fileName);
         $file->setThumbFileName($fileName, $this->pathThumb, $this->naming, $this->suffix);
     }
     DestroyMagickWand($image);
 }
Ejemplo n.º 8
0
 public function destoryWand()
 {
     $numargs = func_num_args();
     $arg_list = func_get_args();
     for ($i = 0; $i < $numargs; $i++) {
         switch (true) {
             case IsMagickWand($arg_list[$i]):
                 DestroyMagickWand($arg_list[$i]);
                 break;
             case IsDrawingWand($arg_list[$i]):
                 DestroyDrawingWand($arg_list[$i]);
                 break;
             case IsPixelWand($arg_list[$i]):
                 DestroyPixelWand($arg_list[$i]);
                 break;
             case IsPixelIterator($arg_list[$i]):
                 DestroyPixelIterator($arg_list[$i]);
                 break;
             default:
                 break;
         }
     }
     return;
 }
Ejemplo n.º 9
0
 public function __destruct()
 {
     if (isset($this->_resource)) {
         DestroyMagickWand($this->_resource);
     }
 }
Ejemplo n.º 10
0
$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);
MagickSetLastIterator($mgck_wnd);
for ($i = $cnt_down_start; $i > 0 && $x2 - $x1 >= $x_int && $y2 - $y1 >= $y_int; $i--) {
    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);
    $red = mt_rand(0, 255);
    $green = mt_rand(0, 255);
    $blue = mt_rand(0, 255);
    $x1 += $x_int;
    $y1 += $y_int;
    $x2 -= $x_int;
    $y2 -= $y_int;
    drawNewImageSetDelay($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $cnt_down_delay, __LINE__);
    addText($txt_wnd, $white, $font_size, $i);
    checkWandError(MagickDrawImage($mgck_wnd, $txt_wnd), $mgck_wnd, __LINE__);