This project is taken from SwiftOCR by garnele007. There is a NSImage (That is also converted into a .png for saving)in the Swift project that I would like to add a shadow on top of. Several examples of adding a shadow inside the viewcontroller etc exist but so far an example of how to use something like Core Graphics/Image to add a shadow has eluded me. My imagination gives me something like
randomImg.CGAddShadow(shadow: true, weight: medium)
A few of the instructions floating around use UIKit which won't work for this MacOS project. Others add a temporary layer for the benefit of the user but don't save the file with the shadow still applied.
The code currently looks like this:
let customImage: (String) -> OCRImage = { code in
let randomImg = randomImage()
randomImg.lockFocus()
randomImg.draw(in: CGRect(origin: CGPoint.zero, size: randomImg.size))
NSString(string: code).draw(in: CGRect(origin: CGPoint(x: 0, y: -15.5 ), size: randomImg.size), withAttributes: randomFontAttributes())
randomImg.unlockFocus()
let data = NSBitmapImageRep(data: randomImg.tiffRepresentation!)?.representation(using: .png, properties: [:])
return randomImg
}
The end result is hopefully a modified file with a shadow over it that can be saved and viewed later.
Thanks for any suggestions