/** * @return Uploader */ public function prepare() { if (is_array($this->session)) { $this->digital = (string) $this->session['digital']; $this->public = (bool) $this->session['fg_publico']; } else { throw new Exception('Não foi possível recuperar os dados da sessão!'); } if ($this->_isFile()) { $this->hash = (string) hash_file('md5', $this->file["tmp_name"]); $this->type = (string) substr($this->file["name"], -3); $this->size = (int) $this->file["size"]; try { MagickReadImage($object = NewMagickWand(), $this->file["tmp_name"]); $this->width = MagickGetImageWidth($object); $this->height = MagickGetImageHeight($object); $this->codeType = MagickGetImageFormat($object); $this->sizeBytes = MagickGetImageSize($object); $this->compression = MagickGetImageCompression($object); $this->compressionQuality = MagickGetImageCompressionQuality($object); $this->resolution = MagickGetImageResolution($object); $this->resolutionUnits = MagickGetImageUnits($object); } catch (Exception $e) { throw new Exception('Ocorreu um erro!'); } } else { throw new Exception('O arquivo está ausente!'); } return $this; }
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; }
function createThumb($objWidth, $objHeight, $nmw = "") { $srcImage = $this->src_image_name; if (!IsMagickWand($nmw)) { $nmw = NewMagickWand(); MagickReadImage($nmw, $srcImage); } $srcImageWidth = MagickGetImageWidth($nmw); $srcImageHeight = MagickGetImageHeight($nmw); if ($objWidth == 0 || $objHeight == 0) { $objWidth = $srcImageWidth; $objHeight = $srcImageHeight; } if ($objWidth < $objHeight) { $mu = $srcImageWidth / $objWidth; $objHeight = ceil($srcImageHeight / $mu); } else { $mu = $srcImageHeight / $objHeight; $objWidth = ceil($srcImageWidth / $mu); } MagickScaleImage($nmw, $objWidth, $objHeight); $ndw = NewDrawingWand(); DrawComposite($ndw, MW_AddCompositeOp, 0, 0, $objWidth, $objHeight, $nmw); $res = NewMagickWand(); MagickNewImage($res, $objWidth, $objHeight); MagickDrawImage($res, $ndw); MagickSetImageFormat($res, MagickGetImageFormat($nmw)); return $res; }