| 1 |
package standard |
| 2 |
|
| 3 |
import ( |
| 4 |
"image" |
| 5 |
"image/jpeg" |
| 6 |
"image/png" |
| 7 |
"io" |
| 8 |
) |
| 9 |
|
| 10 |
type formatTyp uint8 |
| 11 |
|
| 12 |
const ( |
| 13 |
// JPEG_FORMAT as default output file format. |
| 14 |
JPEG_FORMAT formatTyp = iota |
| 15 |
// PNG_FORMAT . |
| 16 |
PNG_FORMAT |
| 17 |
) |
| 18 |
|
| 19 |
// ImageEncoder is an interface which describes the rule how to encode image.Image into io.Writer |
| 20 |
type ImageEncoder interface { |
| 21 |
// Encode specify which format to encode image into io.Writer. |
| 22 |
Encode(w io.Writer, img image.Image) error |
| 23 |
} |
| 24 |
|
| 25 |
type jpegEncoder struct{} |
| 26 |
|
| 27 |
func (j jpegEncoder) Encode(w io.Writer, img image.Image) error { |
| 28 |
return jpeg.Encode(w, img, nil) |
| 29 |
} |
| 30 |
|
| 31 |
type pngEncoder struct{} |
| 32 |
|
| 33 |
func (j pngEncoder) Encode(w io.Writer, img image.Image) error { |
| 34 |
return png.Encode(w, img) |
| 35 |
} |