@ -33,7 +33,7 @@ module ImageMaker =
| true -> ( )
// This function is to be d e l e t e d .
let makeImage width height colour filepath =
let makeImageBase width height colour filepath =
async {
t r y
validateDimension w i d t h
@ -49,61 +49,53 @@ module ImageMaker =
| _ as ex -> return e x . M e s s a g e
}
let private drawMainImage spec =
use bitmap = new Bitmap (spec.width, s p e c . h e i g h t )
use graphics = Graphics.FromImage ( b i t m a p )
graphics.FillRectangle (spec.colour, new Rectangle(0, 0 , bitmap.Width, b i t m a p . H e i g h t ) )
bitmap.Save ( s p e c . f i l e P a t h )
printfn "[SUCCESS] Image s a v e d . "
let private createBorderPath spec =
[|Point (10, 10 ) ;
Point (spec.width, 10 ) ;
Point (spec.width, s p e c . h e i g h t ) ;
Point (spec.height, 10 ) ;
Point (10, 10 ) | ]
( *
Need to call dispose manually because of how the image is/can be b u i l t - u p .
need to reduce the amount of branching code... it's getting u n w i e l d y .
create b i t m a p
create g r a p h i c s
draw b a s e
check o v e r l a y
add b o r d e r
add full o v e r l a y
write image to d i s k
dispose r e s o u r c e s
write output m e s s a g e * )
let private drawImageWithBorder (graphics: Graphics) (pen: Pen) spec =
printfn "[INFO.] Adding border to i m a g e ... "
let penPath = createBorderPath s p e c
graphics.DrawLines (pen, p e n P a t h )
let private createBorderPositions spec =
[|Point (0, 0 ) ;
Point (spec.width, 0 ) ;
Point (spec.width, s p e c . h e i g h t ) ;
Point (spec.height, 0 ) ;
Point (0, 0 ) | ]
let private drawImageWithBorder spec =
let overlay = s p e c . o v e r l a y . V a l u e
use bitmap = new Bitmap (spec.width, s p e c . h e i g h t )
use graphics = Graphics.FromImage ( b i t m a p )
use pen = new Pen ( o v e r l a y . c o l o u r )
let border = createBorderPositions s p e c
graphics.DrawLines (pen, b o r d e r )
printfn "Overlay image function not f i n i s h e d . "
let private drawImageWithFullOverlay graphics pen spec =
printfn "[INFO.] Adding full overlay to i m a g e ... "
( )
let private drawImageWithFullOverlay spec = ( )
let private addOverlayToImage graphics spec =
let overlay = s p e c . o v e r l a y . V a l u e
let pen = new Pen (overlay.colour, Width = 10 .0 f )
match overlay.overlayType w i t h
| Border -> drawImageWithBorder graphics pen s p e c
| Full -> drawImageWithFullOverlay graphics pen s p e c
let private drawImageWithOverlay spec =
match spec.overlay.Value.overlayType w i t h
| Border -> drawImageWithBorder s p e c
| Full -> drawImageWithFullOverlay s p e c
let private drawImage spec =
let bitmap = new Bitmap (spec.width, s p e c . h e i g h t )
let graphics = Graphics.FromImage ( b i t m a p )
let rectangle = Rectangle (0, 0 , spec.width, s p e c . h e i g h t )
graphics.FillRectangle (spec.colour, r e c t a n g l e )
match spec.overlay.IsSome w i t h
| true -> addOverlayToImage graphics s p e c
| false -> printfn "[INFO.] No overlay specified. Creating image without o n e . "
bitmap.Save ( s p e c . f i l e P a t h )
b i t m a p . D i s p o s e ( )
g r a p h i c s . D i s p o s e ( )
let makeImage2 spec =
let makeImage spec =
async {
t r y
printfn "[INFO.] Attempting to make i m a g e ... "
validateDimension s p e c . w i d t h
validateDimension s p e c . h e i g h t
validateDirectory s p e c . f i l e P a t h
match Option.isSome spec.overlay w i t h
| true -> drawImageWithOverlay s p e c
| false -> drawMainImage s p e c
return "[SUCCESS] Image creation attempt c o m p l e t e . "
drawImage s p e c
printfn "[SUCCESS] Image creation attempt c o m p l e t e . "
return ( )
w i t h
| :? ArgumentException as ex -> return e x . M e s s a g e
| _ as ex -> return e x . M e s s a g e
}
| :? ArgumentException as ex -> printfn "%s" e x . M e s s a g e
| _ as ex -> printfn "%s" e x . M e s s a g e
}