Cross-platform Swift library for parsing SVGPath strings

Related tags

Image SVGPath
Overview

Build Codecov Platforms Swift 5.1 License Twitter

Introduction

SVGPath is an open-source parser for the SVG path syntax, making it easy to create CGPaths from this popular format.

SVGPath runs on all Apple platforms, and also Linux (although Linux does not support the CoreGraphics API, so if you need to draw the path you will need to provide your own implementation).

Installation

SVGPath is packaged as a dynamic framework that you can import into your Xcode project. You can install this manually, or by using Swift Package Manager.

Note: SVGPath requires Xcode 10+ to build, and runs on iOS 10+ or macOS 10.12+.

To install using Swift Package Manage, add this to the dependencies: section in your Package.swift file:

.package(url: "https://github.com/nicklockwood/SVGPath.git", .upToNextMinor(from: "1.0.0")),

Usage

You can create an instance of SVGPath as follows:

let svgPath = try SVGPath(string: "M150 0 L75 200 L225 200 Z")

Notice that the SVGPath constructor is a throwing function. It will throw an SVGError if the supplied string is invalid or malformed .

Once you have created an SVGPath object, in most cases you'll want to convert this to a CGPath for rendering on Apple platforms. To do that you can use:

let cgPath = CGPath.from(svgPath: svgPath)

As a shortcut, you can create the CGPath directly from an SVG path string:

let cgPath = try CGPath.from(svgPath: "M150 0 L75 200 L225 200 Z")

Once you have a CGPath you can render it on iOS or macOS using a CoreGraphics context or a CAShapeLayer.

Credits

The SVGPath library is primarily the work of Nick Lockwood.

(Full list of contributors)

You might also like...
Fast and simple OCR library written in Swift

⛔️ This Project is deprecated and no longer gets maintained! Please use Apple's Vision framework instead of SwiftOCR. It is very fast, accurate and mu

AlamofireImage is an image component library for Alamofire

AlamofireImage AlamofireImage is an image component library for Alamofire. Features Image Response Serializers UIImage Extensions for Inflation / Scal

CTPanoramaView is a library that displays spherical or cylindrical panoramas with touch or motion based controls.
CTPanoramaView is a library that displays spherical or cylindrical panoramas with touch or motion based controls.

CTPanoramaView is a high-performance library that uses SceneKit to display complete spherical or cylindrical panoramas with touch or motion based controls.

Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.
Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Kanvas Kanvas is an open-source iOS library for adding effects, drawings, text, stickers, and making GIFs from existing media or the camera.

Image filtering UI library like Instagram.
Image filtering UI library like Instagram.

Sharaku Usage How to present SHViewController let imageToBeFiltered = UIImage(named: "targetImage") let vc = SHViewController(image: imageToBeFiltered

Vision Camera 📸 The Camera library that sees the vision.
Vision Camera 📸 The Camera library that sees the vision.

Vision Camera 📸 The Camera library that sees the vision. npm i react-native-vision-camera npx pod-install Documentation Guides API Ex

Shows your photo library grouped by events, to easily export them to your computer
Shows your photo library grouped by events, to easily export them to your computer

Groupir Shows your photo library grouped by events, to easily export them to your computer Features Currently supported features: reading your photo l

A python library to run metal compute kernels on MacOS 12

metalcompute for Python A python library to run metal compute kernels on MacOS Usage Example execution from M1-based Mac running MacOS 12.0: ./build

iOS library for quickly displaying images while scrolling

Fast Image Cache is an efficient, persistent, and—above all—fast way to store and retrieve images in your iOS application. Part of any good iOS applic

Comments
  • SVGPath coordinate parse issue

    SVGPath coordinate parse issue

    let pathString = "M301 162L307 154L315 149L325 139.5L332.5 135.5L341 128.5L357.5 117.5L364.5 114.5L368.5 110.5L380 105.5L390.5 102L404 96L410.5 96L415 97.5L421 104L425.5 113.5L428.5 126L429.5 134L429.5 141L429.5 148L425.5 161.5L425.5 169L414 184.5L409.5 191L401 201L395 209L386 214.5L378.5 217L368 220L348 219.5L338 218L323.5 212.5L312 205.5L302.5 197.5L295.5 189L291.5 171.5L294 168L298 165.5L301 162z" for this path string, the result shape coordinate y seems flipped. 截屏2022-07-27 10 03 17

    opened by chenyunguiMilook 8
Owner
Nick Lockwood
Nick Lockwood
SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.

SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them type-safe to use.

null 8.3k Jan 5, 2023
A Swift client library for generating URLs with imgix

imgix-swift is a client library for generating image URLs with imgix. Written in Swift, but can be used with Objective-C codebases as well. Installati

imgix 24 Sep 28, 2022
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work

Wei Wang 20.9k Dec 30, 2022
🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations

MapleBacon Introduction MapleBacon is a lightweight and fast Swift library for downloading and caching images. Example The folder Example contains a s

Jan Gorman 335 Nov 1, 2022
Fast and simple OCR library written in Swift

⛔️ This Project is deprecated and no longer gets maintained! Please use Apple's Vision framework instead of SwiftOCR. It is very fast, accurate and mu

Nicolas Camenisch 4.5k Dec 29, 2022
A high-performance image library for downloading, caching, and processing images in Swift.

Features Asynchronous image downloader with priority queuing Advanced memory and database caching using YapDatabase (SQLite) Guarantee of only one ima

Yap Studios 72 Sep 19, 2022
AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.

AYImageKit AYImageKit is a Swift Library for Async Image Downloading. Features Async Image Downloading. Can Show Text Initials. Can have Custom Styles

Adnan Yousaf 11 Jan 10, 2022
A Fast and Complete Swift Drawing Library

FastDraw A Fast and Complete Swift Drawing Library Description FastDraw is a high performance and highly extensible Drawing Library that supports Appl

Collin Zhang 18 Nov 14, 2022
Swift Image Slider library for iOS

Banana - ImageSlider for Swift Image slider with very simple interface. At a Glance @IBOutlet weak var imageScrollView: UIScrollView! // Here imageArr

Gaurav Katoch 17 Apr 20, 2021
GPU-based media processing library using Metal written in Swift

GPU-based media processing library using Metal written in Swift. Overview MetalAcc is a GPU-Based media processing library that lets you apply GPU-acc

Jiawei Wang 259 Dec 17, 2022