AdrianBV Posted August 25, 2013 Share Posted August 25, 2013 hi to all. I've been beating my head against the wall for a couple of days now trying to save a image as a valid ICNS file ( ICNS is the icon format for Mac OS ). Let's say I have a image of 128 x 128. I've managed to get the color and opacity for each pixel but I'm not really sure how the ICNS file format wants this data compressed. I found some pseudo-code but i can't figure out from that what I have to do: http://www.macdisk.com/maciconen.php3#RLE More info about icns file can be found on wiki: http://en.wikipedia.org/wiki/Apple_Icon_Image Does anybody have any good ideeas about this ? As wiki says, ( for example ) the 128 x 128 icns file should have the header it32, the 48x48 ih32, the 32x32 - il32 and the 16x16 - is32 $im = imagecreatefrompng("128.png"); $width = imagesx( $im ); $height = imagesy( $im ); $pixel_data = array(); $opacity_data = array(); $current_opacity_val = 0; for ( $y = $height - 1; $y >= 0; $y-- ) { for ( $x = 0; $x < $width; $x++ ) { $color = imagecolorat( $im, $x, $y ); $alpha = ( $color & 0x7F000000 ) >> 24; $alpha = ( 1 - ( $alpha / 127 ) ) * 255; $color &= 0xFFFFFF; $color |= 0xFF000000 & ( $alpha << 24 ); $pixel_data[] = $color; $opacity = ( $alpha <= 127 ) ? 1 : 0; $current_opacity_val = ( $current_opacity_val << 1 ) | $opacity; if ( ( ( $x + 1 ) % 32 ) == 0 ) { $opacity_data[] = $current_opacity_val; $current_opacity_val = 0; } } if ( ( $x % 32 ) > 0 ) { while ( ( $x++ % 32 ) > 0 ) $current_opacity_val = $current_opacity_val << 1; $opacity_data[] = $current_opacity_val; $current_opacity_val = 0; } } Thanks in advance for any help you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/281541-saving-image-as-icns/ Share on other sites More sharing options...
AdrianBV Posted August 26, 2013 Author Share Posted August 26, 2013 Nobody ? Quote Link to comment https://forums.phpfreaks.com/topic/281541-saving-image-as-icns/#findComment-1446781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.