# icnsutil
A fully-featured python library to handle reading and writing `.icns` files.
## Install
The easy way is to use the PyPi.org index:
```sh
pip3 install icnsutil
```
Or you can install it **manually** by creating a symlink to `cli.py`:
```sh
ln -s '/absolute/path/to/icnsutil/icnsutil/cli.py' /usr/local/bin/icnsutil
ln -s '/absolute/path/to/icnsutil/icnsutil/autosize/cli.py' /usr/local/bin/icnsutil-autosize
```
Or call the python module (if the module is in the search path):
```sh
python3 -m icnsutil
python3 -m icnsutil.autosize
```
## Usage
See [#tools](#tools) for further options on icns processing (e.g., autosize).
```
positional arguments:
command
extract (e) Read and extract contents of icns file(s).
compose (c) Create new icns file from provided image files.
update (u) Update existing icns file by inserting or removing media entries.
info (i) Print contents of icns file(s).
test (t) Test if icns file is valid.
convert (img) Convert images between PNG, ARGB, or RGB + alpha mask.
```
### Use command line interface (CLI)
```sh
# extract
icnsutil e Existing.icns -o ./outdir/
# compose
icnsutil c New.icns 16x16.png 16x16@2x.png *.jp2 --toc
# update
icnsutil u Existing.icns -rm toc ic04 ic05
icnsutil u Existing.icns -set is32=16.rgb dark="dark icon.icns"
icnsutil u Existing.icns -rm dark -set ic04=16.argb -o Updated.icns
# print
icnsutil i Existing.icns
# verify valid format
icnsutil t Existing.icns
# convert image
icnsutil img 1024.png 512@2x.jp2
# or reuse original filename
icnsutil img argb 16x16.png
icnsutil img rgb 32.png
icnsutil img png 16.rgb 16.mask
```
### Use python library
```python
import icnsutil
# extract
img = icnsutil.IcnsFile('Existing.icns')
img.export(out_dir, allowed_ext='png',
recursive=True, convert_png=True)
# compose
img = icnsutil.IcnsFile()
img.add_media(file='16x16.png')
img.add_media(file='16x16@2x.png')
img.write('./new-icon.icns')
# update
img = icnsutil.IcnsFile('Existing.icns')
img.add_media('icp4', file='16x16.png', force=True)
if img.remove_media('TOC '):
print('table of contents removed')
img.write('Existing.icns', toc=True)
# print
# return type str
desc = icnsutil.IcnsFile.description(fname, indent=2)
print(desc)
# verify valid format
# return type Iterator[str]
itr = icnsutil.IcnsFile.verify(fname)
print(list(itr))
# If you just want to check if a file is faulty, you can use `any(itr)` instead.
# This way it will not test all checks but break early after the first hit.
```
#### Converting between (A)RGB and PNG
You can use the library without installing PIL.
However, if you want to convert between PNG and ARGB files, Pillow is required.
```sh
pip install Pillow
```
```python
import icnsutil
# Convert from ARGB to PNG
icnsutil.ArgbImage(file='16x16.argb').write_png('16x16.png')
# Convert from PNG to 24-bit RGB
img = icnsutil.ArgbImage(file='32x32.png')
with open('32x32.rgb', 'wb') as fp:
fp.write(img.rgb_data())
with open('32x32.mask', 'wb') as fp:
fp.write(img.mask_data())
```
Note: the CLI `export` command will fail if you run `--convert` without Pillow.
## Tools
### Autosize
`icnsutil.autosize` is a tool to automatically generate smaller icon sizes from a larger one.
Currently, autosize has support for “normal” raster images (via sips or Pillow) and SVG images (via [resvg] or Chrome Headless).
```sh
icnsutil-autosize icon.svg -32 intermediate.png -16 small.svg
# or
python3 -m icnsutil.autosize icon.svg -32 intermediate.png -16 small.svg
```
Additionally, `autosize` will also try to convert 32px and 16px PNG images to ARGB.
If Pillow is not installed, this step will be skipped (without negative side effects).
The output is an iconset folder with all necessary images.
You may ask why this tool does not create the icns file immediatelly?
This way you can modify the generated images before packing them into an icns file.
For example, you can run [ImageOptim] to compress the images and reduce the overall icns filesize.
[resvg]: https://github.com/RazrFalcon/resvg/
[ImageOptim]: https://github.com/ImageOptim/ImageOptim
### HTML icon viewer
Here are two tools to open icns files directly in your browser. Both tools can be used either with an icns file or a rgb / argb image file.
- The [inspector] shows the structure of an icns file (useful to understand byte-unpacking in ARGB and 24-bit RGB files).
- The [viewer] displays icons in ARGB or 24-bit RGB file format.
[inspector]: https://relikd.github.io/icnsutil/html/inspector.html
[viewer]: https://relikd.github.io/icnsutil/html/viewer.html
## Help needed
1. Do you have an old macOS version running somewhere?
You can help and identify what file formats / icns types were introduced and when. Download the [format-support-icns.zip] file and report back which icons are displayed properly and in which macOS version.
See the [Apple Icon Image](https://en.wikipedia.org/wiki/Apple_Icon_Image) wikipedia article.
2. You can run `make sys-icons-test` and report back whether you find some weird icons that are not handled properly by this library.
[format-support-icns.zip]: https://github.com/relikd/icnsutil/raw/main/tests/format-support-icns.zip
Raw data
{
"_id": null,
"home_page": "https://github.com/relikd/icnsutil",
"name": "icnsutil",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "icns,icon,extract,compose,create",
"author": "relikd",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/50/fd/fa849e34e71468ffce0a8067cf1a99f15697b7d3d192b233ffa9ef112039/icnsutil-1.1.0.tar.gz",
"platform": null,
"description": "# icnsutil\n\nA fully-featured python library to handle reading and writing `.icns` files.\n\n## Install\n\nThe easy way is to use the PyPi.org index:\n\n```sh\npip3 install icnsutil\n```\n\nOr you can install it **manually** by creating a symlink to `cli.py`:\n\n```sh\nln -s '/absolute/path/to/icnsutil/icnsutil/cli.py' /usr/local/bin/icnsutil\nln -s '/absolute/path/to/icnsutil/icnsutil/autosize/cli.py' /usr/local/bin/icnsutil-autosize\n```\n\nOr call the python module (if the module is in the search path):\n\n```sh\npython3 -m icnsutil\npython3 -m icnsutil.autosize\n```\n\n\n## Usage\n\nSee [#tools](#tools) for further options on icns processing (e.g., autosize).\n\n```\npositional arguments:\n command\n extract (e) Read and extract contents of icns file(s).\n compose (c) Create new icns file from provided image files.\n update (u) Update existing icns file by inserting or removing media entries.\n info (i) Print contents of icns file(s).\n test (t) Test if icns file is valid.\n convert (img) Convert images between PNG, ARGB, or RGB + alpha mask.\n```\n\n\n### Use command line interface (CLI)\n\n```sh\n# extract\nicnsutil e Existing.icns -o ./outdir/\n\n# compose\nicnsutil c New.icns 16x16.png 16x16@2x.png *.jp2 --toc\n\n# update\nicnsutil u Existing.icns -rm toc ic04 ic05\nicnsutil u Existing.icns -set is32=16.rgb dark=\"dark icon.icns\"\nicnsutil u Existing.icns -rm dark -set ic04=16.argb -o Updated.icns\n\n# print\nicnsutil i Existing.icns\n\n# verify valid format\nicnsutil t Existing.icns\n\n# convert image\nicnsutil img 1024.png 512@2x.jp2\n# or reuse original filename\nicnsutil img argb 16x16.png\nicnsutil img rgb 32.png\nicnsutil img png 16.rgb 16.mask\n```\n\n\n### Use python library\n\n```python\nimport icnsutil\n\n# extract\nimg = icnsutil.IcnsFile('Existing.icns')\nimg.export(out_dir, allowed_ext='png',\n recursive=True, convert_png=True)\n\n# compose\nimg = icnsutil.IcnsFile()\nimg.add_media(file='16x16.png')\nimg.add_media(file='16x16@2x.png')\nimg.write('./new-icon.icns')\n\n# update\nimg = icnsutil.IcnsFile('Existing.icns')\nimg.add_media('icp4', file='16x16.png', force=True)\nif img.remove_media('TOC '):\n print('table of contents removed')\nimg.write('Existing.icns', toc=True)\n\n# print\n# return type str\ndesc = icnsutil.IcnsFile.description(fname, indent=2)\nprint(desc)\n\n# verify valid format\n# return type Iterator[str]\nitr = icnsutil.IcnsFile.verify(fname)\nprint(list(itr))\n# If you just want to check if a file is faulty, you can use `any(itr)` instead.\n# This way it will not test all checks but break early after the first hit.\n```\n\n\n#### Converting between (A)RGB and PNG\n\nYou can use the library without installing PIL.\nHowever, if you want to convert between PNG and ARGB files, Pillow is required.\n\n```sh\npip install Pillow\n```\n\n```python\nimport icnsutil\n\n# Convert from ARGB to PNG\nicnsutil.ArgbImage(file='16x16.argb').write_png('16x16.png')\n\n# Convert from PNG to 24-bit RGB\nimg = icnsutil.ArgbImage(file='32x32.png')\nwith open('32x32.rgb', 'wb') as fp:\n fp.write(img.rgb_data())\nwith open('32x32.mask', 'wb') as fp:\n fp.write(img.mask_data())\n```\n\nNote: the CLI `export` command will fail if you run `--convert` without Pillow.\n\n\n## Tools\n\n### Autosize\n\n`icnsutil.autosize` is a tool to automatically generate smaller icon sizes from a larger one.\nCurrently, autosize has support for \u201cnormal\u201d raster images (via sips or Pillow) and SVG images (via [resvg] or Chrome Headless).\n\n```sh\nicnsutil-autosize icon.svg -32 intermediate.png -16 small.svg\n# or\npython3 -m icnsutil.autosize icon.svg -32 intermediate.png -16 small.svg\n```\n\nAdditionally, `autosize` will also try to convert 32px and 16px PNG images to ARGB.\nIf Pillow is not installed, this step will be skipped (without negative side effects).\nThe output is an iconset folder with all necessary images.\n\nYou may ask why this tool does not create the icns file immediatelly?\nThis way you can modify the generated images before packing them into an icns file.\nFor example, you can run [ImageOptim] to compress the images and reduce the overall icns filesize.\n\n[resvg]: https://github.com/RazrFalcon/resvg/\n[ImageOptim]: https://github.com/ImageOptim/ImageOptim\n\n\n### HTML icon viewer\n\nHere are two tools to open icns files directly in your browser. Both tools can be used either with an icns file or a rgb / argb image file.\n\n- The [inspector] shows the structure of an icns file (useful to understand byte-unpacking in ARGB and 24-bit RGB files).\n- The [viewer] displays icons in ARGB or 24-bit RGB file format.\n\n[inspector]: https://relikd.github.io/icnsutil/html/inspector.html\n[viewer]: https://relikd.github.io/icnsutil/html/viewer.html\n\n## Help needed\n\n1. Do you have an old macOS version running somewhere? \nYou can help and identify what file formats / icns types were introduced and when. Download the [format-support-icns.zip] file and report back which icons are displayed properly and in which macOS version. \nSee the [Apple Icon Image](https://en.wikipedia.org/wiki/Apple_Icon_Image) wikipedia article.\n\n2. You can run `make sys-icons-test` and report back whether you find some weird icons that are not handled properly by this library.\n\n[format-support-icns.zip]: https://github.com/relikd/icnsutil/raw/main/tests/format-support-icns.zip\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A fully-featured python library to handle reading and writing icns files.",
"version": "1.1.0",
"split_keywords": [
"icns",
"icon",
"extract",
"compose",
"create"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b657030441e24d057dacbbbc0eaec4cc94160984a295cebe1e9f69f0a55717d9",
"md5": "bdc1e78bb151ffd1ef66d580327d0b19",
"sha256": "fd8a16e385b75bbf76735762b03b3c9319d1fa6624e5dba9d320c7ee30cb6425"
},
"downloads": -1,
"filename": "icnsutil-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bdc1e78bb151ffd1ef66d580327d0b19",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 26605,
"upload_time": "2023-03-18T12:20:07",
"upload_time_iso_8601": "2023-03-18T12:20:07.910657Z",
"url": "https://files.pythonhosted.org/packages/b6/57/030441e24d057dacbbbc0eaec4cc94160984a295cebe1e9f69f0a55717d9/icnsutil-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "50fdfa849e34e71468ffce0a8067cf1a99f15697b7d3d192b233ffa9ef112039",
"md5": "4aa2c678399bfaded03b5525d1986670",
"sha256": "fb1556edf0077af5d78934d8da887d3810acc29ee28716df70b7f805f781ed77"
},
"downloads": -1,
"filename": "icnsutil-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "4aa2c678399bfaded03b5525d1986670",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 23675,
"upload_time": "2023-03-18T12:20:09",
"upload_time_iso_8601": "2023-03-18T12:20:09.198977Z",
"url": "https://files.pythonhosted.org/packages/50/fd/fa849e34e71468ffce0a8067cf1a99f15697b7d3d192b233ffa9ef112039/icnsutil-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-18 12:20:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "relikd",
"github_project": "icnsutil",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "icnsutil"
}