/** * liberty_magickwand_check_error * * @param array $pResult * @param array $pWand * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_magickwand_check_error($pResult, $pWand) { $ret = FALSE; if ($pResult === FALSE && WandHasException($pWand)) { $ret = 'An image processing error occurred : ' . WandGetExceptionString($pWand); } return $ret; }
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; }
public function convert($ps_format, $ps_orig_filepath, $ps_dest_filepath) { $vs_filepath = $vs_ext = ""; # # First make sure the original file is an image # if (!($vs_mimetype = $this->test($ps_orig_filepath, ""))) { return false; } if ($vs_mimetype == "application/pdf") { return false; } $va_dest_path_pieces = explode("/", $ps_dest_filepath); $vs_dest_filestem = array_pop($va_dest_path_pieces); $vs_dest_dir = join("/", $va_dest_path_pieces); $vn_width = $vn_height = null; switch ($ps_format) { # ------------------------------------ case 'image/jpeg': $vs_ext = "jpg"; $vs_filepath = $vs_dest_filestem . "_conv." . $vs_ext; switch ($this->backend) { case LIBRARY_GD: if ($vs_mimetype = $this->test($ps_orig_filepath)) { switch ($vs_mimetype) { case "image/jpeg": $rsource = imagecreatefromjpeg($ps_orig_filepath); break; case "image/png": $rsource = imagecreatefrompng($ps_orig_filepath); break; case "image/gif": $rsource = imagecreatefromgif($ps_orig_filepath); break; default: return false; break; } if (!$r) { return false; } list($vn_width, $vn_height) = getimagesize($ps_orig_filepath); if ($vn_width > $vn_height) { $vn_ratio = $vn_height / $vn_width; $vn_target_width = 800; $vn_target_height = 800 * $vn_ratio; } else { $vn_ratio = $vn_width / $vn_height; $vn_target_height = 800; $vn_target_width = 800 * $vn_ratio; } if (!($rdest = imagecreatetruecolor($vn_target_width, $vn_target_height))) { return false; } if (!imagecopyresampled($rdest, $rsource, 0, 0, 0, 0, $vn_target_width, $vn_target_height, $vn_width, $vn_height)) { return false; } if (!imagejpeg($rdest, $vs_dest_dir . "/" . $vs_filepath)) { return false; } } else { return false; } break; default: $handle = NewMagickWand(); if (MagickReadImage($handle, $ps_orig_filepath)) { if (WandHasException($handle)) { return false; } $vn_width = MagickGetImageWidth($handle); $vn_height = MagickGetImageHeight($handle); if ($vn_width > $vn_height) { $vn_ratio = $vn_height / $vn_width; $vn_target_width = 800; $vn_target_height = 800 * $vn_ratio; } else { $vn_ratio = $vn_width / $vn_height; $vn_target_height = 800; $vn_target_width = 800 * $vn_ratio; } if (!MagickResizeImage($handle, $vn_target_width, $vn_target_height, MW_CubicFilter, 1)) { return false; } if (!MagickWriteImage($handle, $vs_dest_dir . "/" . $vs_filepath)) { return false; } } break; } break; # ------------------------------------ # ------------------------------------ default: return false; break; # ------------------------------------ } return array("extension" => $vs_ext, "format_name" => $this->info["CONVERSIONS"][$ps_format]["format_name"], "dangerous" => 0, "width" => $vn_width, "height" => $vn_height, "long_format_name" => $this->info["CONVERSIONS"][$ps_format]["long_format_name"]); }
/** * 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). * * If the return value is FALSE, and the $wand contains a set error condition, * the function outputs the error and forcibly ends the program. * * If not, returns $result as a reference. * * @param mixed MagickWand API function result * @param resource Any MagickWand API resource * @param int Always __LINE__ (script current line number predefined * PHP constant) * * @return reference Returns reference to 1st argument (if no errors found) */ function &checkWandError(&$result, $wand, $line) { if ($result === FALSE && WandHasException($wand)) { echo '<pre>An error occurred on line ', $line, ': ', WandGetExceptionString($wand), '</pre>'; exit; } return $result; }