Sometime we need to process an image, whether we are saving it to a file, combining it with another image or using it for some other purpose, but there are many ways to do this. Some ways use an image processing library, which contains many methods for image processing and sometimes even comes with a library specific to the image format or memory size. Others use a function call at the command line, which is often fast but limited. There are also other ways, but these are almost always slow and might not be the most suitable for the task.
You know that feeling of dread when you have a requirement for a new feature in your app, and you’re hoping to come up with a clean and elegant design to achieve it? This is when you need to use a Library. But, how do you find a library that will do the job?
Processing images is a crucial part of many applications that need to manipulate images. From mobile games to computer vision to machine learning, there are a huge number of image processing task that will benefit from a fast and efficient image processing library like this one.
Toucan is a Swift library that provides a clean and fast API for image processing. It simplifies image editing by supporting resizing, cropping and shaping of images.
Characteristics
- Simple and smart resizing
- Hiding elliptical and rounded rectangles
- Mask with user-defined images
- The chain steps of image processing
Requirements
Setting
- Installation with CocoaPods: https://cocoapods.org/pods/Toucan
- or activate the Toucan framework manually by dragging it into your project and importing the library into your code with import Toucan
Use of toucan
Toucan offers two ways to interact, either by wrapping an individual image in a Toucan instance, or by using static functions that supply an image for each call. This means that it can be used in a very flexible way.
Create an instanti wrapper to simplify the method chain:
let resizedAndMaskedImage = Toucan(image : myimage).resize(CGSize(width : 100, height : 150)).maskWithEllipse().image
You can also use static methods if you only need one operation:
let resizedImage = Toucan.Resize.resizeImage(myImage, size : CGSize(width : 100, height : 150))
let resizedAndMaskedImage = Toucan.maskWithEllipse(resizedImage)
In general, the instance version is a bit easier to use, which is exactly what you need.
Size change
Resizes the image to the specified size. Depending on the chosen fitMode, the image will be cropped, framed or scaled.
Toucan(image : myimage).resize(size : CGSize, fitMode : Toucan.Resize.FitMode)
Setting mode
FitMode controls the resizing process and determines what should happen to the image to fit within the specified size limits.
Example | Mode |
---|---|
Clip.FitMode.Clip Toucan.Resize.FitMode.Clip Resizes the image within the width and height limits without cropping or distorting it.Toucan(image : portraitImage).resize(CGSize(width : 500, height : 500), fitMode : Toucan.Resize.FitMode.Clip).image |
|
Crop Mode Toucan.Resize.FitMode.crop Resizes the image to fill the width and height margins and crop excess image data.Toucan(image : portrait).resize(CGSize(width : 500, height : 500), fitMode : Toucan.Resize.FitMode.Crop).image |
|
Scale mode Toucan.Resize.FitMode.scale Enlarge the image to exactly match the dimensions of the bounding box.Toucan(image : portraitImage).resize(CGSize(width : 500, height : 500), fitMode : Toucan.Resize.FitMode.Scale).image |
Masking
Modifies the original image with a mask; supports ellipse, rounded rectangle, and image masks.
Elliptical mask
Example | Function |
---|---|
Masks a specified image with an ellipse. Specify an additional frame to be drawn on the cropped image. For a circle, make sure the width and height of the image are the same!
Toucan(image: myimage).maskwithEllipse().image |
|
If the edge width is specified, it will be drawn on the cropped image.
Toucan(image : myimage).mask-with-eellipse(borderwidth : 10, bordercolor : UIColor.yellowcolor()).image |
Runway mask
Example | Function |
---|---|
Hides the specified image with an outline. The outline is scaled for correct image placement!
path.moveToPoint(CGPointMake(0, 50) |
|
Hides a specified image via a path specified by a closure. Allows you to build a path relative to the edges of the image!
Toucan(image : myimage).mask-with-path(path : (rectangle : CGRect) -> (UIBezierPath)).image |
Rounded rectangular mask
Example | Function |
---|---|
Conceals a specified image with a rounded rectangular border. Specify an additional frame to be drawn on the cropped image.
Toucan(image: myimage).maskwithroundRect(angleRadius: 30).image |
|
If the width of the border is specified, it is drawn on a trimmed rounded rectangle.
Toucan(image: myimage).mask-with-edge(cornerRadius: 30, borderWidth: 10, borderColor: UIColor.purpleColor()).image |
Image mask
Example | Function |
---|---|
Mask the specified image with another image mask. Note that the areas of the original image that correspond to the black areas of the mask will be translucent in the resulting image. The areas corresponding to the white areas of the mask are not painted. The areas corresponding to the gray areas of the mask are drawn with an intermediate alpha value equal to 1 minus the value of the image mask pattern.
Toucan(image : myimage).mask-with-image(mask-image : octagonMask).image |
Sample images
The sample images are used under a Creative Commons license with attribution:
GitHub
https://github.com/gavinbunney/ToucanBefore you dive into this article, here’s a quick overview of my approach to Swift. I personally believe that the language is too young to judge and that most of its shortcomings are due to the slow implementation, not the language itself. However, since I consider Swift to be a great language (unlike many others), I have been working towards making the language better.. Read more about image gallery swift github and let us know what you think.
Related Tags:
photo filter swift githubiphone image processingqcropperswiftui image processingimage gallery swift githubcrop-image ios github,People also search for,Privacy settings,How Search works,photo filter swift github,iphone image processing,qcropper,swiftui image processing,image gallery swift github,crop-image ios github,image viewer in ios swift github,image segmentation in swift