Applying a color filter to images

Does anyone have experience of manipulating images within an XCode Applescript Application?
I can successfully display images within the ‘image view’ items of my project, but can I apply special effects to them?
In particular, what I want to do is to be able to apply a green filter to enhance the display of retinal images.
It is straightforward to do in Imagine Photo:


set FilterLevel to 10
set BrightLevel to 100
set GreenFilter to {class:RGB balance, red factor:FilterLevel, green factor:BrightLevel, blue factor:FilterLevel}
tell MyPic to create composition element with properties GreenFilter

However, it would be nice if I could do this within my XCode application, without having to load Imagine Photo separately.
Any ideas?
Thanks.

PJ,

If you don’t manage to find a non iMagine Photo solution. It is possible to hide iMagine Photo when it is running, and you can include it in the bundle of your AppleScript Studio application.

Firstly to not display any windows when writing scripts for iMagine Photo replace all intances of where you create the window document with a graphics document.

so you replace:

make new window document

with:

make new graphic document

Secondly you can make iMagine Photo a background only application. To do that use the following script:


tell application "iMagine Photo"
    set run in background to true
    quit
end tell

Every time you run iMagine Photo after this it will run only as a background application. Meaning you cannot get it to have a menubar or bring any of its windows to front. If you want to make iMagine Photo run normally again then you replace true with false in the above script and run it again.

Thirdly, to run iMagine Photo from your AppleScript Studio application, you need to place iMagine Photo in the Contents:Resources:Tools folder of your application package. Then in your script you need to wrap the tell block in the following way.


set imaginePhotoDir to ((path to me as string) & ("Contents:Resources:Tools:"))
using terms from application "iMagine Photo"
    tell application (imaginePhotoDir & "iMagine Photo.app")
        -- your iMagine Photo script goes here.
    end tell
end using terms from

Let me know if you have any problems.

Kevin

Kevin,
Thanks for the extensive suggestions as to how to manage iMagine Photo within XCode.
I had worked out how to ‘make new graphic document’ instead of ‘window document’, but the other techniques are new to me.
I shall give them a go, and see if I can get them to work.
PJ.

Kevin,

Just a quick update: everything worked pretty much as you suggested.
I had a little trouble with the ‘run in background’ command: I think I placed it too close to the point where iMagine was launched, resulting in an error.
Moving the background command to the ‘on awake’ handler resolved the problem.

Bundling the application into Resources:Tools: worked just fine with the ‘Using Terms’.
→ Now I have a fully standalone application :slight_smile:
Thanks for the help - would have taken me far too long to resolve on my own.
Now to find someone else’s system to try it on…

PJ.

PJ,

Thanks for getting back to me.

You only need to run the run in background command once. The command actually modifies iMagine Photo’s own plist file so once the application has been modified it can be copied to any machine and will always run in the background. So you shouldn’t need that part of the script in your AppleScript studio application. You could have just used Script Editor to run the run in background script, and then after that copy the iMagine Photo application to your AppleScript studio application tools folder.

Since I’m always keen to see how iMagine Photo is being used, if you would like to provide a link for me to download your application I can give it a quick whirl. I will not be your best tester though, because I nearly always have multiple copies of different versions of iMagine Photo on my disk and with AppleScript this can cause some odd behaviour. I do have both intel and powerpc to try it out on though.

Kevin

Kevin,
Sorry - I missed your reply, hence the delay in this posting. Would be happy to make a copy of the script accessible. The application package comes with approx 30 x 3MB tiff files, so is a little heavy for mail. Where and how should I post an application in order to make it freely available?
PJ.