What does the PNG to ICO Converter do?
The PNG to ICO Converter converts Portable Network Graphics (.png) raster images into Windows Icon (.ico) resource containers and web favicons. Windows ICO files encapsulate one or more bitmap or PNG image streams paired with directory headers that specify pixel dimensions, color bit depth, and byte offset locations.
This utility validates PNG binary headers, reads intrinsic dimensions and alpha channel transparency from the IHDR chunk, and packages the data into standards-compliant ICONDIR and ICONDIRENTRY structures. It supports standard favicon resolutions (16x16, 32x32, 48x48, 64x64, 128x128, 256x256), custom dimensions, solid background fill compositing, and instant browser downloads.
Core Concepts
Working with Windows Icon (ICO) formats involves several binary data structures:
- ICONDIR Structure: The 6-byte file header starting with two reserved bytes (
0x0000), a 2-byte resource type (1for ICO,2for CUR cursor), and a 2-byte count field specifying the number of image frames. - ICONDIRENTRY Array: A 16-byte entry descriptor per image frame. It defines width and height in pixels (where
0denotes 256 pixels), palette color count, color planes, bits per pixel (e.g. 32-bit for RGBA), total payload byte size, and the absolute file offset where the image resource starts. - PNG Embedding in ICO: Since Windows Vista, the ICO specification natively allows direct embedding of raw PNG compressed bitstreams inside the icon resource block rather than raw uncompressed BMP DIB bitmaps. This preserves 8-bit alpha channel transparency and reduces favicon file sizes.
- Favicon Resolution Standards: Modern browsers request
32x32or16x16icons for browser tabs and bookmarks, while desktop shortcuts, taskbars, and high-DPI displays use48x48,64x64,128x128, and256x256resolutions.
How to use the tool?
- Upload or Paste PNG: Drag and drop a
.pngfile into the upload zone, click Browse File, or paste a Base64-encoded PNG Data URI into the text box. Click Load Sample to test with an example image. - Select Icon Size: Choose from standard icon resolution presets:
16 × 16 px(Browser Tab Favicon),32 × 32 px(Standard Favicon),48 × 48 px(Windows Medium Icon),64 × 64 px(High-DPI Display),128 × 128 px(App Launcher / Dock),256 × 256 px(Full Windows 11 / Vista HD), or select Custom Dimensions. - Configure Background: Select Transparent Alpha to preserve transparency, or choose Solid White, Dark Navy, or Custom Color with the hex code input.
- Convert & Download: Click Convert to ICO. The tool generates a live preview, shows the resulting byte size, and provides a direct Download button for
favicon.icoalongside ready-to-use HTML<link rel="icon">tags and Base64 Data URIs.
Related Developer Utilities
Complementary icon and image conversion tools on blueutils.com:
- ICO to PNG Converter: Extract and convert Windows ICO frames back into lossless PNG images.
- ICO to JPG Converter: Convert Windows ICO favicon files into compressed JPEG images.
- ICO to WebP Converter: Convert Windows ICO icons into high-efficiency WebP format.
- ICO to SVG Converter: Vectorize ICO favicons into scalable SVG code.
- PNG to WebP Converter: Convert PNG images into modern web-optimized WebP format.
- PNG to HEIC Converter: Convert PNG images into High Efficiency Image Container files.
- PNG to EPS Converter: Convert PNG images into Encapsulated PostScript vector files.
- PNG to PSD Converter: Convert PNG files into layered Adobe Photoshop documents.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/image/png-to-ico) for programmatic favicon and Windows icon 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.size |
Number | Optional. Square icon dimension preset (e.g. 16, 32, 48, 64, 128, 256). Defaults to 32. |
32 |
options.width |
Number | Optional. Explicit target width in pixels (16 to 256). | 64 |
options.height |
Number | Optional. Explicit target height in pixels (16 to 256). | 64 |
options.scale |
Number | Optional. Resolution scaling multiplier. | 1 |
options.bgColor |
String | Optional. Background color fill ("transparent", hex string like "#FFFFFF"). Defaults to "transparent". |
"transparent" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/image/png-to-ico \
-H "Content-Type: application/json" \
-d '{
"rawText": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNk+M9Qz0AEYBxVSF+FAAhKDveksOjuAAAAAElFTkSuQmCC",
"options": {
"size": 32,
"bgColor": "transparent"
}
}'Python
import requests
url = "https://blueutils.com/api/image/png-to-ico"
payload = {
"rawText": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNk+M9Qz0AEYBxVSF+FAAhKDveksOjuAAAAAElFTkSuQmCC",
"options": {
"size": 32,
"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\": {\"size\": 32, \"bgColor\": \"transparent\"}}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/image/png-to-ico"))
.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/x-icon"). |
"image/x-icon" |
originalFormat |
String | MIME type of source image ("image/png"). |
"image/png" |
dataUri |
String | Complete ICO Base64 Data URI. | "data:image/x-icon;base64,AAAB..." |
base64 |
String | Pure Base64-encoded ICO binary buffer string. | "AAABAAEA..." |
metadata |
Object | Dimensions, aspect ratio, frame count, byte sizes, and format details. | { "originalWidth": 10, "targetWidth": 32, ... } |
snippets |
Object | HTML <link rel="icon"> and Markdown embed snippets. |
{ "html": "<link rel=\"icon\"...>" } |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"mimeType": "image/x-icon",
"originalFormat": "image/png",
"dataUri": "data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAQ...",
"base64": "AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAQ...",
"metadata": {
"originalWidth": 10,
"originalHeight": 10,
"targetWidth": 32,
"targetHeight": 32,
"size": "32x32",
"bgColor": "transparent",
"bitDepth": 32,
"colorType": "RGBA Truecolor with Alpha",
"hasAlpha": true,
"frameCount": 1,
"formatType": "Windows Icon Resource (.ico)",
"aspectRatio": 1,
"originalSizeBytes": 70,
"icoSizeBytes": 92,
"formattedSize": "92 B"
},
"snippets": {
"html": "<link rel=\"icon\" type=\"image/x-icon\" href=\"data:image/x-icon;base64,...\">",
"htmlShortcut": "<link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\">",
"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 ICO?
Integrating the PNG to ICO API into build systems, static site generators, and CI/CD pipelines provides several benefits:
- Rapid Script Validation: Enables automated build tools and deployment scripts to generate cross-browser compatible
favicon.icofiles on the fly without heavy native image dependencies. - Optimized Token Efficiency for AI Agents: LLMs struggle with constructing binary structures like
ICONDIRheaders and byte offset arithmetic. Offloading ICO generation to a deterministic API saves valuable prompt and completion tokens. - Deterministic Accuracy Without Hallucinations: Image format byte structures require strict byte alignment and valid PNG data offsets. The API guarantees 100% compliant binary packaging.
Native Usage
How to convert PNG images to ICO format locally using native operating system tools and standard libraries:
Windows (PowerShell)
On Windows, PowerShell can use .NET and System.Drawing to create icons:
Add-Type -AssemblyName System.Drawing
$sourcePng = "favicon.png"
$targetIco = "favicon.ico"
$bitmap = [System.Drawing.Bitmap]::FromFile((Resolve-Path $sourcePng))
$hIcon = $bitmap.GetHicon()
$icon = [System.Drawing.Icon]::FromHandle($hIcon)
$fileStream = New-Object System.IO.FileStream($targetIco, [System.IO.FileMode]::Create)
$icon.Save($fileStream)
$fileStream.Close()
$icon.Dispose()
$bitmap.Dispose()
Write-Host "Created $targetIco successfully."Linux / Unix (Bash)
On Linux/macOS, use ImageMagick or standard CLI tools:
# Using ImageMagick CLI (multi-resolution standard favicon)
magick input.png -define icon:auto-resize=64,48,32,16 favicon.ico
# Or single-resolution conversion
magick input.png -resize 32x32 favicon.icoPython
Create a standard Windows ICO file from PNG bytes using the Python standard library:
import struct
def png_to_ico(png_path: str, ico_path: str, width: int = 32, height: int = 32):
"""Wraps a PNG file into a valid Windows ICO container using Python standard library."""
with open(png_path, "rb") as f:
png_bytes = f.read()
# 1. ICONDIR Header: [Reserved (2B), Type=1 (2B), Count=1 (2B)]
icondir = struct.pack("<HHH", 0, 1, 1)
# 2. ICONDIRENTRY: [Width (1B), Height (1B), Colors (1B), Reserved (1B), Planes (2B), BitCount (2B), BytesInRes (4B), ImageOffset (4B)]
w_byte = 0 if width >= 256 else width
h_byte = 0 if height >= 256 else height
data_offset = 6 + 16 # Header (6B) + 1 Entry (16B) = 22B
icondirentry = struct.pack("<BBBBHHII", w_byte, h_byte, 0, 0, 1, 32, len(png_bytes), data_offset)
with open(ico_path, "wb") as f:
f.write(icondir)
f.write(icondirentry)
f.write(png_bytes)
print(f"Created {ico_path} ({len(icondir) + len(icondirentry) + len(png_bytes)} bytes)")
# Example execution
png_to_ico("input.png", "favicon.ico", 32, 32)Java
Create an ICO container wrapping PNG bytes 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 PngToIcoConverter {
public static byte[] createIcoContainer(byte[] pngBytes, int width, int height) {
int dataOffset = 22; // 6 (ICONDIR) + 16 (ICONDIRENTRY)
ByteBuffer buf = ByteBuffer.allocate(dataOffset + pngBytes.length);
buf.order(ByteOrder.LITTLE_ENDIAN);
// ICONDIR
buf.putShort((short) 0); // idReserved
buf.putShort((short) 1); // idType = 1 (ICO)
buf.putShort((short) 1); // idCount = 1
// ICONDIRENTRY
byte bW = (byte) (width >= 256 ? 0 : width);
byte bH = (byte) (height >= 256 ? 0 : height);
buf.put(bW);
buf.put(bH);
buf.put((byte) 0); // bColorCount
buf.put((byte) 0); // bReserved
buf.putShort((short) 1); // wPlanes
buf.putShort((short) 32);// wBitCount
buf.putInt(pngBytes.length); // dwBytesInRes
buf.putInt(dataOffset); // dwImageOffset
// Image data
buf.put(pngBytes);
return buf.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);
}
byte[] ico = createIcoContainer(raw, 32, 32);
try (FileOutputStream fos = new FileOutputStream("favicon.ico")) {
fos.write(ico);
}
System.out.println("Converted to favicon.ico successfully.");
}
}