Created
August 6, 2017 16:09
-
-
Save sparrow/1857eed939c9904fb919e68a68940aff to your computer and use it in GitHub Desktop.
This is a Swift code snippet that we used for our blog post at RubyGarage https://rubygarage.org/. The next script template will work if you need to render an image and text over another image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let item = MediaItem(image: image) | |
let logoImage = UIImage(named: "logo") | |
let firstElement = MediaElement(image: logoImage!) | |
firstElement.frame = CGRect(x: 0, y: 0, width: logoImage!.size.width, height: logoImage!.size.height) | |
let testStr = "Test Attributed String" | |
let attributes = [ NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 35) ] | |
let attrStr = NSAttributedString(string: testStr, attributes: attributes) | |
let secondElement = MediaElement(text: attrStr) | |
secondElement.frame = CGRect(x: 300, y: 300, width: logoImage!.size.width, height: logoImage!.size.height) | |
item.add(elements: [firstElement, secondElement]) | |
let mediaProcessor = MediaProcessor() | |
mediaProcessor.processElements(item: item) { [weak self] (result, error) in | |
self?.resultImageView.image = result.image | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment