7 people like it.

Making QR-code image having contact information (VCard) with Google Chart API

Making QR-code image having contact information (VCard) with Google Chart API. If you scan this image with mobile phone, you can directly add new person to your contacts.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
open System
open System.IO
open System.Net
open System.Drawing

let ImageSize = 300

let fetchImage (url : Uri) = 
    let req = WebRequest.Create (url) :?> HttpWebRequest
    use stream = req.GetResponse().GetResponseStream()
    Image.FromStream(stream)

let googleChartQRCodeImage mydata = 
    let addr = String.Format("http://chart.apis.google.com/chart?chs={0}x{0}&cht=qr&chl={1}&choe=ISO-8859-1", ImageSize, mydata)
    new Uri(addr, UriKind.Absolute)

let vcard = @"BEGIN:VCARD
VERSION:3.0
N:{1};{0};
FN:{0} {1}
NICKNAME:{2}
ORG:{3}
ROLE:{4}
TITLE:{4}
PHOTO;MEDIATYPE={6}:{5}
TEL;TYPE=CELL:{7}
X-TWITTER:{8}
URL:{9}
EMAIL;TYPE=PREF,INTERNET:{10}
ADR;TYPE=HOME:;;{11};{12};;{13};{14}
LABEL;TYPE=HOME:{11}\n{13} {12}\n{14}
REV:{15}
END:VCARD
"

let googleChartUri contact = 
    String.Format(vcard, contact)
    |> Uri.EscapeDataString
    |> googleChartQRCodeImage

let sample : obj [] = [|
    "Matt"; //first name 
    "Oneofus"; //surname
    "matias"; //nickname 
    "Company & co."; //organization
    "Guru"; //title
    "http://www.wpclipart.com/signs_symbol/icons_oversized/male_user_icon.png"; //image url
    "image/png"; //picture mime-type, eg. image/gif or image/jpeg
    "+358 50 123 4567"; //cell phone
    "Thoriumi"; // twitter account
    "http://www.iki.fi/thorium/"; // url
    "nospam@mailinator.com"; //email
    "Katuroad 1 A 5"; // street address
    "Espoo"; //city
    "02100"; //postal code
    "Finland"; //country
    System.DateTime.Now.ToString("yyyyMMddThhmmssZ"); // timestamp
    |]

open System.Windows.Forms
let showImage = 
    let form = new Form()
    let pb = new PictureBox()
    pb.Image <- sample |> googleChartUri |> fetchImage
    pb.SizeMode <- PictureBoxSizeMode.AutoSize
    form.Height <- ImageSize+50
    form.Width <- ImageSize+50
    form.Controls.Add(pb)
    form.Show()
namespace System
namespace System.IO
namespace System.Net
namespace System.Drawing
val ImageSize : int

Full name: Script.ImageSize
val fetchImage : url:Uri -> Image

Full name: Script.fetchImage
val url : Uri
Multiple items
type Uri =
  new : uriString:string -> Uri + 5 overloads
  member AbsolutePath : string
  member AbsoluteUri : string
  member Authority : string
  member DnsSafeHost : string
  member Equals : comparand:obj -> bool
  member Fragment : string
  member GetComponents : components:UriComponents * format:UriFormat -> string
  member GetHashCode : unit -> int
  member GetLeftPart : part:UriPartial -> string
  ...

Full name: System.Uri

--------------------
Uri(uriString: string) : unit
Uri(uriString: string, uriKind: UriKind) : unit
Uri(baseUri: Uri, relativeUri: string) : unit
Uri(baseUri: Uri, relativeUri: Uri) : unit
val req : HttpWebRequest
type WebRequest =
  inherit MarshalByRefObject
  member Abort : unit -> unit
  member AuthenticationLevel : AuthenticationLevel with get, set
  member BeginGetRequestStream : callback:AsyncCallback * state:obj -> IAsyncResult
  member BeginGetResponse : callback:AsyncCallback * state:obj -> IAsyncResult
  member CachePolicy : RequestCachePolicy with get, set
  member ConnectionGroupName : string with get, set
  member ContentLength : int64 with get, set
  member ContentType : string with get, set
  member Credentials : ICredentials with get, set
  member EndGetRequestStream : asyncResult:IAsyncResult -> Stream
  ...

Full name: System.Net.WebRequest
WebRequest.Create(requestUri: Uri) : WebRequest
WebRequest.Create(requestUriString: string) : WebRequest
type HttpWebRequest =
  inherit WebRequest
  member Abort : unit -> unit
  member Accept : string with get, set
  member AddRange : range:int -> unit + 7 overloads
  member Address : Uri
  member AllowAutoRedirect : bool with get, set
  member AllowWriteStreamBuffering : bool with get, set
  member AutomaticDecompression : DecompressionMethods with get, set
  member BeginGetRequestStream : callback:AsyncCallback * state:obj -> IAsyncResult
  member BeginGetResponse : callback:AsyncCallback * state:obj -> IAsyncResult
  member ClientCertificates : X509CertificateCollection with get, set
  ...

Full name: System.Net.HttpWebRequest
val stream : Stream
HttpWebRequest.GetResponse() : WebResponse
type Image =
  inherit MarshalByRefObject
  member Clone : unit -> obj
  member Dispose : unit -> unit
  member Flags : int
  member FrameDimensionsList : Guid[]
  member GetBounds : pageUnit:GraphicsUnit -> RectangleF
  member GetEncoderParameterList : encoder:Guid -> EncoderParameters
  member GetFrameCount : dimension:FrameDimension -> int
  member GetPropertyItem : propid:int -> PropertyItem
  member GetThumbnailImage : thumbWidth:int * thumbHeight:int * callback:GetThumbnailImageAbort * callbackData:nativeint -> Image
  member Height : int
  ...
  nested type GetThumbnailImageAbort

Full name: System.Drawing.Image
Image.FromStream(stream: Stream) : Image
Image.FromStream(stream: Stream, useEmbeddedColorManagement: bool) : Image
Image.FromStream(stream: Stream, useEmbeddedColorManagement: bool, validateImageData: bool) : Image
val googleChartQRCodeImage : mydata:'a -> Uri

Full name: Script.googleChartQRCodeImage
val mydata : 'a
val addr : string
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : unit
String.Format(format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj) : string
String.Format(provider: IFormatProvider, format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj, arg1: obj) : string
String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
type UriKind =
  | RelativeOrAbsolute = 0
  | Absolute = 1
  | Relative = 2

Full name: System.UriKind
field UriKind.Absolute = 1
val vcard : string

Full name: Script.vcard
val googleChartUri : contact:obj [] -> Uri

Full name: Script.googleChartUri
val contact : obj []
Uri.EscapeDataString(stringToEscape: string) : string
val sample : obj []

Full name: Script.sample
type obj = Object

Full name: Microsoft.FSharp.Core.obj
Multiple items
type DateTime =
  struct
    new : ticks:int64 -> DateTime + 10 overloads
    member Add : value:TimeSpan -> DateTime
    member AddDays : value:float -> DateTime
    member AddHours : value:float -> DateTime
    member AddMilliseconds : value:float -> DateTime
    member AddMinutes : value:float -> DateTime
    member AddMonths : months:int -> DateTime
    member AddSeconds : value:float -> DateTime
    member AddTicks : value:int64 -> DateTime
    member AddYears : value:int -> DateTime
    ...
  end

Full name: System.DateTime

--------------------
DateTime()
   (+0 other overloads)
DateTime(ticks: int64) : unit
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : unit
   (+0 other overloads)
property DateTime.Now: DateTime
DateTime.ToString() : string
DateTime.ToString(provider: IFormatProvider) : string
DateTime.ToString(format: string) : string
DateTime.ToString(format: string, provider: IFormatProvider) : string
namespace System.Windows
namespace System.Windows.Forms
val showImage : unit

Full name: Script.showImage
val form : Form
Multiple items
type Form =
  inherit ContainerControl
  new : unit -> Form
  member AcceptButton : IButtonControl with get, set
  member Activate : unit -> unit
  member ActiveMdiChild : Form
  member AddOwnedForm : ownedForm:Form -> unit
  member AllowTransparency : bool with get, set
  member AutoScale : bool with get, set
  member AutoScaleBaseSize : Size with get, set
  member AutoScroll : bool with get, set
  member AutoSize : bool with get, set
  ...
  nested type ControlCollection

Full name: System.Windows.Forms.Form

--------------------
Form() : unit
val pb : PictureBox
Multiple items
type PictureBox =
  inherit Control
  new : unit -> PictureBox
  member AllowDrop : bool with get, set
  member BorderStyle : BorderStyle with get, set
  member CancelAsync : unit -> unit
  member CausesValidation : bool with get, set
  member ErrorImage : Image with get, set
  member Font : Font with get, set
  member ForeColor : Color with get, set
  member Image : Image with get, set
  member ImageLocation : string with get, set
  ...

Full name: System.Windows.Forms.PictureBox

--------------------
PictureBox() : unit
property PictureBox.Image: Image
property PictureBox.SizeMode: PictureBoxSizeMode
type PictureBoxSizeMode =
  | Normal = 0
  | StretchImage = 1
  | AutoSize = 2
  | CenterImage = 3
  | Zoom = 4

Full name: System.Windows.Forms.PictureBoxSizeMode
field PictureBoxSizeMode.AutoSize = 2
property Control.Height: int
property Control.Width: int
property Control.Controls: Control.ControlCollection
Control.ControlCollection.Add(value: Control) : unit
Control.Show() : unit
Form.Show(owner: IWin32Window) : unit

More information

Link:http://fssnip.net/hj
Posted:6 months ago
Author:Tuomas Hietanen
Tags: qr , vcard