Compare images within Xcode calling Terminal

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Motiejus
Posts: 2
Joined: 2017-01-16T04:56:29-07:00
Authentication code: 1151

Compare images within Xcode calling Terminal

Post by Motiejus »

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:

Code: Select all

compare -metric MAE image1.jpg image2.jpg resultimage.jpg
when I try to launch it in Xcode via Terminal, I use this sort of code:

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" )
Then, in Xcode's debug logs I get this:

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.
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.

Code: Select all

Version: ImageMagick 7.0.4-4 Q16 x86_64 2017-01-15 http://www.imagemagick.org
Perhaps someone could shed some light on what am I doing wrong? Thanks in advance!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare images within Xcode calling Terminal

Post by snibgo »

I know nothing about "Xcode via Terminal", but does it have permission to create new files in that directory? You might try a simple "cp" command or similar.

PS What version of IM?
snibgo's IM pages: im.snibgo.com
Motiejus
Posts: 2
Joined: 2017-01-16T04:56:29-07:00
Authentication code: 1151

Re: Compare images within Xcode calling Terminal

Post by Motiejus »

snibgo wrote: 2017-01-16T05:29:54-07:00 I know nothing about "Xcode via Terminal", but does it have permission to create new files in that directory? You might try a simple "cp" command or similar.

PS What version of IM?
I've changed the permissions of the folder I'm trying to export to to "chmod 777" which by idea should allow everyone and everything to create a file there, although I might have still missed something within Xcode. Good idea, will try to check it deeper.

IM version is provided in initial post, it's "7.0.4-4 Q16 x86_64 2017-01-15"
Post Reply