def main(args=None): if args is None: args = sys.argv if len(args) != 3: print("Usage: %s inputfile outputfile." % (args[0], )) return 0 infile = args[1] outfile = args[2] if not isinstance(infile, bytes): infile = infile.encode('utf-8') if not isinstance(outfile, bytes): outfile = outfile.encode('utf-8') # Create the data provider and data consumer. inputURL = Cocoa.CFURLCreateFromFileSystemRepresentation( None, infile, len(infile), False) outputURL = Cocoa.CFURLCreateFromFileSystemRepresentation( None, outfile, len(outfile), False) if inputURL is not None and outputURL is not None: convertPStoPDF(inputURL, outputURL) return 0
def main(args=None): if args is None: args = sys.argv path = b"output.pdf" url = Cocoa.CFURLCreateFromFileSystemRepresentation( None, path, len(path), False) if url is None: print("Couldn't create URL!") return 1 myCreate2PagePDFDocumentAtURL(url) return 0
def exportColorRampImageWithQT(context): width = 256 height = 256 bitsPerComponent = 8 bitsPerPixel = 24 bytesPerRow = width * 3 shouldInterpolate = True imageDataProvider = DataProvidersAndConsumers.createRGBRampDataProvider() if imageDataProvider is None: print("Couldn't create Image Data provider!") return colorspace = Utilities.getTheCalibratedRGBColorSpace() image = Quartz.CGImageCreate( width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, Quartz.kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, Quartz.kCGRenderingIntentDefault, ) del imageDataProvider if image is None: print("Couldn't create CGImageRef for this data!") return rect = Quartz.CGRectMake(0.0, 0.0, width, height) Quartz.CGContextDrawImage(context, rect, image) # Of course this is a total hack. outPath = b"/tmp/imageout.jpg" exportURL = Cocoa.CFURLCreateFromFileSystemRepresentation( None, outPath, len(outPath), False) if exportURL: exportCGImageToJPEGFile(image, exportURL)
def main(args=None): if args is None: args = sys.argv if len(args) < 2: print("Usage: %s inputfile ... " % (args[0], )) return 1 for inputFileName in args[1:]: print("Beginning Document %r" % (inputFileName, )) if not isinstance(inputFileName, bytes): inputFileName = inputFileName.encode("utf-8") inURL = Cocoa.CFURLCreateFromFileSystemRepresentation( None, inputFileName, len(inputFileName), False) if inURL is None: print("Couldn't create URL for input file!") return 1 dumpPageStreams(inURL, sys.stdout) return 0
def exportImageWithMaskFromURLWithDestination(context, imageURL, imagewidth, imageheight, bitsPerComponent, theMaskingImageURL, maskwidth, maskheight): imageBitsPerPixel = bitsPerComponent * 3 bytesPerRow = ((imagewidth * imageBitsPerPixel) + 7) / 8 shouldInterpolate = True imageDataProvider = Quartz.CGDataProviderCreateWithURL(imageURL) if imageDataProvider is None: print("Couldn't create Image Data provider!") return colorspace = Utilities.getTheCalibratedRGBColorSpace() image = Quartz.CGImageCreate(imagewidth, imageheight, bitsPerComponent, imageBitsPerPixel, bytesPerRow, colorspace, Quartz.kCGImageAlphaNone, imageDataProvider, None, shouldInterpolate, Quartz.kCGRenderingIntentDefault) del imageDataProvider if image is None: print("Couldn't create CGImageRef for this data!") return imageRect = Quartz.CGRectMake(0.0, imageheight, imagewidth, imageheight) # Draw the image. Quartz.CGContextDrawImage(context, imageRect, image) # Now the mask. maskDataProvider = Quartz.CGDataProviderCreateWithURL(theMaskingImageURL) if maskDataProvider is None: print("Couldn't create Image Data provider!") return mask = Quartz.CGImageMaskCreate(maskwidth, maskheight, bitsPerComponent, bitsPerComponent, maskwidth, maskDataProvider, None, shouldInterpolate) del maskDataProvider if mask is None: print("Couldn't create CGImageRef for mask data!") return # Draw the mask below the image. maskRect = Quartz.CGRectMake(0.0, 0.0, maskwidth, maskheight) Quartz.CGContextDrawImage(context, maskRect, mask) # Create a new CGImage object, the image, masked with mask. imageMaskedWithImage = Quartz.CGImageCreateWithMask(image, mask) # Once the new image is created, we can release the image # and the mask which make it up. Quartz retains what it needs # for the new masked image. del image del mask if imageMaskedWithImage is None: print("Couldn't create image masked with mask!") return imageRect = Quartz.CGRectMake(imagewidth, imageheight / 2, imagewidth, imageheight) # Draw the masked image to the right of the image and its mask. Quartz.CGContextDrawImage(context, imageRect, imageMaskedWithImage) # Of course this is a total hack. outPath = b"/tmp/imageout.png" exportURL = Cocoa.CFURLCreateFromFileSystemRepresentation( None, outPath, len(outPath), False) if exportURL is not None: Images.exportCGImageToPNGFileWithDestination(imageMaskedWithImage, exportURL)
def createURL(path): if not isinstance(path, bytes): path = path.encode('utf-8') return Cocoa.CFURLCreateFromFileSystemRepresentation(None, path, len(path), False)