program AspectTools ; { Cropping and zooming tools for printing digital photos } { IMPORTANT: Preset the base size and required aspect ratio (wide/high) below } { Copyright (C) 2008, Digital Optics Ltd, Auckland, New Zealand } toolbar 'Aspect Tools' ; const xBase = 1440 ; yBase = 960 ; Ratio = 1.5 ; var Image ; xs,ys ; xn,yn ; x1,y1,x2,y2 ; procedure ShowRatio ; button btn_Text,'Ratio|Display image aspect ratio' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; WriteInfo( 'Aspect ratio = ',( double( xs ) / ys ) ) ; end; end; { Ratio } procedure ZoomToBase ; button btn_Text,'Zoom|Zoom to the base size' ; var r ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; r := double( xs ) / ys ; xn := xBase ; yn := round( double( xn ) / r ) ; StoreUndoInfo( Image,'Zoom' ) ; Image := ZoomTo( Image,xn,yn ) ; end; end; { ZoomToBase } procedure CropTopAndBottom ; button btn_Text,'-Vertical|Crop the top and bottom evenly' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; xn := xs ; yn := round( xs / Ratio ) ; x1 := 0 ; y1 := ( ys - yn ) / 2 ; x2 := xs - 1 ; y2 := y1 + yn - 1 ; StoreUndoInfo( Image,'Crop' ) ; Image := Image[ x1..x2,y1..y2 ] ; end; end; { CropTopAndBottom } procedure CropTop ; button btn_Text,'Top|Crop the top of the image' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; xn := xs ; yn := round( xs / Ratio ) ; x1 := 0 ; y1 := ys - yn ; x2 := xs - 1 ; y2 := y1 + yn - 1 ; StoreUndoInfo( Image,'Crop' ) ; Image := Image[ x1..x2,y1..y2 ] ; end; end; { CropTop } procedure CropBottom ; button btn_Text,'Bottom|Crop the bottom of the image' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; xn := xs ; yn := round( xs / Ratio ) ; x1 := 0 ; y1 := 0 ; x2 := xs - 1 ; y2 := y1 + yn - 1 ; StoreUndoInfo( Image,'Crop' ) ; Image := Image[ x1..x2,y1..y2 ] ; end; end; { CropBottom } procedure CropLeftAndRight ; button btn_Text,'-Horizontal|Crop the left and right sides evenly' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; xn := round( ys * Ratio ) ; yn := ys ; x1 := ( xs - xn ) / 2 ; y1 := 0 ; x2 := x1 + xn - 1 ; y2 := ys - 1 ; StoreUndoInfo( Image,'Crop' ) ; Image := Image[ x1..x2,y1..y2 ] ; end; end; { CropLeftAndRight } procedure CropLeft ; button btn_Text,'Left|Crop the left side of the image' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; xn := round( ys * Ratio ) ; yn := ys ; x1 := xs - xn ; y1 := 0 ; x2 := x1 + xn - 1 ; y2 := ys - 1 ; StoreUndoInfo( Image,'Crop' ) ; Image := Image[ x1..x2,y1..y2 ] ; end; end; { CropLeft } procedure CropRight ; button btn_Text,'Right|Crop the right side of the image' ; begin GetActiveImage( Image ) ; if IsImage( Image ) then begin GetXYSize( Image,xs,ys ) ; xn := round( ys * Ratio ) ; yn := ys ; x1 := 0 ; y1 := 0 ; x2 := x1 + xn - 1 ; y2 := ys - 1 ; StoreUndoInfo( Image,'Crop' ) ; Image := Image[ x1..x2,y1..y2 ] ; end; end; { CropRight } begin end.