$imageHeight * $sy) { $sy = ($sy / $sx); $sx = 1; error_log("X Is normal", 0); } else if ($imageWidth * $sx < $imageHeight * $sy){ $sx = ($sx / $sy); $sx = 1; error_log("Y Is normal", 0); } else { $sx = 1; $sy = 1; error_log("Both are normal", 0); } MagickResizeImage($wnd, ($sx * $imageWidth), ($sy * $imageHeight), MW_CubicFilter, 0.5); } else { error_log("SX == SY", 0); } /* $hype = sqrt(($fWidth * $fWidth) + ($fHeight * $fHeight)); if ($imageWidth > $imageHeight) { $aspectRatio = ($sx * $imageWidth) / $hype; } else { $aspectRatio = ($sx * $imageHeight) / $hype; } $newAspectWidth = ($sx * $imageWidth) / $aspectRatio; $newAspectHeight = ($sx * $imageHeight) / $aspectRatio; error_log("Start Aspect Resize", 0); MagickResizeImage($wnd, $newAspectWidth, $newAspectHeight, MW_CubicFilter, 0.5); error_log("End Aspect Resize", 0); */ error_log("Aspect Image Width: ". MagickGetImageWidth($wnd), 0); error_log("Aspect Image Height: ". MagickGetImageHeight($wnd), 0); error_log("Starting Rotation: ".$rotation, 0); MagickRotateImage($wnd, $transparentColor, $rotation); error_log("Ending Rotation", 0); error_log("Rotated Image Width: ". MagickGetImageWidth($wnd), 0); error_log("Rotated Image Height: ". MagickGetImageHeight($wnd), 0); } if($x<0){ $mergeWidth = $fWidth+$x; $dx = 0; $sx = -$x; }else{ $mergeWidth = $fWidth; $dx = $x; $sx = 0; } if($y<0){ $mergeHeight = $fHeight+$y; $dy = 0; $sy = -$y; }else{ $mergeHeight = $fHeight; $dy = $y; $sy = 0; } error_log("Processing: ".$file, 0); error_log("SX: ".$sx, 0); error_log("SY: ".$sy, 0); error_log("DX: ".$dx, 0); error_log("DY: ".$dy, 0); error_log("fWidth: ".$fWidth, 0); error_log("fHeight: ".$fHeight, 0); error_log("alpha: ".$alpha, 0); error_log("mergeWidth: ".$mergeWidth, 0); error_log("mergeHeight: ".$mergeHeight, 0); error_log("rotation: ".$rotation, 0); error_log("Starting Resize", 0); $blur = 0.3; $resizeRatio = (($fWidth + $fHeight) / 2) / (($imageWidth + $imageHeight / 2)); if ($resizeRatio > 2) { //If the image is much bigger... $blur = .7; } else if ($resizeRatio < 2 && $resizeRatio > 1) { $blur = .5; } error_log("resizeRatio: ".$resizeRatio, 0); error_log("Blur: ".$blur, 0); MagickResizeImage($wnd, $fWidth, $fHeight, MW_CubicFilter, $blur); error_log("Resize Done", 0); /* crop image place image with alpha repeat */ MagickCropImage($wnd, $mergeWidth, $mergeHeight, $sx, $sy); error_log("MagickCropImage", 0); //MagickSetImageOpacity($wnd, ($alpha/100)); MagickEvaluateImage($wnd, MW_DivideEvaluateOperator, (100/$alpha), MW_AlphaChannel); error_log("MagickSetImageOpacity", 0); MagickCompositeImage($background, $wnd, MW_DissolveCompositeOp, $dx, $dy); error_log("MagickCompositeImage", 0); DestroyMagickWand($wnd); error_log("DestroyMagickWand", 0); } if(!empty($infoLayer) && file_exists($infoLayer)){ error_log("Info Layer: ".$infoLayer, 0); $infoWnd = NewMagickWand(); MagickReadImage($infoWnd, $infoLayer); $infoImageWidth = MagickGetImageWidth($infoWnd); $infoImageHeight = MagickGetImageHeight($infoWnd); if ($infoImageWidth != $bgrWidth || $infoImageHeight != $bgrHeight) { error_log("Start Info Layer Resize", 0); MagickResizeImage($infoWnd, $bgrWidth, $bgrHeight, MW_CubicFilter, 0.5); error_log("End Info Layer Resize", 0); } error_log("Start Info Layer Composite", 0); MagickCompositeImage($background, $infoWnd, MW_DissolveCompositeOp, 0, 0); error_log("End Info Layer Composite", 0); DestroyMagickWand($infoWnd); error_log("Destroy Info Layer", 0); } try { //add cut template calibration $margin = 100; $diameter = 75; $draw = NewDrawingWand(); $drawBackgroundColor = NewPixelWand(); PixelSetColor($drawBackgroundColor, "white"); DrawSetFillColor($draw, $drawBackgroundColor); DrawSetStrokeColor($draw, $drawBackgroundColor); DrawSetStrokeWidth($draw, 1); DrawSetStrokeAntialias($draw, FALSE); error_log("Set Rect Attribs", 0); DrawRectangle($draw, 0, 0, $bgrWidth, $margin); DrawRectangle($draw, 0, $bgrHeight, $bgrWidth, ($bgrHeight - $margin)); DrawRectangle($draw, 0, 0, $margin, $bgrHeight); DrawRectangle($draw, $bgrWidth-$margin,0, $bgrWidth, $bgrHeight); error_log("Draw Rectangles", 0); MagickDrawImage($background, $draw); error_log("Draw Image", 0); $drawCircleColor = NewPixelWand(); PixelSetColor($drawCircleColor, "black"); error_log("Create Pixel Colors", 0); DrawSetFillColor($draw, $drawCircleColor); DrawSetStrokeColor($draw, $drawCircleColor); DrawSetStrokeWidth($draw, 0); DrawSetStrokeAntialias($draw, TRUE); error_log("Set Circle Attribs", 0); DrawEllipse($draw, 37, 37, 37, 37, 0, 360); DrawEllipse($draw, ($bgrWidth - 38), 37, 37, 37, 0, 360); DrawEllipse($draw, ($bgrWidth - 38), ($bgrHeight/2), 37, 37, 0, 360); DrawEllipse($draw, ($bgrWidth - 38), ($bgrHeight - 38), 37, 37, 0, 360); DrawEllipse($draw, 37, ($bgrHeight - 38), 37, 37, 0, 360); error_log("Draw Circles", 0); MagickDrawImage($background, $draw); error_log("Draw Image", 0); error_log("End Adding Print Calibration", 0); } catch(Exception $z){ $error = "Could not create image calibration template"; } error_log("Saving: ".$finalFileName, 0); //imagepng($background, $relativeGraphicsPath.$finalFileName); MagickSetImageCompression($background, MW_JPEGCompression); MagickSetImageCompressionQuality($background, 100); MagickWriteImage($background, $relativeGraphicsPath.$finalFileName); DestroyMagickWand($background); error_log("Saved: ".$finalFileName, 0); unset($background); } ?>