MacNN Forums (https://forums.macnn.com/index.php)
-   macOS (https://forums.macnn.com/forumdisplay.php?f=90)
-   -   Icons are overweight. How do I reduce them? (https://forums.macnn.com/showthread.php?t=529271)

 
Uncle Skeleton Jan 22, 2024 11:58 AM
Icons are overweight. How do I reduce them?
I like to paste custom icons on files, in Finder. I recently updated to OS X Sonoma (14.2.1) from Big Sur, and now custom icons add about 1.5 to 2 MB to the file. That's insane.
I pulled out an older mac that still has High Sierra, and the custom icons there only add 50KB max. Actually, now that I think about it the enormous icons were probably in Big Sur too.

I want to be able to add 50KB custom icons using my current mac. How do I do it?

I tried to google this, and I found that I can use the cli app iconutil to create a .icns file (29KB, with a more-than-adequate 256x256 png image). But if I use Finder to copy this icon to a new file, the new file grows by 2MB, and if I copy the icon back out, into Preview, it has all these (superfluous) extra resolutions, which is probably why it's 2MB.

Thank you in advance
 
andi*pandi Jan 22, 2024 01:14 PM
long ago I would have checked the iconfactory for their handy icon app. but it seems they have moved on to bigger and brighter things.
 
reader50 Jan 22, 2024 04:27 PM
I used to apply custom picture icons. So they'd all render immediately in Finder when you open a pics folder. Today, those old pic files all show low-res icons. And most of the utilities I once used for adding or removing custom icons were lost after Mojave. They all seemed to be 32-bit.

I mostly let Finder generate icons on the fly now, and I could remove old custom icons one-at-a-time in the info dialog. Or I could do batches from Mojave. The problem hasn't annoyed me enough to do either. Yet.

If anyone knows of a 64-bit batch utility for generating / removing picture icons, I'd appreciate it. None of my old standbys are being maintained.
 
Uncle Skeleton Jan 23, 2024 10:43 AM
Thanks for the replies. Still pursuing...

Quote, Originally Posted by reader50 (Post 4432893)
I could remove old custom icons one-at-a-time in the info dialog. Or I could do batches from Mojave.
I just tested in Sonoma, search for ".jpeg", select all, get info, delete icon.
In so doing, I also learned you can get a "merged" info window even with few items, with cmd-opt-i.
Then while writing this comment, I learned that the File menu options in Finder change as you hold down modifier keys :eek:

Quote
If anyone knows of a 64-bit batch utility for generating / removing picture icons, I'd appreciate it. None of my old standbys are being maintained.
GraphicConverter? I haven't tried it with icons, but I have done batch conversions that maintain folder hierarchies
 
Uncle Skeleton Jan 23, 2024 11:56 AM
So I made some progress. Various sites say you can set icons with NSWorkspace in cocoa, and I didn't muster the trust to download and run someone's arbitrary app, I did write my own, and tentatively it works! It runs in Sonoma, and it creates file icons that only add KB not MB to the file size.

Here is my code:
Code:

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>

NSImage *resizedImage(NSImage *sourceImage)
{ // https://stackoverflow.com/questions/11949250/how-to-resize-nsimage/38442746#38442746
    if (! sourceImage.isValid) return nil;
   
    NSSize oldSize = [sourceImage size];
    NSSize newSize = NSMakeSize(oldSize.width, oldSize.width);
    if (oldSize.height > oldSize.width) newSize = NSMakeSize(oldSize.height, oldSize.height);
    NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
                            initWithBitmapDataPlanes:NULL
                            pixelsWide:newSize.width
                            pixelsHigh:newSize.height
                            bitsPerSample:8
                            samplesPerPixel:4
                            hasAlpha:YES
                            isPlanar:NO
                            colorSpaceName:NSCalibratedRGBColorSpace
                            bytesPerRow:0
                            bitsPerPixel:0];
    rep.size = newSize;
   
    [NSGraphicsContext saveGraphicsState];
    [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:rep]];
    int x = 0;
    int y = 0;
    if (oldSize.width > oldSize.height) {
        y = (newSize.height - oldSize.height) / 2;
    }
    if (oldSize.height > oldSize.width) {
        x = (newSize.width - oldSize.width) / 2;
    }
    [sourceImage drawInRect:NSMakeRect(x, y, oldSize.width, oldSize.height) fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
    [NSGraphicsContext restoreGraphicsState];
   
    NSImage *newImage = [[NSImage alloc] initWithSize:newSize];
    [newImage addRepresentation:rep];
    return newImage;
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"usage: iconia <image file> <destination file>");
        NSString *myImage = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
        NSString *myFile = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding];
        NSImage *im = [[NSImage alloc] initWithContentsOfFile:myImage];
        NSImage *im2 = resizedImage(im);
        [[NSWorkspace sharedWorkspace] setIcon:im2 forFile:myFile options:NSExclude10_4ElementsIconCreationOption];
    }
    return 0;
}

 
Brien Jan 27, 2024 01:37 AM
But why, I wonder, have the sizes embiggened?
 
reader50 Jan 27, 2024 02:39 AM
Retina displays.

also, our eyesight may not be what it used to be
 
CharlesS Jan 28, 2024 08:51 PM
It's because the modern icns format contains one 1024x1024 image, two 512x512 images, two 256x256 images, as well as all the 128x128 and smaller image sizes that were available way back in Mac OS X 4K78. The reason there are two of so many of these is because there's two sets of images; one for HiDPI mode and one for standard. So for example, one of the 512x512 images is actually a double-resolution version of the 256x256 for use on Retina displays, whereas the other one is a 512x512 version for standard displays, for anyone insane enough to have their icon size set that high. ;) All those images take up space.

If it makes you feel any better, the maximum size of a Mac resource fork is 16 MiB, so they won't be able to grow the sizes bigger than that (unless, of course, they finally move the custom icons out of the resource fork and into an extended attribute like they honestly probably should have done years ago).
 
andi*pandi Jan 29, 2024 01:11 PM
^this guy icons.
 
All times are GMT -4. The time now is 07:00 AM.

Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.