Spooner/releasy — Issue #21: Auto-convert root PNG 'icon.png' to 'icon.icns' with this handy script
Author: jlnr
Created: 2012-02-26 14:40:39+00:00
State: open

Since you are not on IRC...I just hacked this together, it works fine on my 10.7 system. Adding support for 512x512 and 1024x1024px icons would be trivial too. Do you think we could get some autoconversion going here?

```ruby
# Source: http://en.wikipedia.org/wiki/Apple_Icon_Image_format

def png_to_icns(filename_256x256_png)
magic_bytes = 'icns'
os_type_256 = 'ic08'
png_256 = File.read(filename_256x256_png)
size_256 = [png_256.length + 8].pack('N')
file_size = [png_256.length + 16].pack('N')

"#{magic_bytes}#{file_size}#{os_type_256}#{size_256}#{png_256}"
end

if $0 == __FILE__ then
File.open('test.icns', 'w') do |out_file|
out_file.print png_to_icns('icon-256.png')
end
end
```