Skip to content

Commit 0b310f3

Browse files
committed
adding data from the images, loading images and getting the path
1 parent b7b3028 commit 0b310f3

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

08-filepath-walk/main.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* example of a file path for the images */
2+
package main
3+
4+
import (
5+
"os"
6+
"fmt"
7+
"path/filepath"
8+
)
9+
10+
// main walk
11+
func main() {
12+
// loading the file path
13+
filepath.Walk("../images", func(path string, info os.FileInfo, err error) error {
14+
15+
if info.IsDir() {
16+
return nil
17+
}
18+
19+
fmt.Println(path)
20+
21+
return nil
22+
})
23+
}

09-getall-images/main.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
example to get all the images and process the files
3+
4+
*/
5+
6+
package main
7+
8+
9+
import (
10+
"fmt"
11+
"os"
12+
"image"
13+
"image/jpeg"
14+
"path/filepath"
15+
"log"
16+
)
17+
18+
// defining the interfaces
19+
type loadimage interface {
20+
LoadImage() image.Image
21+
}
22+
23+
// defining the struct
24+
type imagen struct {
25+
filename string
26+
}
27+
28+
// definding the procedure call
29+
func (fil imagen) LoadImage() image.Image {
30+
// first let load the files
31+
f, err := os.Open(fil.filename)
32+
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
37+
defer f.Close()
38+
39+
// get the images information
40+
imgn, err := jpeg.Decode(f)
41+
42+
if err != nil {
43+
log.Fatal(err)
44+
}
45+
46+
return imgn
47+
48+
}
49+
50+
func getImages() []image.Image {
51+
52+
// get all the images
53+
var images []image.Image
54+
55+
// walk to the folder to look the images
56+
filepath.Walk("../images", func(path string, info os.FileInfo, err error) error {
57+
58+
if info.IsDir() {
59+
return nil
60+
}
61+
62+
img := imagen{ filename: path}
63+
images = append(images, img.LoadImage())
64+
65+
return nil
66+
})
67+
68+
return images
69+
70+
}
71+
72+
func main() {
73+
// load all teh images
74+
images := getImages()
75+
76+
for _, v := range images {
77+
r, g, b, a := v.At(0, 0).RGBA()
78+
fmt.Printf("%d %d %d %d \n", r, g, b, a)
79+
}
80+
}
81+
82+
83+
84+

0 commit comments

Comments
 (0)