' Crop and Rotate ' This script crops and rotates a section of the image as defined ' by a rectangular Lasso. The script places a rectangular Lasso ' in the current image and prompts the user to place and rotate it ' such that it encompasses the area to be cropped and rotated. ' When the user clicks the Resume button in the message box ' in the top left of the screen, the image is cropped, rotated and ' recropped so there are no borders. ' Note: this script requires QFX 8 or better. ' Set this global variable to the number of pixels to ' 'fudge' the final crop rectangle size so we don't see ' a border around the final cropped image ' Tip: If you see a colored egde or border on the final ' cropped image, increase the value below $Fudge = 4 ' Make sure an image window is open If Len('$ImageName') = 0 [MSGBOX] Name="" Prompt="Please open or scan an image to crop and rotate." Title="Crop and Rotate" Buttons=Ok Icon=Exclamation [QUIT] EndIf ' Make sure there are no other Lassos in the image by ' 'stashing' any current Lassos LassoNew ' Get width and height of current image so we can create ' an initial cropping rect for the user to align $W = $ImageWidth $H = $ImageHeight ' Create a rectangle Lasso that is 10% smaller than image $W = $W * 0.9 $H = $H * 0.9 ObjRect Size=$W,$H Locate=0,0 ' Center the Lasso rectangle in image ArrangeAlign ObjHorz=None ObjVert=None SelHorz=Center SelVert=Middle Selection=No ' Select the Pick tool ToolsPick ' Put up a message box [SUSPEND] Time=0 Update=Yes Msgbox=Yes Posn=6,6,160,64 Title="Crop and Rotate" Message="Resize and rotate the Lasso rectangle to encompass the area to crop and rotate.\n\nClick Resume once the Lasso is positioned." ' Make sure the Lasso is selected and get is size and rotation EditSelectAll $W = $ObjectWidth $H = $ObjectHeight $A = $ObjectAngle ' Set the Lasso options so we get an anti-aliased crop LassoOptions Fill=Inside AntiAlias=Yes Softness=0 ' Set a black canvas color ColorCanvas RGB=0,0,0 CMYK=0,0,0,255 ' Crop the image EditCrop ' Select original image and close it WindowPrevious FileClose ' Select the cropped image WindowSelect Window="" ' Rotate the cropped image by the negative angle of the ' crop Lasso (Note: angle is in degrees X 100 so we subtract ' the angle from 3600 to get the negative angle) $A = 3600 - $A ImageResizeRotate Source=Full Scale=100.00,100.00 MinMax=No Angle=$A Units=Pixels Dpi=300 Borders=0,0,0,0 Qual=3,3 NewWin=Yes Prop=100 LockProp=Yes LockSize=No ' Select cropped image and close it WindowPrevious FileClose ' Select the rotated image WindowSelect Window="" ' Place a new rectangle Lasso in image that is slightly ' smaller than the cropping rectangle the user aligned ' so we don't get any extraneous borders on new image ObjRect Size=$W-$Fudge,$H-$Fudge Locate=0,0 ' Center the Lasso rectangle in image ArrangeAlign ObjHorz=None ObjVert=None SelHorz=Center SelVert=Middle Selection=No ' Set the Lasso options so we get a hard edge crop LassoOptions Fill=Inside AntiAlias=No Softness=0 ' Crop the image EditCrop ' Select rotated image and close it WindowPrevious FileClose ' Select the cropped image WindowSelect Window=""