3 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
val fetchImage : url:Uri -> 'a
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
  ...

--------------------
Uri(uriString: string) : Uri
Uri(uriString: string, uriKind: UriKind) : Uri
Uri(baseUri: Uri, relativeUri: string) : Uri
Uri(baseUri: Uri, relativeUri: Uri) : Uri
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
  ...
WebRequest.Create(requestUri: Uri) : WebRequest
WebRequest.Create(requestUriString: string) : WebRequest
Multiple items
type HttpWebRequest =
  inherit WebRequest
  new : unit -> HttpWebRequest
  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 AllowReadStreamBuffering : bool with get, set
  member AllowWriteStreamBuffering : bool with get, set
  member AutomaticDecompression : DecompressionMethods with get, set
  member BeginGetRequestStream : callback:AsyncCallback * state:obj -> IAsyncResult
  ...

--------------------
HttpWebRequest() : HttpWebRequest
val stream : Stream
val googleChartQRCodeImage : mydata:'a -> Uri
val mydata : 'a
val addr : string
Multiple items
type String =
  new : value:char[] -> string + 8 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool + 3 overloads
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 3 overloads
  member EnumerateRunes : unit -> StringRuneEnumerator
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  ...

--------------------
String(value: char []) : String
String(value: nativeptr<char>) : String
String(value: nativeptr<sbyte>) : String
String(value: ReadOnlySpan<char>) : String
String(c: char, count: int) : String
String(value: char [], startIndex: int, length: int) : String
String(value: nativeptr<char>, startIndex: int, length: int) : String
String(value: nativeptr<sbyte>, startIndex: int, length: int) : String
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String
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(provider: IFormatProvider, format: string, arg0: obj) : string
String.Format(format: string, arg0: obj, arg1: obj) : string
String.Format(provider: IFormatProvider, format: string, arg0: obj, arg1: obj) : string
String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
String.Format(provider: IFormatProvider, format: string, arg0: obj, arg1: obj, arg2: obj) : string
type UriKind =
  | RelativeOrAbsolute = 0
  | Absolute = 1
  | Relative = 2
field UriKind.Absolute: UriKind = 1
val vcard : string
val googleChartUri : contact:obj [] -> Uri
val contact : obj []
Uri.EscapeDataString(stringToEscape: string) : string
val sample : obj []
type obj = Object
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

--------------------
DateTime ()
   (+0 other overloads)
DateTime(ticks: int64) : DateTime
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
property DateTime.Now: DateTime with get
namespace System.Windows
val showImage : obj
val form : obj
val pb : obj

More information

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