Saturday, May 10, 2025
Alternative Way
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use
No Result
View All Result
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use
No Result
View All Result
Alternative Way
No Result
View All Result

A Swift library that provides a clean and quick API for processing images

Gordon James by Gordon James
October 3, 2021
in World Tech Code
0 0
0
Home World Tech Code

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.

Table of Contents

Toggle
  • Characteristics
  • Requirements
  • Setting
  • Use of toucan
  • Size change
    • Setting mode
  • Masking
    • Elliptical mask
    • Runway mask
    • Rounded rectangular mask
    • Image mask
  • Sample images
  • GitHub
      • Related Tags:

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
A Swift library that provides a clean and quick API for processing images 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)
path.addLineToPoint(CGPointMake(50, 0)
path.addLineToPoint(CGPointMake(100, 50)
path.addLineToPoint(CGPointMake(50, 100)
path.closePath()
Toucan(image : myImage).maskWithPath(path : path).image

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

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
ShareTweet
Gordon James

Gordon James

Next Post
Convenient UITableViewCell subclass that implements a swippable content to trigger actions

Convenient UITableViewCell subclass that implements a swippable content to trigger actions

  • Trending
  • Comments
  • Latest
How To Get Free Internet On Android Without Service

How To Get Free Internet On Android Without Service

March 10, 2022
🥇 +4 Neo Geo Emulators for Android  List ▷ 2021

🥇 +4 Neo Geo Emulators for Android  List ▷ 2021

October 3, 2021

Fix: Notifications not working on Nova Launcher

October 3, 2021
How to Fix OpenVPN Connected but Not Changing IP Address

How to Fix OpenVPN Connected but Not Changing IP Address

October 3, 2021

Setting Up Directory Sync Between On-Premises Active Directory with Microsoft 365 Azure AD

0
🥇 DELETE ACCOUNT from PS4  ▷ Step by Step Guide ▷ 2020

🥇 DELETE ACCOUNT from PS4  ▷ Step by Step Guide ▷ 2020

0
🥇 PPTX File Extension  What is .Pptx and how to open them? ▷ 2020

🥇 PPTX File Extension  What is .Pptx and how to open them? ▷ 2020

0
🥇 Make a Crossword in Microsoft Word  Step by Step Guide ▷ 2020

🥇 Make a Crossword in Microsoft Word  Step by Step Guide ▷ 2020

0
What to Know About Car Shipping Services

What to Know About Car Shipping Services

May 7, 2025
CS2 Skins-Why Trade Them?

CS2 Skins-Why Trade Them?

May 7, 2025
Alternative Routes: Successfully Exiting Your Wyndham Timeshare Without The Stress

Alternative Routes: Successfully Exiting Your Wyndham Timeshare Without The Stress

May 6, 2025
The Ultimate Seiko Watch Gift Guide

The Ultimate Seiko Watch Gift Guide

May 1, 2025

There's always an alternative Way!
Find us at 4145 Zolynthian Street, Vylorthos, QP 78425
No Result
View All Result
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use

© 2022 - Alternative Way

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT
No Result
View All Result
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Travel News

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.