scripting Graphic converter
scripting Graphic converter
I've written a script hat takes horizontal and vertical photos and makes
them squares -- excerpt below. In doing so I've hit some questions I can't
answer for myself. Any help greatly appreciated.
Q1 - how do I set the background color swatch to white to ensure that when I
add margins the added area is filled with white. It seems to reset to white
on it's own every time GC opens, but I'd like to trap for any potential
errors.
Q2 - I've noticed when I make squares (see method below) sometimes the
resulting image can end up being 1 pixel wider than it is tall or vice
versa. I'd speculate that is happening because as I subtract width from
height I end up with an odd number which is divided by 2 resulting in a
remainder. To trap this I thought I might test if the value for height or
width is odd and then add 1. Looking back at this excerpt now, I'm still
not sure it'll do exactly what I want, but you see my question nonetheless.
Right now I'm making the coercion to square as noted in sample below and
then subsequently testing if theWidth=theHeight. If not, then I force
theWidth=theHeight, trusting that this 1 pixel distortion is negligible.
Shhh. don't tell anybody.
Any tips would be welcome.
thanks in advance -
brian
_________________
sample code follows:
tell application "GraphicConverter"
--activate --- do I need this?
open this_item
set xy to image dimension of window 1
set theWidth to item 1 of xy
set theHeight to item 2 of xy
if theWidth > theHeight then
(* this doesn't work - "odd" is treated as a variable.
if theWidth is odd then
et theWidth to theWidth + 1
end if
if theHeight is odd then
set theHeight to theHeight + 1
end if
*)
--how do I ensure the background color is white before I add margins??
set theDiff to (theWidth - theHeight) / 2
change margins of window 1 with {0, theDiff, 0, theDiff}
end if
end tell