Example #1
0
/**
 * Function addMorphedImages() morphs the images in $pre_morph_wnd, with
 * $num_morph_frames intermediary frames. The new sequence's images are then
 * set to display for $morph_delay 100th's of a second, and then added to the
 * end of $mgck_wnd's image list.
 *
 * @param resource    MagickWand resource
 * @param resource    MagickWand resource
 * @param int         number of intermediary frames desired between the images
 *                        to be morphed
 * @param int         desired length of time (in hundredths of a second) that
 *                        each frame in the newly morphed sequence will be
 *                        displayed
 * @param int         Always __LINE__ (script current line number predefined
 *                        PHP constant)
 *
 * @return void
 */
function addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, $line)
{
    $line = 'program line ' . $line . ', function line ';
    MagickSetFirstIterator($pre_morph_wnd);
    $morph_wnd =& checkWandError(MagickMorphImages($pre_morph_wnd, $num_morph_frames), $pre_morph_wnd, $line . __LINE__);
    MagickSetFirstIterator($morph_wnd);
    checkWandError(MagickRemoveImage($morph_wnd), $morph_wnd, $line . __LINE__);
    MagickSetLastIterator($morph_wnd);
    checkWandError(MagickRemoveImage($morph_wnd), $morph_wnd, $line . __LINE__);
    MagickResetIterator($morph_wnd);
    while (MagickNextImage($morph_wnd)) {
        checkWandError(MagickSetImageDelay($morph_wnd, $morph_delay), $morph_wnd, $line . __LINE__);
    }
    MagickSetLastIterator($morph_wnd);
    MagickSetLastIterator($mgck_wnd);
    checkWandError(MagickAddImages($mgck_wnd, $morph_wnd), $mgck_wnd, $line . __LINE__);
    DestroymagickWand($morph_wnd);
}
 /**
  * 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;
 }
Example #3
0
/**
 * Function addMorphedImages() morphs the images in $pre_morph_wnd, with
 * $num_morph_frames intermediary frames. The new sequence's images are then
 * set to display for $morph_delay 100th's of a second, and then added to the
 * end of $mgck_wnd's image list.
 *
 * @param resource    MagickWand resource
 * @param resource    MagickWand resource
 * @param int         number of intermediary frames desired between the images
 *                        to be morphed
 * @param int         desired length of time (in hundredths of a second) that
 *                        each frame in the newly morphed sequence will be
 *                        displayed
 * @param int         Always __LINE__ (script current line number predefined
 *                        PHP constant)
 *
 * @return void
 */
function addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, $line)
{
    $line = 'program line ' . $line . ', function line ';
    /* Set the current active image in the $mgck_wnd MagickWand to the first
          image in its image list
       */
    MagickSetFirstIterator($pre_morph_wnd);
    /* Perform the morph special effect on $pre_morph_wnd and assign the result
          to $morph_wnd
       */
    $morph_wnd =& checkWandError(MagickMorphImages($pre_morph_wnd, $num_morph_frames), $pre_morph_wnd, $line . __LINE__);
    /* Set the current active image in the $morph_wnd MagickWand to the first
          image in its image list and remove it.
       */
    MagickSetFirstIterator($morph_wnd);
    checkWandError(MagickRemoveImage($morph_wnd), $morph_wnd, $line . __LINE__);
    /* Set the current active image in the $morph_wnd MagickWand to the last
          image in its image list and remove it.
       */
    MagickSetLastIterator($morph_wnd);
    checkWandError(MagickRemoveImage($morph_wnd), $morph_wnd, $line . __LINE__);
    /* Reset $morph_wnd's image list iterator; this has the effect that the
           next call to MagickNextImage($morph_wnd) sets $morph_wnd's current
           active image index to 0, i.e., to the first image.
    
           Contrast this behavior to MagickSetFirstIterator()'s, which sets the
           current active image's index to 0, causing the next call to
           MagickNextImage() to actually set the image index to 1, i.e., the
           second image in the MagickWand in question.
    
           This is an important distinction -- be careful.
        */
    MagickResetIterator($morph_wnd);
    while (MagickNextImage($morph_wnd)) {
        /*
           Set the length of time the current active image is displayed to
           $morph_delay hundredths of a second.
        */
        checkWandError(MagickSetImageDelay($morph_wnd, $morph_delay), $morph_wnd, $line . __LINE__);
    }
    MagickSetLastIterator($morph_wnd);
    /* Add the images in $morph_wnd to the end of $mgck_wnd */
    MagickSetLastIterator($mgck_wnd);
    checkWandError(MagickAddImages($mgck_wnd, $morph_wnd), $mgck_wnd, $line . __LINE__);
    DestroymagickWand($morph_wnd);
}