What is Inkwell?
Inkwell is a powerful image editing library for iOS and macOS, designed to make it easy to apply filters and effects to images in your app. Whether you need to adjust the brightness, add a vintage look, or apply artistic effects, Inkwell provides a simple and intuitive API to achieve professional-level results.
Key Features
- Over 50 built-in filters and effects
- Support for custom filters with a simple API
- Real-time preview of filters
- Adjustable filter parameters
- Easy integration with existing projects
- Support for both iOS and macOS platforms
Usage Guide
Using Inkwell in your project is straightforward, and the library provides a set of APIs to help you achieve the desired image effects. Here’s a quick guide to get you started:
Installation
To begin using Inkwell, you’ll need to add it to your project’s dependencies. Here’s how:
1. Open your project in Xcode.
2. Add Inkwell to your project’s Podfile
:
pod 'Inkwell', '~> 2.0'
3. Run the command pod install
in the terminal to install Inkwell.
4. Open your project’s workspace file (.xcworkspace
).
5. Import the Inkwell framework in the files where you’ll be using it:
import Inkwell
With Inkwell installed and imported, you’re ready to start applying filters to your images.
Applying Filters
Applying filters to your images with Inkwell is a breeze. Here’s an example that demonstrates the basic usage:
// Load an image
let image = UIImage(named: "example.jpg")
// Create an Inkwell context with the image
let context = CIContext()
guard let imageCI = CIImage(image: image!) else { return }
let inkwellContext = InkwellContext(inputImage: imageCI, ciContext: context)
// Apply a filter
let filteredImage = inkwellContext.applyFilter(.vintage)
// Display the filtered image
let filteredImageView = UIImageView(image: filteredImage)
self.view.addSubview(filteredImageView)
In the above example, we load an image, create an Inkwell context with the image, apply the “vintage” filter, and display the filtered image on a UIImageView. You can replace the .vintage
filter with any other filter from the extensive set provided by Inkwell.
Custom Filters
In addition to the built-in filters, Inkwell allows you to create custom filters by chaining existing filters or creating custom Core Image filters. Here’s an example of creating a custom filter:
// Define a custom filter
let customFilter = CIKernel(source: """
kernel vec4 customFilter(sampler originalImage) {
vec4 color = sample(originalImage, samplerCoord(originalImage));
// Apply custom effects here
return color;
}
""")
// Apply the custom filter
inkwellContext.addCustomFilter(customFilter)
// Apply other filters
inkwellContext.applyFilter(.vintage)
// Display the final filtered image
let filteredImage = inkwellContext.outputImage
let filteredImageView = UIImageView(image: filteredImage)
self.view.addSubview(filteredImageView)
In the above code, we define a custom filter using a CIKernel object, add it to the Inkwell context, apply other filters (in this case, the “vintage” filter), and display the final filtered image as before.
Adjustable Filter Parameters
Inkwell allows you to tweak the parameters of some filters to achieve the desired effect. Here’s an example of how to adjust a filter’s parameters:
// Apply a filter with adjustable parameters
inkwellContext.applyFilter(.brightness).setValue(0.5, forKey: "inputBrightness")
// Apply other filters
inkwellContext.applyFilter(.vintage)
// Display the final filtered image
let filteredImage = inkwellContext.outputImage
let filteredImageView = UIImageView(image: filteredImage)
self.view.addSubview(filteredImageView)
In the above example, we apply the “brightness” filter and set its “inputBrightness” parameter to 0.5. You can adjust parameters for other filters as well by referencing the appropriate key.
With these examples, you should have a good starting point for using Inkwell’s powerful image editing capabilities in your iOS and macOS projects. Enjoy enhancing your images with Inkwell!