Skip to main content
A collection of specialized operations for common asset pipeline tasks.
Quantize an image down to a limited palette. Useful for shrinking indexed PNGs and GIFs before deployment.

Parameters

operation
string
required
Must be "palette".
input
string
required
Path to the source image.
output_dir
string
required
Directory where the palette-reduced file will be written.
max_colors
number
default:"256"
Maximum number of colors in the output palette. Range: 2–256.
dithering
number
default:"0.0"
Dithering strength applied during quantization to reduce color banding. Range: 0.0 (none) to 1.0 (maximum).
format
string
default:"same as input"
Output format. png is typical for palette-reduced output.

Go client

// Reduce to a fixed palette size
func (c *Client) Palette(ctx context.Context, input, outputDir string, maxColors uint32) (*JobResult, error)

// Reduce with dithering
func (c *Client) PaletteWithDithering(ctx context.Context, input, outputDir string, maxColors uint32, dithering float32) (*JobResult, error)
type PaletteJob struct {
    Operation string   `json:"operation"`
    Input     string   `json:"input"`
    OutputDir string   `json:"output_dir"`
    MaxColors *uint32  `json:"max_colors,omitempty"`
    Dithering *float32 `json:"dithering,omitempty"`
    Format    *string  `json:"format,omitempty"`
    Inline    bool     `json:"inline,omitempty"`
}

Examples

{
  "operation": "palette",
  "input": "icon.png",
  "output_dir": "dist/icons",
  "max_colors": 32,
  "format": "png"
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

// Simple palette reduction
result, err := client.Palette(ctx, "icon.png", "dist/icons", 32)

// With dithering to smooth color bands
result, err = client.PaletteWithDithering(ctx, "icon.png", "dist/icons", 16, 0.8)
Generate a favicon.ico and individual PNG sizes from a single SVG or raster source.

Parameters

operation
string
required
Must be "favicon".
input
string
required
Path to the source image. SVG inputs produce the sharpest results at all sizes.
output_dir
string
required
Directory where favicon files will be written.
sizes
number[]
default:"[16, 32, 48, 180, 192, 512]"
Array of square sizes in pixels to generate. Common values: 16, 32, 48 for browsers; 180 for Apple Touch Icon; 192, 512 for PWA manifest icons.
generate_ico
boolean
default:"false"
When true, generates a multi-size favicon.ico bundling the 16×16, 32×32, and 48×48 sizes.
generate_manifest
boolean
default:"false"
When true, generates a site.webmanifest JSON file referencing the PNG icons.

Output files

FileDescription
favicon.icoMulti-size ICO file (when generate_ico: true)
favicon-{size}.pngIndividual PNG at each requested size
site.webmanifestPWA manifest (when generate_manifest: true)

Go client

func (c *Client) Favicon(ctx context.Context, input, outputDir string) (*JobResult, error)
The convenience method enables both generate_ico and generate_manifest. For custom sizes, use Client.Execute() with a FaviconJob:
type FaviconJob struct {
    Operation        string   `json:"operation"`
    Input            string   `json:"input"`
    OutputDir        string   `json:"output_dir"`
    Sizes            []uint32 `json:"sizes,omitempty"`
    GenerateICO      bool     `json:"generate_ico"`
    GenerateManifest bool     `json:"generate_manifest,omitempty"`
    Prefix           *string  `json:"prefix,omitempty"`
}

Example

JSON
{
  "operation": "favicon",
  "input": "logo.svg",
  "output_dir": "dist/favicon",
  "sizes": [16, 32, 48, 180, 192, 512],
  "generate_ico": true,
  "generate_manifest": true
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

result, err := client.Favicon(ctx, "logo.svg", "dist/favicon")
if err != nil {
    log.Fatal(err)
}
// Produces: favicon.ico, favicon-16.png, favicon-32.png, ...
Pack multiple images into a single sprite sheet. Optionally generate a CSS file with background-position rules for each sprite.

Parameters

operation
string
required
Must be "sprite".
inputs
string[]
required
Ordered array of input image paths. Images are placed left-to-right, top-to-bottom.
output
string
required
Path for the output sprite sheet image.
columns
number
default:"4"
Number of columns in the sprite grid.
padding
number
default:"0"
Pixel gap between sprites in the grid.
generate_css
boolean
default:"false"
When true, generates a .css file alongside the sprite sheet with background-position rules for each input image.
cell_size
number
Fixed cell size in pixels. When set, all sprites are scaled to fit this square cell. When omitted, cell dimensions match the largest input image.

Go client

type SpriteJob struct {
    Operation   string   `json:"operation"`
    Inputs      []string `json:"inputs"`
    Output      string   `json:"output"`
    CellSize    *uint32  `json:"cell_size,omitempty"`
    Columns     *uint32  `json:"columns,omitempty"`
    Padding     *uint32  `json:"padding,omitempty"`
    GenerateCSS bool     `json:"generate_css,omitempty"`
}

Example

JSON
{
  "operation": "sprite",
  "inputs": ["icon1.png", "icon2.png", "icon3.png", "icon4.png"],
  "output": "sprites.png",
  "columns": 2,
  "padding": 5,
  "generate_css": true
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

cols := uint32(2)
pad := uint32(5)

result, err := client.Execute(ctx, &dpf.SpriteJob{
    Operation:   "sprite",
    Inputs:      []string{"icon1.png", "icon2.png", "icon3.png", "icon4.png"},
    Output:      "sprites.png",
    Columns:     &cols,
    Padding:     &pad,
    GenerateCSS: true,
})
if err != nil {
    log.Fatal(err)
}
Generate a low-quality blurred preview (LQIP) or extract the dominant color of an image. Both are useful for progressive loading — display the placeholder immediately while the full image loads.

Parameters

operation
string
required
Must be "placeholder".
input
string
required
Path to the source image.
kind
string
default:"lqip"
Placeholder type.
ValueDescription
lqipLow-quality blurred thumbnail, returned as base64 inline data URI
dominantExtract dominant color; returned as hex in response metadata
lqip_width
number
default:"20"
Width of the LQIP thumbnail in pixels. Smaller values produce smaller data URIs. Used when kind is "lqip".
format
string
default:"webp"
Output format for LQIP thumbnails.
quality
number
default:"30"
Encode quality for the LQIP thumbnail. Low values (20–40) are typical.
inline
boolean
default:"false"
When true, the LQIP image is returned as a base64-encoded string in data_base64.

Response — dominant color

When kind is "dominant", the response metadata field contains:
{
  "metadata": {
    "dominant_color": "#3498db"
  }
}

Go client

// Returns inline LQIP base64
func (c *Client) Placeholder(ctx context.Context, input string) (*JobResult, error)
type PlaceholderJob struct {
    Operation string  `json:"operation"`
    Input     string  `json:"input"`
    Output    *string `json:"output,omitempty"`
    Kind      *string `json:"kind,omitempty"`
    LQIPWidth *uint32 `json:"lqip_width,omitempty"`
    Inline    bool    `json:"inline"`
}

Examples

{
  "operation": "placeholder",
  "input": "photo.jpg",
  "kind": "lqip",
  "lqip_width": 20,
  "format": "webp",
  "quality": 30,
  "inline": true
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

// Inline LQIP (convenience method)
result, err := client.Placeholder(ctx, "photo.jpg")
if err != nil {
    log.Fatal(err)
}
// result.Outputs[0].DataBase64 contains the data URI payload

// Dominant color extraction
kind := "dominant"
result, err = client.Execute(ctx, &dpf.PlaceholderJob{
    Operation: "placeholder",
    Input:     "photo.jpg",
    Kind:      &kind,
})
Generate a set of width-scaled variants and optionally emit an HTML <img> tag with the srcset attribute pre-populated.

Parameters

operation
string
required
Must be "srcset".
input
string
required
Path to the source image.
output_dir
string
required
Directory where generated image variants will be written.
widths
number[]
required
Array of target widths in pixels. Each produces a separate output file.
densities
number[]
default:"[1.0, 2.0]"
Pixel density multipliers. [1.0, 2.0] produces standard and retina variants at each width.
format
string
default:"same as input"
Output format: png, jpeg, webp, or avif.
quality
number
default:"85"
Encode quality for JPEG and WebP outputs. Range: 1–100.
generate_html
boolean
default:"false"
When true, the response metadata includes a ready-to-use <img> element with src and srcset attributes.
linear_rgb
boolean
default:"false"
When true, resize is performed in linear light for higher accuracy.

Output filename pattern

DensityPatternExample
{name}-{width}w.{ext}hero-640w.webp
Other{name}-{width}w-{density}x.{ext}hero-640w-2x.webp

Go client

func (c *Client) Srcset(ctx context.Context, job *SrcsetJob) (*JobResult, error)
type SrcsetJob struct {
    Operation    string    `json:"operation"`
    Input        string    `json:"input"`
    OutputDir    string    `json:"output_dir"`
    Widths       []uint32  `json:"widths"`
    Densities    []float64 `json:"densities,omitempty"`
    Format       string    `json:"format,omitempty"`
    Quality      *uint8    `json:"quality,omitempty"`
    GenerateHTML bool      `json:"generate_html,omitempty"`
    LinearRGB    bool      `json:"linear_rgb,omitempty"`
}

Example

JSON
{
  "operation": "srcset",
  "input": "hero.jpg",
  "output_dir": "dist/images",
  "widths": [320, 640, 960, 1280, 1920],
  "densities": [1.0, 2.0],
  "format": "webp",
  "quality": 85,
  "generate_html": true,
  "linear_rgb": true
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

q := uint8(85)

result, err := client.Srcset(ctx, &dpf.SrcsetJob{
    Input:        "hero.jpg",
    OutputDir:    "dist/images",
    Widths:       []uint32{320, 640, 960, 1280, 1920},
    Densities:    []float64{1.0, 2.0},
    Format:       "webp",
    Quality:      &q,
    GenerateHTML: true,
    LinearRGB:    true,
})
if err != nil {
    log.Fatal(err)
}
Strip, preserve, extract, or apply EXIF orientation data. Use this to sanitize images before public upload, correct camera orientation, or read camera metadata.

Parameters

operation
string
required
Must be "exif".
input
string
required
Path to the source image.
output
string
Path for the output file. Required for strip, preserve, and auto_orient. Not needed for extract.
exif_op
string
required
EXIF operation type.
ValueDescription
stripRemove EXIF data according to mode
preserveRemove all EXIF except tags listed in keep
extractRead and return EXIF metadata without writing a file
auto_orientApply the EXIF orientation rotation to pixel data, then remove the tag
mode
string
default:"all"
Controls which data is stripped when exif_op is "strip".
ValueDescription
allRemove all EXIF data
gpsRemove GPS coordinates only
thumbnailRemove embedded thumbnail only
cameraRemove camera make and model only
keep
string[]
Array of EXIF tag names to retain when exif_op is "preserve". All other tags are removed.
return_metadata
boolean
default:"true"
When true, the response metadata field contains the parsed EXIF data. Relevant for extract and useful for inspecting results from other operations.
format
string
default:"same as input"
Output format.
quality
number
default:"85"
Encode quality for JPEG and WebP outputs. Range: 1–100.
inline
boolean
default:"false"
When true, the output is also returned as a base64-encoded string in data_base64.

Extracted metadata fields

When exif_op is "extract" or return_metadata is true, the response metadata object may contain:
{
  "has_exif": true,
  "make": "Canon",
  "model": "EOS 5D",
  "orientation": 1,
  "datetime": "2024:01:15 10:30:00",
  "exposure_time": "1/250",
  "f_number": "f/2.8",
  "iso": 400,
  "gps": {
    "latitude": 40.7128,
    "longitude": -74.0060,
    "altitude": 10.5
  }
}

Go client

func (c *Client) Exif(ctx context.Context, job *ExifJob) (*JobResult, error)
type ExifJob struct {
    Operation      string   `json:"operation"`
    Input          string   `json:"input"`
    Output         string   `json:"output,omitempty"`
    ExifOp         string   `json:"exif_op"`
    Mode           string   `json:"mode,omitempty"`
    Keep           []string `json:"keep,omitempty"`
    ReturnMetadata bool     `json:"return_metadata,omitempty"`
    Format         string   `json:"format,omitempty"`
    Quality        *uint8   `json:"quality,omitempty"`
    Inline         bool     `json:"inline,omitempty"`
}

Examples

{
  "operation": "exif",
  "input": "photo.jpg",
  "output": "cleaned.jpg",
  "exif_op": "strip",
  "mode": "all",
  "format": "jpeg",
  "quality": 90
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

// Strip all EXIF before public upload
result, err := client.Exif(ctx, &dpf.ExifJob{
    Input:  "photo.jpg",
    Output: "cleaned.jpg",
    ExifOp: "strip",
    Mode:   "all",
})

// Extract metadata for display
result, err = client.Exif(ctx, &dpf.ExifJob{
    Input:          "photo.jpg",
    ExifOp:         "extract",
    ReturnMetadata: true,
})

// Auto-orient from EXIF rotation tag
result, err = client.Exif(ctx, &dpf.ExifJob{
    Input:  "photo.jpg",
    Output: "oriented.jpg",
    ExifOp: "auto_orient",
})
Automatically determine the highest JPEG/WebP/AVIF quality that still meets a target file size, using binary search. Returns convergence metadata so you can audit the result.

Parameters

operation
string
required
Must be "quality".
input
string
required
Path to the source image.
output
string
required
Path for the optimized output file.
target_size
number
required
Target file size in bytes. The engine finds the quality setting that produces a file as close to this size as possible without exceeding tolerance_percent.
format
string
required
Output format. Must be a lossy format: jpeg, webp, or avif.
tolerance_percent
number
default:"5.0"
Acceptable deviation from target_size as a percentage. The search stops when it achieves a result within this tolerance.
max_iterations
number
default:"10"
Maximum number of binary search iterations before stopping.
min_quality
number
default:"30"
Lower bound for the quality search range.
max_quality
number
default:"95"
Upper bound for the quality search range.
inline
boolean
default:"false"
When true, the output is also returned as a base64-encoded string in data_base64.

Response metadata

The metadata field of the response reports the outcome of the binary search:
{
  "target_size": 50000,
  "final_quality": 72,
  "final_size": 48500,
  "deviation_percent": 3.0,
  "iterations": 6,
  "converged": true
}
FieldTypeDescription
target_sizenumberRequested target in bytes
final_qualitynumberQuality setting selected
final_sizenumberActual output file size in bytes
deviation_percentnumberDeviation from target as a percentage
iterationsnumberNumber of iterations performed
convergedbooleanWhether the search met the tolerance

Go client

func (c *Client) AutoQuality(ctx context.Context, job *QualityJob) (*JobResult, error)
type QualityJob struct {
    Operation        string   `json:"operation"`
    Input            string   `json:"input"`
    Output           string   `json:"output"`
    TargetSize       uint64   `json:"target_size"`
    TolerancePercent *float64 `json:"tolerance_percent,omitempty"`
    MaxIterations    *uint8   `json:"max_iterations,omitempty"`
    MinQuality       *uint8   `json:"min_quality,omitempty"`
    MaxQuality       *uint8   `json:"max_quality,omitempty"`
    Format           string   `json:"format"`
    Inline           bool     `json:"inline,omitempty"`
}

Examples

{
  "operation": "quality",
  "input": "photo.jpg",
  "output": "optimized.jpg",
  "target_size": 50000,
  "tolerance_percent": 5,
  "max_iterations": 10,
  "format": "jpeg"
}
Go
client := dpf.NewClient("/usr/local/bin/dpf")

tolerance := float64(5.0)

result, err := client.AutoQuality(ctx, &dpf.QualityJob{
    Input:            "photo.jpg",
    Output:           "optimized.jpg",
    TargetSize:       50000,
    TolerancePercent: &tolerance,
    Format:           "jpeg",
})
if err != nil {
    log.Fatal(err)
}

// Inspect convergence metadata
fmt.Printf("result: %s\n", string(*result.Metadata))

Build docs developers (and LLMs) love