-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.go
78 lines (63 loc) · 1.54 KB
/
11.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
76
77
package main
import (
"fmt"
"os"
"io"
"net/http"
"image"
"image/jpeg"
_"io/ioutil"
)
const Filename string = "cave.jpg"
func main() {
imgfile, _ := os.Open( Filename )
defer imgfile.Close()
defer func(){
err := os.Remove(Filename)
fmt.Println("err/del.", err)
}()
img, _, _ := image.Decode( imgfile )
bounds := img.Bounds()
Even := image.NewRGBA( bounds )
Odd := image.NewRGBA( bounds )
W := bounds.Dx()
H := bounds.Dy()
var r, c int
r = 0
for r < H {
c = 0
for c < W {
pix := img.At(c, r)
rc := r + c
if rc % 2 == 0 {
Even.Set( c, r, pix )
} else {
Odd.Set( c, r, pix )
}
c++
}
r++
}
// save both jpg
imgfileEven, _ := os.Create("1.jpg")
defer imgfileEven.Close()
jpeg.Encode( imgfileEven, Even, nil )
imgfileOdd, _ := os.Create("2.jpg")
defer imgfileOdd.Close()
jpeg.Encode (imgfileOdd, Odd, nil)
}
func init(){
f, err := os.Create( Filename )
fmt.Println("err/init", err)
defer f.Close()
URL := "http://www.pythonchallenge.com/pc/return/"
ups, mid := "hugefile", 4
conn := &http.Client{}
req, err := http.NewRequest("GET", URL + Filename, nil)
fmt.Println("err/GET", err)
req.SetBasicAuth(ups[:mid], ups[mid:])
resp, err := conn.Do( req )
fmt.Println("err/GET", err, resp.StatusCode)
defer resp.Body.Close()
_, _ = io.Copy(f, resp.Body)
}