SVG-Native (SVG OpenType) image coder plugin for SDWebImage

Overview

SDWebImageSVGNativeCoder

CI Status Version License Platform

Background

Currently SDWebImage org provide 3 kinds of SVG Coder Plugin support, here is comparison:

Plugin Name Vector Image Bitmap Image Platform Compatibility Dependency
SVGNativeCoder NO YES iOS 9+ Best and W3C standard adobe/svg-native-viewer
SVGCoder YES YES iOS 13+ OK but buggy on some SVG Apple CoreSVG(Private)
SVGKitPlugin YES NO iOS 9+ Worst, no longer maintain SVGKit/SVGKit

For now, I recommand to use this SVGNativeCoder (this repo) for most cases, until there are any other native support on Apple platforms.

SVG-Native

SVG Native is an upcoming specification of the SVG WG based on SVG OpenType.

SVG Native will be a strict subset of SVG 1.1 and SVG 2.0.

Requirements

  • iOS 9+
  • tvOS 9+
  • macOS 10.11+
  • watchOS 2+

Installation

CocoaPods

SDWebImageSVGNativeCoder is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SDWebImageSVGNativeCoder'

Carthage

SDWebImageSVGNativeCoder is available through Carthage.

github "SDWebImage/SDWebImageSVGNativeCoder"

Swift Package Manager

SDWebImageSVGNativeCoder is available through Swift Package Manager.

let package = Package(
    dependencies: [
        .package(url: "https://github.com/SDWebImage/SDWebImageSVGNativeCoder.git", from: "0.1")
    ]
)

Usage

Register Coder Plugin

To use SVG coder, you should firstly add the SDImageSVGNativeCoder to the coders manager. Then you can call the View Category method to start load SVG images. See Wiki - Coder Usage here for these steps.

  • Objective-C
// register coder, on AppDelegate
SDImageSVGNativeCoder *SVGCoder = [SDImageSVGNativeCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:SVGCoder];
  • Swift
// register coder, on AppDelegate
let SVGCoder = SDImageSVGNativeCoder.shared
SDImageCodersManager.shared.addCoder(SVGCoder)

Render SVG as bitmap image

This coder plugin only support bitmap SVG image, which means once you load an image, even you change the image view size, the image size will not dynamic change and has to stretch up and may be blur. So you'd better provide the suitable large enough image size (like your image view size).

By default it use the SVG viewBox size. You can also specify a desired size during image loading using .imageThumbnailPixelSize context option. And you can specify whether or not to keep aspect ratio during scale using .imagePreserveAspectRatio context option.

  • Objective-C
UIImageView *imageView;
CGSize bitmapSize = CGSizeMake(500, 500);
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextThumbnailPixelSize: @(bitmapSize)];
  • Swift
let imageView: UIImageView
let bitmapSize = CGSize(width: 500, height: 500)
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : bitmapSize])

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Screenshot

Author

DreamPiggy

License

SDWebImageSVGNativeCoder is available under the MIT license. See the LICENSE file for more info.

You might also like...
Cordova plugin to display a native color-picker dialog

Color Picker Plugin for Cordova (cordova-plugin-color-picker) Description This plugin allows you to display a color-picker native dialog in iOS and An

Elegant SVG animation kit for swift
Elegant SVG animation kit for swift

Elephant This is SVG animation presentation kit for iOS. Example You can run example app. Please open Example-iOS/Elephant-iOS.xcworkspace! Usage You

❄️  SVG in Swift
❄️ SVG in Swift

Snowflake ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut ma

A simple, performant, and lightweight SVG parser
A simple, performant, and lightweight SVG parser

Key Features Parsing performance that meets or beats other popular SVG Frameworks A simple architecture, optimized for extension, flexibility and deve

Powerful and easy-to-use vector graphics Swift library with SVG support
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

A simple, performant, and lightweight SVG parser
A simple, performant, and lightweight SVG parser

Key Features Parsing performance that meets or beats other popular SVG Frameworks A simple architecture, optimized for extension, flexibility and deve

❄️  SVG in Swift
❄️ SVG in Swift

Snowflake ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut ma

Powerful and easy-to-use vector graphics Swift library with SVG support
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

A Swift library for parsing and drawing SVG images to CoreGraphics contexts.

SwiftDraw A Swift library for parsing and drawing SVG images to CoreGraphics contexts. SwiftDraw can also convert an SVG into Swift source code. Usage

SVG parser and renderer written in SwiftUI
SVG parser and renderer written in SwiftUI

SVGView SVG parser written in SwiftUI We are a development agency building phenomenal apps. Overview The goal of this project is to bring the full pow

Tool to convert SVG to SwiftUI's Shape structure.
Tool to convert SVG to SwiftUI's Shape structure.

SVG to SwiftUI Converter Tool to convert SVG to SwiftUI's Shape structure. This approach is much more memory efficient than introducing a SVG library

ImageView - Component for loading and displaying different images aka SVG/PNG/JPG/JPEG

ImageView Component that loads and displays images(.svg/.png/.jpg/.jpeg) form as

 ALCameraViewController - A camera view controller with custom image picker and image cropping.
ALCameraViewController - A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

📷 A composable image editor using Core Image and Metal.
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component 🎉 v2.0.0-alpha now open!

An image download extension of the image view written in Swift for iOS, tvOS and macOS.
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

📷 A composable image editor using Core Image and Metal.
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component 🎉 v2.0.0-alpha now open!

A camera view controller with custom image picker and image cropping.
A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

SwiftUI animated image view that works on iOS and layout just as SwiftUI.Image

SwiftUI.AnimatedImage SwiftUI animated image view that works on iOS and layout just as SwiftUI.Image Screen.Recording.2021-07-31.at.02.18.33.mov Insta

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Comments
  • Cannot find 'SDImageSVGNativeCoder' in scope issue

    Cannot find 'SDImageSVGNativeCoder' in scope issue

    I installed this library using SPM. And when I add coder in SDImageCachesManager, and I get an error message "Cannot find 'SDImageSVGNativeCoder' in scope"

    Please check this

    thank you

    swiftpm 
    opened by dev-jiwon 7
  • 'svgnative/SVGDocument.h' file not found error when installing via CocoaPods

    'svgnative/SVGDocument.h' file not found error when installing via CocoaPods

    After adding SDWebImageSVGNativeCoder to the Podfile, the project fails to compile with 'svgnative/SVGDocument.h' file not found. The svgnative pod was also added in the Pod project.

    Adding ${PODS_ROOT}/svgnative/svg-native-viewer/svgnative/include/** to HEADER_SEARCH_PATHS fixed this issue.

    cocoapods 
    opened by AndreiArdelean1 3
  • image default Color is black

    image default Color is black

    After change the SVGKit to this lib, the image that show with white background color now display black bg, so can this lib open a interface or property to set the default color?

    svgnative 
    opened by iPermanent 5
Releases(0.1.1)
Owner
null
EbImagesSwiftUI - SDWebImageSwiftUI - a SwiftUI image loading framework, which based on SDWebImage

SDWebImageSwiftUI What's for SDWebImageSwiftUI is a SwiftUI image loading framew

An Tran 1 Jan 6, 2022
SDWebImageMockPlugin makes possible the creation of snapshot testing with views using SDWebImage to configure images

SDWebImageMockPlugin makes possible the creation of snapshot testing with views using SDWebImage to configure images.

FABERNOVEL 4 Oct 19, 2022
Kinopoisk clone iOS app using Swift, TMDb API, Youtube API and SDWebImage.

?? Kinopoisk clone iOS app using Swift, TMDb API, Youtube API and SDWebImage. App mainly developed to learn about Swift(UIKit), working with JSON, using MVVM architectural pattern.

ofigensky 1 Aug 20, 2022
Developed with use Swift language. As a third party library used SDWebImage. JSON parsing using URLSession with TMDB API. This app provide by the Core Data structure.

Capstone Project ?? About Developed with use Swift language. As a third party library used SDWebImage. JSON parsing using URLSession with TMDB API. Ad

Ensar Batuhan Unverdi 9 Aug 22, 2022
Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki Versions:

null 4.3k Jan 3, 2023
Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode

Stream Deck Xcode Plugin This repository contains a Stream Deck plugin to add so

Daniel Kennett 77 Dec 27, 2022
Plugin-spell-timer - Spell Timer Plugin for Outlander

Spell Timer Plugin for Outlander This plugin provides variables for spells from

Outlander 0 Jan 22, 2022
Cordova-plugin-saveimage - This plugin helps you save images

cordova-plugin-saveimage This plugin helps you save images on iOS/Android Instal

Bernat 2 May 11, 2022
Swift-lint-plugin - A SwiftPM plugin that adds a linting command

SwiftLintPlugin This is a SwiftPM plugin that adds a lint command. SwiftPM plugi

null 9 Nov 23, 2022
This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

null 0 Nov 2, 2021