making rectangular images square
making rectangular images square
- Subject: making rectangular images square
- From: Brian <email@hidden>
- Date: Sun, 24 Feb 2002 16:08:54 -0500
I need to write a script that will convert folders of either vertical or
horizontal images to squares. Below is my first pass at writing the script.
Environment is:
Mac OS 9.x
Applescript 1.4.3
Graphic converter 3.9.1
The script works pretty well, but still occasionally misses creating a
square output file. What I receive instead is a file whose dimensions
differ by exactly one pixel. I'm pretty sure the reason for this is my
blunt instrument approach of taking the width/height and dividing 2, setting
that value to a variable and padding by that value on both the left and
right or top and bottom to center the original image.
My attempts to evaluate whether the width height are an odd integer have not
been successful, however and any guidance would be greatly appreciated.
If, alternatively there's a better way to build this mousetrap I'd be
curious to explore those options as well.
thanks in advance for any help. cc: replies to email welcome as I'm on
digest mode.
brian
--begin script
tell application "Finder"
set this_folder to choose folder
set the_items to every file of this_folder
repeat with this_item in the_items
set the creator type of this_item to "GKON" -- so it opens with GC
tell application "GraphicConverter"
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
set theDiff to (theWidth - theHeight) / 2
change margins of window 1 with {0, theDiff, 0, theDiff}
end if
if theHeight > theWidth then
set theDiff to (theHeight - theWidth) / 2
change margins of window 1 with {theDiff, 0, theDiff, 0}
end if
-- trying to force image to square with this next bit unsuccessfully
set xy to image dimension of window 1
set thenewWidth to item 1 of xy
set thenewHeight to item 2 of xy
if thenewHeight thenewWidth then
set thenewHeight to thenewWidth
set image dimension of window 1 to {thenewWidth, thenewHeight}
end if
--end of my failed coercion to square
save window 1 as Photoshop
close window 1
end tell
set the creator type of this_item to "8BIM" -- so it opens with Photoshop
set oldname to the name of this_item
set newname to characters 1 thru -5 of oldname as text -- kill old extension
set the name of this_item to newname & ".psd"
end repeat
end tell
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.