1

I currently have an NSData with valid PNG data:
NSData* imageData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];

I've written this data out to a file:
[imageData writeToFile:@"test.png" atomically:YES];
And compressing it with OptiPNG or PNGCrush yields promising results (25%+ compression).

I'd like to perform this task in memory, adding a category to NSData to enable something like:
[imageData optimizePNGData]

However, file system calls are baked in deeply into both OptiPNG and PNGCrush, making neither of them fit to be built as a library (e.g. optipng.a).

Does anyone have any ideas of how to accomplish something similar without relying on exec calls as most of the GUI wrappers do?

Jonathan
  • 11
  • 1

1 Answers1

0

If you can build these libraries and link them into your process, but your issue is that they operate on paths and not blocks of bytes, you could create a named pipe with mkfifo and then feed one end of the pipe with data from your process and pass the other end into the function from OptiPNG or PNGCrush. You'll need to feed the pipe continuously during the call to the library, so you'll probably need a second thread.

You can read about mkfifo() with "man 2 mkfifo" in terminal.app.

Jon Hess
  • 14,237
  • 1
  • 47
  • 51