Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created January 27, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninjarobot/a4c14bd2ba27a5e6507e to your computer and use it in GitHub Desktop.
Save ninjarobot/a4c14bd2ba27a5e6507e to your computer and use it in GitHub Desktop.
Image from text in fsharp
open System.Drawing
[<EntryPoint>]
let main argv =
let text = argv.[0]
use font = new Font("Courier New", 72.0f * 5.0f, FontStyle.Bold)
let getTextSize str =
use b = new Bitmap (1, 1)
use g = b |> Graphics.FromImage
g.MeasureString (str, font)
let textSize = text |> getTextSize
use b = new Bitmap (textSize.Width |> int32, textSize.Height |> int32)
use g = b |> Graphics.FromImage
Color.Black |> g.Clear
use textBrush = new SolidBrush (Color.LightGreen)
g.DrawString (text, font, textBrush, 0.0f, 0.0f)
g.Save |> ignore
b.Save ("pipe.png", Imaging.ImageFormat.Png)
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment