|
7 | 7 | "fmt"
|
8 | 8 | "image"
|
9 | 9 | "image/jpeg"
|
| 10 | + "image/png" |
10 | 11 | "io"
|
11 | 12 | "net/http"
|
12 | 13 | "os"
|
@@ -154,36 +155,38 @@ func SdkapiHandler(w http.ResponseWriter, r *http.Request) {
|
154 | 155 | }
|
155 | 156 | //resizedImg := resizeImage(img, 184, 96)
|
156 | 157 |
|
157 |
| - bounds := img.Bounds() |
| 158 | + // bounds := img.Bounds() |
158 | 159 |
|
159 |
| - rgbValues := make([][][3]uint8, bounds.Dy()) // height |
| 160 | + // rgbValues := make([][][3]uint8, bounds.Dy()) // height |
160 | 161 |
|
161 |
| - for y := bounds.Min.Y; y < bounds.Max.Y; y++ { |
162 |
| - rgbRow := make([][3]uint8, bounds.Dx()) // width |
| 162 | + // for y := bounds.Min.Y; y < bounds.Max.Y; y++ { |
| 163 | + // rgbRow := make([][3]uint8, bounds.Dx()) // width |
163 | 164 |
|
164 |
| - for x := bounds.Min.X; x < bounds.Max.X; x++ { |
165 |
| - //get current pixel color |
166 |
| - f := img.At(x, y) |
| 165 | + // for x := bounds.Min.X; x < bounds.Max.X; x++ { |
| 166 | + // //get current pixel color |
| 167 | + // f := img.At(x, y) |
167 | 168 |
|
168 |
| - r, g, b, _ := f.RGBA() |
169 |
| - r8 := uint8(r >> 8) |
170 |
| - g8 := uint8(g >> 8) |
171 |
| - b8 := uint8(b >> 8) |
| 169 | + // r, g, b, _ := f.RGBA() |
| 170 | + // r8 := uint8(r >> 8) |
| 171 | + // g8 := uint8(g >> 8) |
| 172 | + // b8 := uint8(b >> 8) |
172 | 173 |
|
173 |
| - //store RGB values |
174 |
| - rgbRow[x] = [3]uint8{r8, g8, b8} |
175 |
| - } |
| 174 | + // //store RGB values |
| 175 | + // rgbRow[x] = [3]uint8{r8, g8, b8} |
| 176 | + // } |
176 | 177 |
|
177 |
| - rgbValues[y] = rgbRow |
178 |
| - } |
| 178 | + // rgbValues[y] = rgbRow |
| 179 | + // } |
179 | 180 |
|
180 | 181 | // Reads the image and handles possible errors
|
181 |
| - faceBytes, err := imageToBytes(img) |
| 182 | + var buf bytes.Buffer |
| 183 | + err = png.Encode(&buf, img) |
182 | 184 | if err != nil {
|
183 | 185 | http.Error(w, "Error reading image: "+err.Error(), http.StatusInternalServerError)
|
184 | 186 | return
|
185 | 187 | }
|
186 | 188 |
|
| 189 | + faceBytes := buf.Bytes() |
187 | 190 | ctx := r.Context()
|
188 | 191 | ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
189 | 192 | defer cancel()
|
|
0 commit comments