Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sparrow/1857eed939c9904fb919e68a68940aff to your computer and use it in GitHub Desktop.
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.
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