1. Products
  2.   Image
  3.   Swift
  4.   SwiftImage

Open Source Swift Library for Image Processing

Free Swift API provides the capability to handle image processing tasks such as  images rotation, flipping and resizing images, cropping image, image conversion to other format, and many more

SwiftImage is a very powerful Swift image processing open source library that enables software developers to work with different kinds of images using Swift code. The library can easily access pixels of the images and modify them according to as required. It is a high-performance e image library that gives developers the capability to download, cache, and process images with ease

The SwiftImage library is very stable as well as feature-rich and has included several important features for handling their images such as rotating images, flipping and resizing images, image cropping, image conversion to other formats, applying filters and image Binarization, and many more. The library is very powerful and can convert an RGBA image to greyscale with just one-liner code.

One great feature of the SwiftImage library is that it supports the copy-on-write process that’s why image instances can never be shared and defensive copying is unnecessary. The library uses Image with the RGBA type which is a generic type and represents various formats of pixels. The library also supports gray-scale images without nested parameters. It supports both 8-bit and 16-bit greyscale images.

Previous Next

Getting Started with SwiftImage

You can easily install SwiftImage is using Swift Package Manager. Please use the following command for a smooth installation.

Install SwiftImage via Github 

 .package(url: "https://github.com/koher/swift-image.git", from: "0.7.0"),

Image Resizing via Swift

The open source SwiftImage library gives software developers the capability to resize images inside their own Swift applications with a couple of lines of code. The library makes it easy for software developers to load and resize images using several important functions such as resizing an image by providing width & height, cropping an image to custom size, applying a filter to an image, and many more.

Resize Image via Swift API

let result = image.resizedTo(width: 320, height: 240)

let result = image.resizedTo(width: 320, height: 240,
    interpolatedBy: .nearestNeighbor) // Nearest neighbor

Rotate, Flip or iterate Images via Swift API

The SwiftImage library has provided complete support for programmatically rotating as well as Flipping images using Swift commands. Developers can use different available functions to flip the image, such as flipping images horizontally as well as vertically. Developers can also flip as well as iterate images according to their own needs and save them back on disk at the place of their choice.

Rotate or Crop Image via Swift API

//Rotate Image 
let result = image.rotated(by: .pi) // Rotated clockwise by π
let result = image.rotated(byDegrees: 180) // Rotated clockwise by 180 degrees

//Crop Image 

let slice: ImageSlice> = image[32..<64, 32..<64] // No copying costs
let cropped = Image>(slice) // Copying is executed here

Image Filtering Support via Swift

Image filtering is a very useful technique that helps developers to modify or enhance images with ease. The open source SwiftImage library has provided different types of very useful filters that can be applied to images to enhance their properties inside Swift applications.  The library supports several important filters such as mean filter, Gaussian filter, enhanced edges, blur images, image brightness, and many more.

Apply Gaussian Filter to Image via Github 

let kernel = Image(width: 5, height: 5, pixels: [
    1,  4,  6,  4, 1,
    4, 16, 24, 16, 4,
    6, 24, 36, 24, 6,
    4, 16, 24, 16, 4,
    1,  4,  6,  4, 1,
]).map { Float($0) / 256.0 }
let result = image.convoluted(kernel)