-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages.go
75 lines (68 loc) · 1.63 KB
/
images.go
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
70
71
72
73
74
75
package vcardgen
import "fmt"
type cardImageType string
const (
// PhotoImage is the type of images that represent the human face of a vCard
PhotoImage cardImageType = "PHOTO"
// LogoImage is the type of images that represent the faceless Corporatehood of a vCard
LogoImage cardImageType = "LOGO"
)
// CardImage represents a URI pointing to an image for a Logo or Photo.
type CardImage struct {
// Photo Type, i.e LOGO or PHOTO
PhotoType cardImageType
Contents, MediaType string
Base64 bool
Version majorVersion
}
// NewLogo returns a logo image from a URL.
func NewLogo(URL, MediaType string) *CardImage {
return &CardImage{
PhotoType: LogoImage,
Contents: URL,
MediaType: MediaType,
Base64: false,
Version: VersionFour,
}
}
// NewPhoto returns a logo image from a URL.
func NewPhoto(URL, MediaType string) *CardImage {
return &CardImage{
PhotoType: PhotoImage,
Contents: URL,
MediaType: MediaType,
Base64: false,
Version: VersionFour,
}
}
// Returns a formatted URL for a photo, or the photo contents.
func (img *CardImage) getFormattedPhoto() string {
var params string
switch img.Version {
case VersionFour:
{
if img.Base64 {
params = ";ENCODING=b;MEDIATYPE=image/"
} else {
params = ";MEDIATYPE=image/"
}
}
case VersionThree:
{
if img.Base64 {
params = ";ENCODING=b;TYPE="
} else {
params = ";TYPE="
}
}
case VersionTwo:
{
if img.Base64 {
params = ";ENCODING=BASE64;"
} else {
params = ";"
}
}
}
return fmt.Sprintf("%s%s%s:%s\r\n", string(img.PhotoType), params, img.MediaType, encodeString(img.Contents))
}