Git Product home page Git Product logo

ftassetrenderer's Introduction

FTAssetRenderer

Create image assets, at runtime, in any color when used as mask and/or at any resolution when it’s a PDF.

Install

If you’re using CocoaPods, add the following to your Podfile:

pod 'FTAssetRenderer'

Otherwise, simply add the files from the Source dir to your project.

Usage

If you have a bitmap image that’s used as a mask to generate images in different colors, then you can use it like so:

FTImageAssetRenderer *renderer = [FTAssetRenderer rendererForImageNamed:@"my-icon" withExtension:@"png"];
renderer.targetColor = [UIColor redColor];
UIImage *result = [renderer imageWithCacheIdentifier:@"red"];

If, on the other hand, you have a vector based PDF image, you should generally indicate the size at which it should be rendered as well:

FTPDFAssetRenderer *renderer = [FTAssetRenderer rendererForPDFNamed:@"my-scalable-icon"];
renderer.targetColor = [UIColor blueColor];
renderer.targetSize = CGSizeMake(123, 456);
UIImage *result = [renderer imageWithCacheIdentifier:@"without-preserving-aspect-ratio"];

In the above example, an explicit width and height is given for the result image, which might lead to the image not preserving its original aspect ratio. To ensure the ratio is preserved, a few convience methods are available:

  • -[FTPDFAssetRenderer fitWidth:] will make the result image as wide as the given width, while the height is based on it.
  • -[FTPDFAssetRenderer fitHeight:] will make the result image as high as the given height, while the width is based on it.
  • -[FTPDFAssetRenderer fitSize:] will make the image as large as possible, inside the bounding size, but without cropping any part of the image, thus only fully covering one of the two sides.

By default, the resulting image is cached on disk. For each different target color, a different cache identifier should be used. For instance, for controls you might use identifiers such as normal, highlighted, and selected.

Acknowledgements

Based on work by:

Thanks to Peter Steinberger (of PSPDFKit fame) for his invaluable advice during the creation of this library.

ftassetrenderer's People

Contributors

alloy avatar manfred avatar myell0w avatar patrick-kladek avatar schwmi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.