-
Notifications
You must be signed in to change notification settings - Fork 16
/
example_jpeg_test.go
60 lines (50 loc) · 1.15 KB
/
example_jpeg_test.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
package fastimage_test
import (
"fmt"
"os"
"github.com/rubenfonseca/fastimage"
)
// This example shows basic usage of the package: just pass an url to the
// detector, and analyze the results.
func Example_remoteBigJPEG() {
url := "http://upload.wikimedia.org/wikipedia/commons/9/9a/SKA_dishes_big.jpg"
imagetype, size, err := fastimage.DetectImageType(url)
if err != nil {
// Something went wrong, http failed? not an image?
panic(err)
}
fmt.Printf("Image size: %v\n", size)
switch imagetype {
case fastimage.JPEG:
fmt.Println("JPEG")
case fastimage.PNG:
fmt.Println("PNG")
case fastimage.GIF:
fmt.Println("GIF")
}
// Output: Image size: &{5000 2813}
// JPEG
}
func Example_localBigJPEG() {
f, err := os.Open("example.gif")
if err != nil {
panic(err)
}
defer f.Close()
imagetype, size, err := fastimage.DetectImageTypeFromReader(f)
if err != nil {
// Something went wrong, not an image?
panic(err)
}
fmt.Printf("Image size: %v\n", size)
switch imagetype {
case fastimage.JPEG:
fmt.Printf("JPEG")
case fastimage.PNG:
fmt.Printf("PNG")
case fastimage.GIF:
fmt.Printf("GIF")
}
// Output: Image size: &{320 240}
// GIF
}