MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / Encode

Method Encode

internal/attachments/processor_purego.go:154–166  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

152// Other formats fall through to ErrUnsupportedFormat so callers can
153// see the limitation explicitly.
154func (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
168func (p *pureGoProcessor) formatSupported(format string) bool {
169 for _, f := range p.caps.ImageFormats {

Callers

nothing calls this directly

Calls 1

EncodeMethod · 0.65

Tested by

no test coverage detected