MCPcopy Create free account
hub / github.com/kataras/iris / createThumbnail

Method createThumbnail

_examples/dropzonejs/src/main.go:79–118  ·  view source on GitHub ↗
(uf uploadedFile)

Source from the content-addressed store, hash-verified

77}
78
79func (f *uploadedFiles) createThumbnail(uf uploadedFile) {
80 file, err := os.Open(path.Join(f.dir, uf.Name))
81 if err != nil {
82 return
83 }
84 defer file.Close()
85
86 name := strings.ToLower(uf.Name)
87
88 out, err := os.OpenFile(f.dir+"thumbnail_"+uf.Name,
89 os.O_WRONLY|os.O_CREATE, 0666)
90 if err != nil {
91 return
92 }
93 defer out.Close()
94
95 if strings.HasSuffix(name, ".jpg") {
96 // decode jpeg into image.Image
97 img, err := jpeg.Decode(file)
98 if err != nil {
99 return
100 }
101
102 // write new image to file
103 resized := resize.Thumbnail(180, 180, img, resize.Lanczos3)
104 jpeg.Encode(out, resized,
105 &jpeg.Options{Quality: jpeg.DefaultQuality})
106
107 } else if strings.HasSuffix(name, ".png") {
108 img, err := png.Decode(file)
109 if err != nil {
110 return
111 }
112
113 // write new image to file
114 resized := resize.Thumbnail(180, 180, img, resize.Lanczos3) // slower but better res
115 png.Encode(out, resized)
116 }
117 // and so on... you got the point, this code can be simplify, as a practise.
118}
119
120func main() {
121 app := iris.New()

Callers 2

mainFunction · 0.80
dropzone.jsFile · 0.80

Calls 4

EncodeMethod · 0.80
CloseMethod · 0.65
DecodeMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected