Skip to content

Commit

Permalink
Merge pull request #22 from wallisch/background-fill
Browse files Browse the repository at this point in the history
Fill launch image background appropriately when using Aspect Fit
  • Loading branch information
raphaelhanneken committed Oct 9, 2018
2 parents 7807293 + bfe2c7b commit abcaa75
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Iconizer/Helper/NSImageExtensions.swift
Expand Up @@ -35,9 +35,17 @@ extension NSImage {
let newSize = self.calculateAspectSize(withTargetSize: targetSize, aspectMode: aspectMode) ?? targetSize
let xCoordinate = round((targetSize.width - newSize.width) / 2)
let yCoordinate = round((targetSize.height - newSize.height) / 2)
let targetFrame = NSRect(origin: NSPoint.zero, size: targetSize)
let frame = NSRect(origin: NSPoint(x: xCoordinate, y: yCoordinate), size: newSize)

var backColor = NSColor.clear
if let tiff = self.tiffRepresentation, let tiffData = NSBitmapImageRep(data: tiff) {
backColor = tiffData.colorAt(x: 0, y: 0) ?? NSColor.clear
}

return NSImage(size: targetSize, flipped: false) { (_: NSRect) -> Bool in
backColor.setFill()
NSBezierPath.fill(targetFrame)
guard let rep = self.bestRepresentation(for: NSRect(origin: NSPoint.zero, size: newSize),
context: nil,
hints: nil) else {
Expand Down

0 comments on commit abcaa75

Please sign in to comment.