public function fixSize(&$img, $fix_width = 0, $fix_height = 0, $fix_top = 0, $fix_left = 0, $bgcolor = "white", $fix_mode = false) { if ($fix_width == 0 && $fix_height == 0) { return; } $width = MagickGetImageWidth($img); $height = MagickGetImageHeight($img); if ($fix_mode) { $fix_width += $width; $fix_height += $height; } else { if ($fix_width == 0) { $fix_width = $width; } if ($fix_height == 0) { $fix_height = $height; } } $result = NewMagickWand(); MagickResetIterator($img); while (MagickNextImage($img)) { $drawWand = NewDrawingWand(); DrawComposite($drawWand, MW_AddCompositeOp, $fix_left, $fix_top, $width, $height, $img); $frame = $this->getImgWand(array($bgcolor, $fix_width, $fix_height)); MagickDrawImage($frame, $drawWand); MagickSetImageDelay($frame, MagickGetImageDelay($img)); MagickAddImage($result, $frame); } $this->destoryWand($img, $imgTemp, $drawWand); $img = $result; return; }
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; }