@@ -23,6 +23,10 @@ func main() {
2323 os .Exit (1 )
2424 }
2525
26+ // Set up imagemagick
27+ imagick .Initialize ()
28+ defer imagick .Terminate ()
29+
2630 // Open the file supplied
2731 in , err := os .Open (* input )
2832 if err != nil {
@@ -41,16 +45,17 @@ func main() {
4145 for i , row := range records [1 :] {
4246 url := row [0 ]
4347
44- filepath := fmt .Sprintf ("/tmp/%d-%d.%s" , time .Now ().UnixMilli (), rand .Int (), "jpg" )
48+ inputFilepath := fmt .Sprintf ("/tmp/%d-%d.%s" , time .Now ().UnixMilli (), rand .Int (), "jpg" )
49+ outputFilepath := fmt .Sprintf ("/tmp/%d-%d.%s" , time .Now ().UnixMilli (), rand .Int (), "jpg" )
4550
46- log .Printf ("downloading: row %d (%q) to %q" , i , url , filepath )
51+ log .Printf ("downloading: row %d (%q) to %q" , i , url , inputFilepath )
4752
4853 // Create a new file that we will write to
49- out , err := os .Create (filepath )
54+ input , err := os .Create (inputFilepath )
5055 if err != nil {
5156 log .Fatal (err )
5257 }
53- defer out .Close ()
58+ defer input .Close ()
5459
5560 // Get it from the internet!
5661 res , err := http .Get (url )
@@ -62,13 +67,19 @@ func main() {
6267 // TODO: check status code
6368
6469 // Copy the body of the response to the created file
65- _ , err = io .Copy (out , res .Body )
70+ _ , err = io .Copy (input , res .Body )
71+ if err != nil {
72+ log .Fatal (err )
73+ }
74+
75+ ret , err := imagick .ConvertImageCommand ([]string {
76+ "convert" , inputFilepath , "-set" , "colorspace" , "Gray" , "-separate" , "-average" , outputFilepath ,
77+ })
6678 if err != nil {
6779 log .Fatal (err )
6880 }
81+
82+ fmt .Printf ("monochrome: %s\n %s\n " , outputFilepath , ret .Meta )
6983 }
7084
71- // Set up imagemagick
72- imagick .Initialize ()
73- defer imagick .Terminate ()
7485}
0 commit comments