SwiftyImages
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
Filtering
- Brighten
- Contrast adjustment
- Edge detection
- Emboss
- Gamma correction
- Grayscale
- Invert
- Opacity
- Sepia
- Sharpen
- Unsharpen
- Blur
Masking
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)
Resizing
This extension can be used to crop to scale images.
Cropping
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
- Center
Scaling
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)
Rotating
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)
Saving
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)
Operator overloading
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)
UIColor extensions
Some utilities to create color from a hexadecimal value, invert a color and more.
CGContext extensions
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)
Classes
NYXProgressiveImageView
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/.
KawaiiColors
Class to match colors like iTunes 11.
let analyzer = KawaiiColors(image: myImage)
analyzer.analyze()
//analyzer.edgeColor
//analyzer.dominantColor
//analyzer.primaryColor
//analyzer.secondaryColor
//analyzer.thirdColor
LICENSE
SwiftyImages is released under the MIT License, see LICENSE file.