code: func Encode(w io.Writer, img image.Image, format Format, opts ...EncodeOption) error {
  	cfg := defaultEncodeConfig
  	for _, option := range opts {
  		option(&cfg)
  	}
  
  	switch format {
  	case JPEG:
  		if nrgba, ok := img.(*image.NRGBA); ok && nrgba.Opaque() {
  			rgba := &image.RGBA{
  				Pix:    nrgba.Pix,
  				Stride: nrgba.Stride,
  				Rect:   nrgba.Rect,
  			}
  			return jpeg.Encode(w, rgba, &jpeg.Options{Quality: cfg.jpegQuality})
  		}
  		return jpeg.Encode(w, img, &jpeg.Options{Quality: cfg.jpegQuality})
  
  	case PNG:
  		encoder := png.Encoder{CompressionLevel: cfg.pngCompressionLevel}
  		return encoder.Encode(w, img)
  
  	case GIF:
  		return gif.Encode(w, img, &gif.Options{
  			NumColors: cfg.gifNumColors,
  			Quantizer: cfg.gifQuantizer,
  			Drawer:    cfg.gifDrawer,
  		})
  
  	case TIFF:
  		return tiff.Encode(w, img, &tiff.Options{Compression: tiff.Deflate, Predictor: true})
  
  	case BMP:
  		return bmp.Encode(w, img)
  	}
  
  	return ErrUnsupportedFormat
  }
docs: // Encode writes the image img to w in the specified format (JPEG, PNG, GIF, TIFF or BMP).