Skip to content

PIXU encode — native WebP/JPEG output ​

format: 'image/pixu' selects the TECR encode path. The file you get is always image/webp or image/jpeg with a matching .webp / .jpg extension — ready for <img>, downloads, and CDNs.

Live demo ​

PIXU encode

TECR path — downloads as .webp or .jpg

Try a sample image

How it works ​

StepWhat happens
Encodecompress(..., { format: 'image/pixu' }) uses adaptive / smart quality
Resultresult.format is image/webp or image/jpeg
DisplayURL.createObjectURL(result.file) works in <img>
SavebuildDownloadName(name, result.format) → .webp or .jpg
typescript
import {
  compress,
  buildDownloadName,
  PIXU_MIME_TYPE,
} from '@pantanal/pixu'

const result = await compress(file, {
  format: PIXU_MIME_TYPE,
  enableSmartQuality: true,
})

img.src = URL.createObjectURL(result.file)

const a = document.createElement('a')
a.href = URL.createObjectURL(result.file)
a.download = buildDownloadName('photo', result.format)
a.click()

Legacy helpers ​

If you still hold a blob typed as image/pixu (older builds), these remap the payload for display:

HelperRole
createPreviewObjectURL(file, format?)Object URL safe for <img>
pixuToDisplayBlob(file)Same bytes, browser MIME
loadPixuImage(file)Decoded HTMLImageElement
detectPixuPayloadMime(buffer)Sniff WebP vs JPEG payload

New compressions do not need these for normal preview or download.

Released under the MIT License.