/** * 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']); }
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; }