Skip to content

Instantly share code, notes, and snippets.

@rolandvarga
Last active July 6, 2020 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolandvarga/b5086ad1f9c2efcd3830c4c58f434553 to your computer and use it in GitHub Desktop.
Save rolandvarga/b5086ad1f9c2efcd3830c4c58f434553 to your computer and use it in GitHub Desktop.
func main() {
...
for _, f := range r.File {
if f.FileInfo().IsDir() {
os.MkdirAll(*dest+"/"+f.Name, os.ModePerm)
continue
}
fmt.Printf("converting image: %s\n", f.Name)
zipped, err := f.Open()
if err != nil {
fmt.Printf("error reading '%s': %s\n", f.Name, err.Error())
continue
}
// grayscale images
img, _, err := image.Decode(zipped)
if err != nil {
fmt.Printf("error decoding image '%s': %s\n", f.Name, err.Error())
continue
}
gray := image.NewGray(img.Bounds())
for x := 0; x < img.Bounds().Max.X; x++ {
for y := 0; y < img.Bounds().Max.Y; y++ {
color := img.At(x, y)
gray.Set(x, y, color)
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment