Skip to main content
Two operations handle file size reduction and format migration: Optimize applies lossless or lossy compression to one or more files in place, and Convert re-encodes a single image to a different format.

Optimize

Compress one or more images without resizing them. Supports lossless and lossy modes, and can optionally produce a WebP copy alongside each compressed original.

Parameters

operation
string
required
Must be "optimize".
inputs
string[]
required
Array of input file paths to optimize.
output_dir
string
required
Directory where optimized files will be written.
level
string
default:"lossless"
Optimization level.
ValueDescription
losslessMaximum quality, moderate file size reduction
lossySmaller files with configurable quality loss
quality
number
default:"80"
Encode quality when level is "lossy". Range: 1–100.
also_webp
boolean
default:"false"
When true, each input also produces a .webp sibling file in output_dir. Useful for serving modern formats with a fallback.
Pair also_webp: true with an <picture> element in HTML to serve WebP to supporting browsers and the original format as a fallback. DevPixelForge handles the conversion in a single pass — no second job required.

Go client

func (c *Client) Optimize(ctx context.Context, inputs []string, outputDir string) (*JobResult, error)
The convenience method sets also_webp: true by default. For full control, use Client.Execute() with an OptimizeJob:
type OptimizeJob struct {
    Operation string   `json:"operation"`
    Inputs    []string `json:"inputs"`
    OutputDir *string  `json:"output_dir,omitempty"`
    Level     *string  `json:"level,omitempty"`
    Quality   *uint8   `json:"quality,omitempty"`
    AlsoWebp  bool     `json:"also_webp,omitempty"`
}

Examples

{
  "operation": "optimize",
  "inputs": ["a.png", "b.png"],
  "output_dir": "dist/images",
  "level": "lossless"
}
Go examples
client := dpf.NewClient("/usr/local/bin/dpf")

// Convenience method (also_webp enabled by default)
result, err := client.Optimize(ctx,
    []string{"a.png", "b.png"},
    "dist/images",
)
if err != nil {
    log.Fatal(err)
}

// Lossy with explicit quality, no WebP
level := "lossy"
outDir := "dist/images"
q := uint8(85)

result, err = client.Execute(ctx, &dpf.OptimizeJob{
    Operation: "optimize",
    Inputs:    []string{"a.jpg", "b.jpg"},
    OutputDir: &outDir,
    Level:     &level,
    Quality:   &q,
})

Convert

Re-encode a single image to a different format. Optionally resize the output in the same pass by providing width and/or height.

Parameters

operation
string
required
Must be "convert".
input
string
required
Path to the source image.
output
string
required
Path for the converted output file, including the new extension.
format
string
required
Target format. See the supported formats table below.
quality
number
default:"85"
Encode quality for lossy formats (JPEG, WebP, AVIF). Range: 1–100.
width
number
Output width in pixels. When provided alongside height, the image is resized during conversion. When provided alone, aspect ratio is preserved.
height
number
Output height in pixels. Follows the same aspect-ratio rules as width.
inline
boolean
default:"false"
When true, the output is also returned as a base64-encoded string in data_base64.

Supported formats

Formatformat valueNotes
PNGpngLossless
JPEGjpeg or jpgLossy
WebPwebpLossy or lossless depending on quality
AVIFavifHigh efficiency, lossy
GIFgifPaletted, 256 colors
ICOicoWindows icon format

Go client

func (c *Client) Convert(ctx context.Context, input, output, format string) (*JobResult, error)
For width/height resize-during-convert, use Client.Execute() with a ConvertJob:
type ConvertJob struct {
    Operation string  `json:"operation"`
    Input     string  `json:"input"`
    Output    string  `json:"output"`
    Format    string  `json:"format"`
    Quality   *uint8  `json:"quality,omitempty"`
    Width     *uint32 `json:"width,omitempty"`
    Height    *uint32 `json:"height,omitempty"`
    Inline    bool    `json:"inline,omitempty"`
}

Examples

{
  "operation": "convert",
  "input": "image.png",
  "output": "image.webp",
  "format": "webp",
  "quality": 85
}
Go examples
client := dpf.NewClient("/usr/local/bin/dpf")

// PNG → WebP
result, err := client.Convert(ctx, "image.png", "image.webp", "webp")
if err != nil {
    log.Fatal(err)
}

// JPEG → AVIF with explicit quality
q := uint8(80)
result, err = client.Execute(ctx, &dpf.ConvertJob{
    Operation: "convert",
    Input:     "image.jpg",
    Output:    "image.avif",
    Format:    "avif",
    Quality:   &q,
})

Build docs developers (and LLMs) love