Frage

Does anybody know how to convert images with MacRuby (or normal ruby)? I would imagine that the 'ScriptingBridge' framework would be able to handle it.

In addition, I would prefer not to use ImageMagick or the like (something lighter would be fine, however).

Thanks!

War es hilfreich?

Lösung

you can do this with MacRuby:

 framework 'AppKit'

 input_file_path = "/Users/username/Desktop/input_file.png"
 img_data = NSData.dataWithContentsOfFile(input_file_path)
 bitmap = NSBitmapImageRep.imageRepWithData(img_data)

 new_data = bitmap.representationUsingType(NSJPEGFileType, properties: nil)  # NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType.

 output_file_path = "/Users/username/Desktop/output_file.jpeg"
 new_data.writeToFile(output_file_path, atomically: true)

and you're done, NSBitmapImageRep#representationUsingType:properties: can takes NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType or NSTIFFFileType for bmp, gif, jpeg, png or tiff

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top