| Crates.io | imgico |
| lib.rs | imgico |
| version | 0.1.3 |
| created_at | 2026-01-05 02:29:15.856417+00 |
| updated_at | 2026-01-11 15:44:11.654871+00 |
| description | High-performance image to ICO/SVG converter with WebAssembly support |
| homepage | https://github.com/aciddust/imgico |
| repository | https://github.com/aciddust/imgico |
| max_upload_size | |
| id | 2022989 |
| size | 522,818 |
High-performance image to ICO/SVG converter built with Rust.
Features:
If you wanna specific version, add to your Cargo.toml:
[dependencies]
imgico = "0.1.3"
cargo install imgico
Build from source:
# Install wasm-pack
cargo install wasm-pack
# Build
wasm-pack build --target web
use imgico::{imgico_core, imgsvg_core};
use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read input image
let input = fs::read("input.png")?;
// Convert to ICO with default sizes [16, 32, 48, 64, 128, 256]
let ico_data = imgico_core(&input, None)?;
fs::write("output.ico", ico_data)?;
// Convert to ICO with custom sizes
let custom_ico = imgico_core(&input, Some(vec![16, 32, 48]))?;
fs::write("custom.ico", custom_ico)?;
// Convert to SVG (default size)
let svg_data = imgsvg_core(&input, None)?;
fs::write("output.svg", svg_data)?;
// Convert to SVG with specific size
let sized_svg = imgsvg_core(&input, Some(512))?;
fs::write("output_512.svg", sized_svg)?;
Ok(())
}
Convert image to ICO format:
imgico input.png -f ico
Convert image to SVG format:
imgico input.png -f svg
This creates a directory with timestamped name containing multiple sizes (16, 32, 48, 64, 128, 256).
import init, { imgico, imgsvg } from './pkg/imgico.js';
async function convertImage() {
// Initialize the Wasm module
await init();
// Load image as Uint8Array
const response = await fetch('input.png');
const arrayBuffer = await response.arrayBuffer();
const inputBuffer = new Uint8Array(arrayBuffer);
// Convert to ICO with default sizes
try {
const icoData = imgico(inputBuffer);
downloadFile(icoData, 'icon.ico');
} catch (e) {
console.error('ICO conversion failed:', e);
}
// Convert to ICO with custom sizes
try {
const customIco = imgico(inputBuffer, new Uint32Array([16, 32, 64]));
downloadFile(customIco, 'custom.ico');
} catch (e) {
console.error('Custom ICO conversion failed:', e);
}
// Convert to SVG
try {
const svgData = imgsvg(inputBuffer, 512);
const svgString = new TextDecoder().decode(svgData);
console.log(svgString);
} catch (e) {
console.error('SVG conversion failed:', e);
}
}
function downloadFile(data, filename) {
const blob = new Blob([data], { type: 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
convertImage();
imgico_core(input: &[u8], sizes: Option<Vec<u32>>) -> Result<Vec<u8>, String>Convert an image to ICO format.
Parameters:
input - Input image data (PNG, JPEG, WebP, etc.)sizes - Optional vector of icon sizes. Default: [16, 32, 48, 64, 128, 256]Returns: ICO file data as bytes
Example:
let ico = imgico_core(&image_data, Some(vec![16, 32, 64]))?;
imgsvg_core(input: &[u8], size: Option<u32>) -> Result<Vec<u8>, String>Convert an image to SVG format with embedded PNG.
Parameters:
input - Input image datasize - Optional target width/height. If None, uses original sizeReturns: SVG file data as bytes
Example:
let svg = imgsvg_core(&image_data, Some(512))?;
imgico(input: Uint8Array, sizes?: Uint32Array) -> Uint8ArrayConvert an image to ICO format.
Parameters:
input - Input image data as Uint8Arraysizes - Optional array of icon sizes. Default: [16, 32, 48, 64, 128, 256]Returns: ICO file data as Uint8Array
Example:
const icoData = imgico(inputBuffer, new Uint32Array([16, 32]));
imgsvg(input: Uint8Array, size?: number) -> Uint8ArrayConvert an image to SVG format.
Parameters:
input - Input image data as Uint8Arraysize - Optional target width/heightReturns: SVG file data as Uint8Array
Example:
const svgData = imgsvg(inputBuffer, 512);
const svgString = new TextDecoder().decode(svgData);
image crate)# Clone the repository
git clone https://github.com/aciddust/imgico
cd imgico/rust
# Build Rust library/CLI
cargo build --release
# Build WebAssembly
wasm-pack build --target web --release
# Run tests
cargo test
The library is optimized for both speed and size:
MIT OR Apache-2.0