SwiftyImages is the continuation of NYXImagesKit, it's more modern, uses Swift 3 and requires at least iOS 9.3.
It's a framework which regroups a collection of useful extensions and classes to interact with images and colors.
UIImage / CGImage extensions
- Contrast adjustment
- Edge detection
- Gamma correction
This extension is composed of a single method which allows to mask an image with another one, you just have to create the mask image you desire.
let maskedImage = myImage.masked(withImage: maskImage)
This extension can be used to crop to scale images.
let croppedImage = myImage.cropped(toSize: CGSize(width, height))
You can crop your image by 9 different ways :
- Top left
- Top center
- Top right
- Bottom left
- Bottom center
- Bottom right
- Left center
- Right center
You have the choice between two methods to scale images, the two methods will keep the aspect ratio of the original image.
let scaledImage1 = myImage.scaled(factor: 0.5) let scaledImage2 = myImage.scaled(toSize: CGSize(width, height)
With this extension you can rotate, flip or reflect an image.
let reflectedImage = myImage.reflected() let flippedImage = myImage.horizontallyFlipped() let rotatedImage = myImage.rotated(degrees: 45.0)
This extension allows you to save an image at a specified path or file URL among these format : BMP, GIF, JPG, PNG, TIFF.
let success = myImage.save(to: yourURL) let success = myImage.save(toPath: yourPath, type: .jpg)
You can combine images using the
+ operator, it's a top composition.
let combinedImage = img1 + img2
Creating a gradient image
let gradient = UIImage.makeGrayGradient(width: width, height: height, fromAlpha: 1.0, toAlpha: 1.0)
Creating an image from a string
let stringImage = UIImage.makeFromString("SwiftyImages", font: textFont, fontColor: fontColor, backgroundColor: bgColor, maxSize: maxSize)
Some utilities to create color from a hexadecimal value, invert a color and more.
3 functions to easily get a bitmap context :
let bmContext = CGContext.ARGBBitmapContext(width: width, height: height, withAlpha: false) let bmContext = CGContext.RGBABitmapContext(width: width, height: height, withAlpha: true) let bmContext = CGContext.GrayBitmapContext(width: width, height: height)
This is a subclass of UIImageView to load asynchronously an image from an URL and display it as it is being downloaded. Image caching is supported. For more informations see https://cocoaintheshell.whine.fr/2012/01/nyximageskit-class-nyxprogressiveimageview/ and https://cocoaintheshell.whine.fr/2011/05/progressive-images-download-imageio/.
Class to match colors like iTunes 11.
let analyzer = KawaiiColors(image: myImage) analyzer.analyze() //analyzer.edgeColor //analyzer.dominantColor //analyzer.primaryColor //analyzer.secondaryColor //analyzer.thirdColor
SwiftyImages is released under the MIT License, see LICENSE file.