Encode writes img to w in the requested format. Only "png" and "jpeg" are supported — these are the two formats the thumbnail pipeline emits, and the only ones every browser renders without question. Other formats fall through to ErrUnsupportedFormat so callers can see the limitation explicitly.
(img image.Image, format string, w io.Writer)
| 152 | // Other formats fall through to ErrUnsupportedFormat so callers can |
| 153 | // see the limitation explicitly. |
| 154 | func (p *pureGoProcessor) Encode(img image.Image, format string, w io.Writer) error { |
| 155 | switch format { |
| 156 | case "png": |
| 157 | return png.Encode(w, img) |
| 158 | case "jpeg", "jpg": |
| 159 | // Quality 85 is the standard sweet spot — visibly identical |
| 160 | // to 100% on screen, ~3x smaller. Higher would balloon |
| 161 | // thumbnail storage; lower introduces visible blocking. |
| 162 | return jpeg.Encode(w, img, &jpeg.Options{Quality: 85}) |
| 163 | default: |
| 164 | return fmt.Errorf("%w: encode target %q", ErrUnsupportedFormat, format) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | func (p *pureGoProcessor) formatSupported(format string) bool { |
| 169 | for _, f := range p.caps.ImageFormats { |