Created
July 8, 2012 16:18
-
-
Save sholloway/3071583 to your computer and use it in GitHub Desktop.
Basic Core Image filtering and Image I/O
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework "Quartz" | |
input_a = "path/to/a/file" | |
input_b = "path/to/a/file" | |
output = "path/to/a/file" | |
#load images using Core Image (could have also used Image I/O | |
h_path = NSURL.fileURLWithPath(input_a,false) | |
forground_image = CIImage.alloc.initWithContentsOfURL(h_path) | |
b_path = NSURL.fileURLWithPath(input_b,false) | |
background_image = CIImage.alloc.initWithContentsOfURL(b_path) | |
#set up filter | |
filter = CIFilter.filterWithName("CIHardLightBlendMode")#CIOverlayBlendMode | |
filter.setDefaults() | |
filter.setValue(forground_image, forKey:"inputImage") | |
filter.setValue(background_image, forKey:"inputBackgroundImage") | |
#run the filter | |
output_image = filter.valueForKey("outputImage") | |
# get a CIContext to process the images | |
#Creates a Core Image context from a Quartz context | |
ci_context = CIContext.contextWithOptions(NSGraphicsContext.currentContext, options:nil) | |
#generate a CGImageRefs (Switch to Core Graphics) | |
cgimg_ref = ci_context.createCGImage(output_image, fromRect:output_image.extent) | |
#save to the file system using Image I/O | |
myImageDest = CGImageDestinationCreateWithURL(NSURL.fileURLWithPath(output,false), "public.jpeg", 1, nil) | |
CGImageDestinationAddImage(myImageDest, cgimg_ref, nil) | |
CGImageDestinationFinalize(myImageDest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment