Created
January 27, 2016 19:01
-
-
Save ninjarobot/a4c14bd2ba27a5e6507e to your computer and use it in GitHub Desktop.
Image from text in fsharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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