Skip to content

Instantly share code, notes, and snippets.

@A-Zak
Last active December 9, 2025 18:26
Show Gist options
  • Select an option

  • Save A-Zak/3c38d3f83f911a25790f to your computer and use it in GitHub Desktop.

Select an option

Save A-Zak/3c38d3f83f911a25790f to your computer and use it in GitHub Desktop.

Revisions

  1. A-Zak renamed this gist Oct 19, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. A-Zak created this gist Oct 19, 2015.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    extension UIImage {

    class func imageByCombiningImage(firstImage: UIImage, withImage secondImage: UIImage) -> UIImage {

    let newImageWidth = max(firstImage.size.width, secondImage.size.width )
    let newImageHeight = max(firstImage.size.height, secondImage.size.height)
    let newImageSize = CGSize(width : newImageWidth, height: newImageHeight)


    UIGraphicsBeginImageContextWithOptions(newImageSize, false, UIScreen.mainScreen().scale)

    let firstImageDrawX = round((newImageSize.width - firstImage.size.width ) / 2)
    let firstImageDrawY = round((newImageSize.height - firstImage.size.height ) / 2)

    let secondImageDrawX = round((newImageSize.width - secondImage.size.width ) / 2)
    let secondImageDrawY = round((newImageSize.height - secondImage.size.height) / 2)

    firstImage .drawAtPoint(CGPoint(x: firstImageDrawX, y: firstImageDrawY))
    secondImage.drawAtPoint(CGPoint(x: secondImageDrawX, y: secondImageDrawY))

    let image = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()


    return image
    }
    }