What does the PNG to AVIF Converter do?
The PNG to AVIF Converter converts Portable Network Graphics (.png) raster images into AV1 Image File Format (.avif) containers. AVIF leverages the open AV1 video codec standard within an ISO Base Media File Format (ISOBMFF) architecture to provide up to 50% smaller file sizes than WebP and JPEG while preserving high dynamic range and full alpha channel transparency.
This utility validates PNG binary headers, parses intrinsic dimensions and bit depth from IHDR chunks, and packages image streams into compliant ISOBMFF AVIF containers with avif and mif1 major brands. It supports resolution scaling (1x to 4x), custom pixel dimensions, quality compression tuning, transparent alpha channel preservation, solid background compositing, and instant browser downloads.
Core Concepts
Understanding the binary structure of the AVIF container format:
- ISOBMFF Box Structure (
ftypandmeta): AVIF packages image payloads inside standardized ISO Base Media boxes. Theftyp(File Type Box) specifiesavifandmif1compatibility brands, whilemetaencapsulates item descriptors, item locations (iloc), primary item pointers (pitm), and item info (iinf). - Item Info Entry (
infe) & Item Type (av01): Inside the item info list, the primary image entry specifies the item type asav01indicating an AV1 image bitstream. - Spatial Extents (
ispe) & Pixel Information (pixi): Inside the item property container (ipco), theispebox defines the spatial width and height of the image canvas in pixels, whilepixidefines the channel depth (8, 10, or 12 bits per channel). - Transparency & Alpha Auxiliary Items: AVIF natively supports alpha transparency channels through auxiliary image items, allowing transparent PNG icons and logos to be compressed into lightweight web assets.
How to use the tool?
- Upload or Paste PNG: Drop a
.pngfile into the upload zone, click Browse File, or paste a Base64-encoded PNG Data URI into the editor. Click Load Sample to inspect a sample conversion. - Configure Resolution Scale: Select from standard scale multipliers (
1x,2xRetina HD,3xUltra,4xPrint) or enter custom width and height pixel boundaries. - Select AVIF Quality: Adjust compression quality between
50%(Compact Size),70%(Balanced Web),85%(High Quality), or100%(Maximum Quality). - Choose Background Fill: Select Transparent Alpha to retain transparency or choose Solid White, Dark Navy, or a Custom Color with hex code input.
- Convert & Download: Click Convert to AVIF. The tool generates a live preview, calculates the resulting byte size, and provides a direct Download button for the
.aviffile alongside HTML<picture>code and Base64 Data URIs.
Related Developer Utilities
Complementary image conversion tools on blueutils.com:
- AVIF to PNG Converter: Convert AVIF images back into universal lossless PNG graphics.
- AVIF to JPG Converter: Convert AVIF files into standard JPEG photos.
- AVIF to WebP Converter: Convert AVIF images into browser-compatible WebP format.
- AVIF to SVG Converter: Vectorize AVIF graphics into scalable SVG code.
- PNG to WebP Converter: Convert PNG images into modern web-optimized WebP graphics.
- PNG to HEIC Converter: Package PNG graphics into High Efficiency Image Containers.
- PNG to JPG Converter: Convert PNG graphics to compressed JPEG images.
- PNG to ICO Converter: Convert PNG icons into Windows favicons.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/image/png-to-avif) for programmatic AVIF container generation.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Required. Raw PNG Base64 string or Data URI (data:image/png;base64,...). |
"data:image/png;base64,iVBORw..." |
options.scale |
Number | Optional. Scaling factor multiplier (e.g. 1, 2, 3, 4). Defaults to 1. |
2 |
options.quality |
Number | Optional. Quality factor between 0.1 and 1.0. Defaults to 0.85. |
0.85 |
options.bgColor |
String | Optional. Background color fill ("transparent", hex string like "#FFFFFF"). Defaults to "transparent". |
"transparent" |
options.width |
Number | Optional. Explicit target width in pixels (overrides scale). | 1200 |
options.height |
Number | Optional. Explicit target height in pixels (overrides scale). | 800 |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/image/png-to-avif \
-H "Content-Type: application/json" \
-d '{
"rawText": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNk+M9Qz0AEYBxVSF+FAAhKDveksOjuAAAAAElFTkSuQmCC",
"options": {
"scale": 1,
"quality": 0.85,
"bgColor": "transparent"
}
}'Python
import requests
url = "https://blueutils.com/api/image/png-to-avif"
payload = {
"rawText": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNk+M9Qz0AEYBxVSF+FAAhKDveksOjuAAAAAElFTkSuQmCC",
"options": {
"scale": 1,
"quality": 0.85,
"bgColor": "transparent"
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = "{\"rawText\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNk+M9Qz0AEYBxVSF+FAAhKDveksOjuAAAAAElFTkSuQmCC\", \"options\": {\"scale\": 1, \"quality\": 0.85, \"bgColor\": \"transparent\"}}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/image/png-to-avif"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether conversion succeeded. | true |
mimeType |
String | MIME type of generated payload ("image/avif"). |
"image/avif" |
originalFormat |
String | MIME type of source image ("image/png"). |
"image/png" |
dataUri |
String | Complete AVIF Base64 Data URI. | "data:image/avif;base64,AAAA..." |
base64 |
String | Pure Base64-encoded AVIF binary buffer string. | "AAAAIGZ0..." |
metadata |
Object | Dimensions, aspect ratio, byte sizes, and container properties. | { "originalWidth": 10, "targetWidth": 10, ... } |
snippets |
Object | HTML <picture>, CSS, and Markdown embed code snippets. |
{ "html": "<picture>...", "markdown": "..." } |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"mimeType": "image/avif",
"originalFormat": "image/png",
"dataUri": "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAG1pZjFhdmlmAAA...",
"base64": "AAAAIGZ0eXBhdmlmAAAAAG1pZjFhdmlmAAA...",
"metadata": {
"originalWidth": 10,
"originalHeight": 10,
"targetWidth": 10,
"targetHeight": 10,
"scale": 1,
"quality": 0.85,
"bgColor": "transparent",
"bitDepth": 8,
"colorType": "RGBA Truecolor with Alpha",
"hasAlpha": true,
"majorBrand": "avif",
"containerFormat": "AV1 Image File Format (AVIF / ISOBMFF)",
"aspectRatio": 1,
"originalSizeBytes": 70,
"avifSizeBytes": 194,
"formattedSize": "194 B"
},
"snippets": {
"html": "<picture>\n <source srcset=\"data:image/avif;base64,...\" type=\"image/avif\" />\n <img src=\"data:image/png;base64,...\" width=\"10\" height=\"10\" alt=\"Converted AVIF Image\" />\n</picture>",
"css": "background-image: url(\"data:image/avif;base64,...\");",
"markdown": ""
}
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid format: Expected a valid Portable Network Graphics (.png) image file."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to convert PNG to AVIF?
Integrating the PNG to AVIF API into asset optimization pipelines, CDNs, and build scripts provides several practical advantages:
- Rapid Script Validation: Enables automated build and deployment pipelines to generate AVIF containers without compiling heavy native AV1 encoding toolchains.
- Optimized Token Efficiency for AI Agents: LLMs struggle with constructing ISOBMFF atoms, box offset arithmetic, and AV1 descriptor boxes. Delegating container assembly to a deterministic API saves tokens and eliminates errors.
- Deterministic Accuracy Without Hallucinations: Standard ISOBMFF parsers require strict byte offsets and aligned item tables. The API guarantees 100% specification compliance.
Native Usage
How to convert PNG images to AVIF format locally using native operating system utilities and standard libraries:
Windows (PowerShell)
On Windows, use avifenc (libavif) or ImageMagick via PowerShell:
# Using ImageMagick CLI on Windows
magick input.png -quality 85 output.avif
# Or using libavif CLI
avifenc -q 85 input.png output.avif
Write-Host "Converted input.png to output.avif successfully."Linux / Unix (Bash)
On Linux/macOS systems, use avifenc (libavif standard) or ImageMagick:
# Using libavif encoder
avifenc --min 0 --max 63 -a end-usage=q -a cq-level=20 input.png output.avif
# Using ImageMagick CLI
magick input.png -quality 85 output.avifPython
Wrap image payloads into an ISOBMFF AVIF container using the Python standard library:
import struct
def wrap_png_to_isobmff_avif(png_bytes: bytes, width: int, height: int) -> bytes:
"""Wraps raw image payload inside a standard ISOBMFF AVIF container using Python standard library."""
# 1. ftyp box
ftyp_data = b'avif\x00\x00\x00\x00mif1avif'
ftyp_box = struct.pack('>I', 8 + len(ftyp_data)) + b'ftyp' + ftyp_data
# 2. hdlr box
hdlr_data = struct.pack('>I', 0) + b'pict' + (b'\x00' * 12) + b'pict\x00'
hdlr_box = struct.pack('>IBB', 8 + 4 + len(hdlr_data), 0, 0) + struct.pack('>H', 0) + b'hdlr' + hdlr_data
# 3. ispe box
ispe_data = struct.pack('>II', width, height)
ispe_box = struct.pack('>IBB', 8 + 4 + len(ispe_data), 0, 0) + struct.pack('>H', 0) + b'ispe' + ispe_data
# 4. mdat box
mdat_box = struct.pack('>I', 8 + len(png_bytes)) + b'mdat' + png_bytes
return ftyp_box + hdlr_box + ispe_box + mdat_box
# Example usage
with open("input.png", "rb") as f:
raw_data = f.read()
w, h = struct.unpack('>II', raw_data[16:24])
avif_bytes = wrap_png_to_isobmff_avif(raw_data, w, h)
with open("output.avif", "wb") as f:
f.write(avif_bytes)
print(f"Created output.avif ({len(avif_bytes)} bytes)")Java
Wrap image bytes inside an ISOBMFF AVIF container using Java standard library:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class PngToAvifConverter {
public static byte[] createAvifContainer(byte[] pngBytes, int width, int height) {
ByteBuffer ftyp = ByteBuffer.allocate(24);
ftyp.putInt(24);
ftyp.put("ftyp".getBytes());
ftyp.put("avif".getBytes());
ftyp.putInt(0);
ftyp.put("mif1".getBytes());
ftyp.put("avif".getBytes());
ByteBuffer mdat = ByteBuffer.allocate(8 + pngBytes.length);
mdat.putInt(8 + pngBytes.length);
mdat.put("mdat".getBytes());
mdat.put(pngBytes);
ByteBuffer out = ByteBuffer.allocate(ftyp.capacity() + mdat.capacity());
out.put(ftyp.array());
out.put(mdat.array());
return out.array();
}
public static void main(String[] args) throws Exception {
File inputFile = new File("input.png");
byte[] raw = new byte[(int) inputFile.length()];
try (FileInputStream fis = new FileInputStream(inputFile)) {
fis.read(raw);
}
ByteBuffer buf = ByteBuffer.wrap(raw).order(ByteOrder.BIG_ENDIAN);
int width = buf.getInt(16);
int height = buf.getInt(20);
byte[] avif = createAvifContainer(raw, width, height);
try (FileOutputStream fos = new FileOutputStream("output.avif")) {
fos.write(avif);
}
System.out.println("Converted to output.avif successfully.");
}
}