def extract_icon(file_path): file_icon_tiff = NSWorkspace.sharedWorkspace().iconForFile_( file_path).TIFFRepresentation() file_icon_png = NSBitmapImageRep.imageRepWithData_( file_icon_tiff).representationUsingType_properties_(NSPNGFileType, None) file_icon_png_path = file_path + ".png" file_icon_png.writeToFile_atomically_(file_icon_png_path, None) return file_icon_png_path
def _init_from_file(self, file): #ns_image = NSImage.alloc().initWithContentsOfFile_(file) #if not ns_image: ns_data = NSData.dataWithContentsOfFile_(file) if not ns_data: raise EnvironmentError("Unable to read image file: %s" % file) ns_rep = NSBitmapImageRep.imageRepWithData_(ns_data) if not ns_rep: raise ValueError("Unrecognised image file type: %s" % file) ns_rep.setSize_((ns_rep.pixelsWide(), ns_rep.pixelsHigh())) self._init_from_ns_rep(ns_rep)
def _init_from_file(self, file): #ns_image = NSImage.alloc().initWithContentsOfFile_(file) #if not ns_image: ns_data = NSData.dataWithContentsOfFile_(file) if not ns_data: raise EnvironmentError("Unable to read image file: %s" % file) ns_rep = NSBitmapImageRep.imageRepWithData_(ns_data) if not ns_rep: raise ValueError("Unrecognised image file type: %s" % file) ns_rep.setSize_((ns_rep.pixelsWide(), ns_rep.pixelsHigh())) self._init_from_ns_rep(ns_rep)
def evaluateToFile_(self, filename): self.canvas.lockFocus() if self.clip: self.clip.setClip() if self.image: self.image.compositeToPoint_operation_((0,0), NSCompositeCopy) elif self.gradient: self.gradient.drawInBezierPath_angle_(self.clip, -90) elif self.color: self.clip.fill(self.color) self.canvas.unlockFocus() image_data = self.canvas.TIFFRepresentation() image_rep = NSBitmapImageRep.imageRepWithData_(image_data) data = image_rep.representationUsingType_properties_(NSPNGFileType, None) data.writeToFile_atomically_(filename, False)
import tempfile from mojo.roboFont import CurrentGlyph from AppKit import NSPNGFileType, NSBitmapImageRep g = CurrentGlyph() result = g.getRepresentation("money.money.money") if result: im, offset = result imagePath = tempfile.mkstemp(suffix=".png")[1] imageRep = NSBitmapImageRep.imageRepWithData_(im.TIFFRepresentation()) imageData = imageRep.representationUsingType_properties_(NSPNGFileType, None) imageData.writeToFile_atomically_(imagePath, True) g.addImage(path=imagePath, position=offset)
import tempfile from mojo.roboFont import CurrentGlyph from AppKit import NSPNGFileType, NSBitmapImageRep g = CurrentGlyph() result = g.getRepresentation("money.money.money") if result: im, offset = result imagePath = tempfile.mkstemp(suffix=".png")[1] imageRep = NSBitmapImageRep.imageRepWithData_(im.TIFFRepresentation()) imageData = imageRep.representationUsingType_properties_( NSPNGFileType, None) imageData.writeToFile_atomically_(imagePath, True) g.addImage(path=imagePath, position=offset)