daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Nov 18th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension UIImage {
  2.  
  3.     static func imageByMergingImages(topImage: UIImage, bottomImage: UIImage, scaleForTop: CGFloat = 1.0) -> UIImage {
  4.         let size = bottomImage.size
  5.         let container = CGRect(x: 0, y: 0, width: size.width, height: size.height)
  6.         UIGraphicsBeginImageContextWithOptions(size, false, 2.0)
  7.         UIGraphicsGetCurrentContext()!.interpolationQuality = .high
  8.         bottomImage.draw(in: container)
  9.  
  10.         let topWidth = size.width / scaleForTop
  11.         let topHeight = size.height / scaleForTop
  12.         let topX = (size.width / 2.0) - (topWidth / 2.0)
  13.         let topY = (size.height / 2.0) - (topHeight / 2.0)
  14.  
  15.         topImage.draw(in: CGRect(x: topX, y: topY, width: topWidth, height: topHeight), blendMode: .normal, alpha: 1.0)
  16.  
  17.         return UIGraphicsGetImageFromCurrentImageContext()!
  18.     }
  19.  
  20. }
RAW Paste Data
Top