Compare images within Xcode calling Terminal
Posted: 2017-01-16T05:10:12-07:00
Hey there, I'm a complete newbie in this forum, moreover, a bit struggling to find out what am I doing wrong. Not sure if I'm banging a right tree, but let's get to the chase:
I'm trying to run the ImageMagic compare command from within Xcode using swift, however, even though I seem to be able to get the image difference values, it doesn't seem to be able to create a comparison image file. As you probably know, the syntax of the compare function should look something like this:
when I try to launch it in Xcode via Terminal, I use this sort of code:
Then, in Xcode's debug logs I get this:
where the "5.36454 (8.18576e-05)" is the actual compare difference result between image1.jpg and image2.jpg, but the resultimage.jpg file is not being created in the provided directory.
If I run compare command from within Terminal manually, everything works as expected. I've installed ImageMagick while using "brew" tool and it shows no errors whatsoever.
Perhaps someone could shed some light on what am I doing wrong? Thanks in advance!
I'm trying to run the ImageMagic compare command from within Xcode using swift, however, even though I seem to be able to get the image difference values, it doesn't seem to be able to create a comparison image file. As you probably know, the syntax of the compare function should look something like this:
Code: Select all
compare -metric MAE image1.jpg image2.jpg resultimage.jpg
Code: Select all
@discardableResult
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/usr/local/bin/compare"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
shell("-metric", "MAE", "/Users/CurrentUser/Desktop/TestExport/image1.jpg", "/Users/CurrentUser/Desktop/TestExport/image2.jpg", "/Users/CurrentUser/Desktop/TestExport/resultimage.jpg" )
Code: Select all
5.36454 (8.18576e-05)compare: unable to open image '/Users/CurrentUser/Desktop/TestExport/resultimage.jpg': Operation not permitted @ error/blob.c/OpenBlob/2691.
If I run compare command from within Terminal manually, everything works as expected. I've installed ImageMagick while using "brew" tool and it shows no errors whatsoever.
Code: Select all
Version: ImageMagick 7.0.4-4 Q16 x86_64 2017-01-15 http://www.imagemagick.org