0.0.7 • Published 3 years ago

@fiahfy/icns v0.0.7

Weekly downloads
245
License
MIT
Repository
github
Last release
3 years ago

icns

badge

Apple Icon Image format parser and builder.

Installation

npm install @fiahfy/icns

Usage

Parsing

import fs from 'fs'
import { Icns } from '@fiahfy/icns'

const buf = fs.readFileSync('icon.icns')
const icns = Icns.from(buf)
const imagesAsBuffers = icns.images.map((icon) => icon.image)

Note that the images may be encoded in different file formats, in accordance with Apple's icon type specifications.

Building

import fs from 'fs'
import { Icns, IcnsImage } from '@fiahfy/icns'

const icns = new Icns()
let buf, image

buf = fs.readFileSync('512x512.png')
image = IcnsImage.fromPNG(buf, 'ic09')
icns.append(image)

buf = fs.readFileSync('1024x1024.png')
image = IcnsImage.fromPNG(buf, 'ic10')
icns.append(image)

/* Some other PNG files */

fs.writeFileSync('icon.icns', icns.data)

API

Class: Icns

static from(buffer)

Create ICNS from the icon buffer.

buffer

Type: Buffer

The ICNS icon buffer.

append(image)

Adds ICNS image at the end.

image

Type: IcnsImage

The ICNS Image to append.

insert(image, index)

Inserts ICNS image at the specified position.

image

Type: IcnsImage

The ICNS Image to insert.

index

Type: number

The position at which to insert the ICNS Image.

remove(index)

Removes ICNS image at the specified position.

index

Type: number

The position of the ICNS Image to remove.

fileHeader

Type: IcnsFileHeader

Return the file header on the ICNS.

images

Type: IcnsImage[]

Return the ICNS images on the ICNS.

data

Type: Buffer

Return the ICNS buffer.

Class: IcnsImage

static from(buffer)

Create ICNS image from the buffer.

buffer

Type: Buffer

The ICNS image buffer.

static fromPNG(buffer, osType)

Create ICNS Image from the PNG image buffer.

buffer

Type: Buffer

The PNG image buffer.

osType

Type: OSType

The icon OSType.

Class: IcnsFileHeader

static from(buffer)

Create ICNS file header from the buffer.

buffer

Type: Buffer

The ICNS file header buffer.

Specifications

Supported OSTypes

OSTypeOS VersionSizeDescription
is328.51616×16 24-bit icon
il328.53232x32 24-bit icon
ih328.54848×48 24-bit icon
it3210.0128128x128 24-bit icon
s8mk8.51616x16 8-bit mask
l8mk8.53232×32 8-bit mask
h8mk8.54848×48 8-bit mask
t8mk10.0128128x128 8-bit mask
ic041616x16 ARGB
ic053232x32 ARGB
icp410.71616x16 icon in PNG format
icp510.73232x32 icon in PNG format
icp610.76464x64 icon in PNG format
ic0710.7128128x128 icon in PNG format
ic0810.5256256×256 icon in PNG format
ic0910.5512512×512 icon in PNG format
ic1010.710241024×1024 in 10.7 (or 512x512@2x "retina" in 10.8) icon in PNG format
ic1110.83216x16@2x "retina" icon in PNG format
ic1210.86432x32@2x "retina" icon in PNG format
ic1310.8256128x128@2x "retina" icon in PNG format
ic1410.8512256x256@2x "retina" icon in PNG format