Is there a way to set the Canvas Size using AppleScript?
I have written a script that adds a watermark image to a photo. The watermark is 237px by 280px. If the photo is shorter or narrower than the watermark image, I'd like to change the canvas size of the photo - adding white space to the background - before the watermark is inserted. How can this be done in AppleScript?
I don't want to scale the image. I only want to make the photo's canvas size larger.
Thanks,
Frank
GC 10.1.0
OSX 10.11.6
Setting Canvas Size via AppleScript
-
- Posts: 9
- Joined: Mon Dec 31, 2018 6:54 pm
- Country: Canada
- forum_adm
- Site Admin
- Posts: 1818
- Joined: Fri Dec 23, 2016 9:41 am
- Location: Germany
- Country: Germany
- Contact:
Re: Setting Canvas Size via AppleScript
Hi Frank,
you can use:
change margins v : changes the margins of the object
change margins window
with list of integer : delta values (left, top, right, bottom), positive values add a margin, negative values remove the margins
I suggest to create a batch and call this via the command line. That is much faster.
Thorsten
you can use:
change margins v : changes the margins of the object
change margins window
with list of integer : delta values (left, top, right, bottom), positive values add a margin, negative values remove the margins
I suggest to create a batch and call this via the command line. That is much faster.
Thorsten
-
- Posts: 9
- Joined: Mon Dec 31, 2018 6:54 pm
- Country: Canada
Re: Setting Canvas Size via AppleScript
Hi Thorsten,
Thanks for the reply. I didn't get an email saying you had replied, so I ended up using Image Events. However, I'd prefer to do everything in GC.
After some trial and error, I got change margins to work. Here's the code I came up with:
This does resize the canvas, but I wasn't able to get "background color" to work. What's the proper syntax for that?
Frank
Thanks for the reply. I didn't get an email saying you had replied, so I ended up using Image Events. However, I'd prefer to do everything in GC.
After some trial and error, I got change margins to work. Here's the code I came up with:
Code: Select all
set the_image to ":Applications:MAMP:htdocs:original_images:xxxx4.jpg"
tell application "GraphicConverter 10"
activate
open the_image
tell front window
copy image dimension to {orig_pic_width, orig_pic_height}
set {left_margin, right_margin, top_margin, bottom_margin} to {0, 0, 0, 0}
if orig_pic_width < 300 then
set the_difference to 300 - orig_pic_width
set {left_margin, right_margin} to {the_difference / 2, the_difference / 2}
end if
if orig_pic_height < 300 then
set the_difference to 300 - orig_pic_height
set {top_margin, bottom_margin} to {the_difference / 2, the_difference / 2}
end if
change margins with {left_margin, top_margin, right_margin, bottom_margin}
end tell -- front window
end tell
Frank
- forum_adm
- Site Admin
- Posts: 1818
- Joined: Fri Dec 23, 2016 9:41 am
- Location: Germany
- Country: Germany
- Contact:
Re: Setting Canvas Size via AppleScript
That is on old RGB format: set to {0xFFFF,0xFFFF,0xFFFF} for white.
That is on old RGB format: set to {0,0,0} for black.
That is on old RGB format: set to {0,0,0} for black.
-
- Posts: 9
- Joined: Mon Dec 31, 2018 6:54 pm
- Country: Canada
Re: Setting Canvas Size via AppleScript
I'm getting compile errors in Script Debugger. When trying things like:
I get:
Code: Select all
change margins with {left_margin, top_margin, right_margin, bottom_margin} set background color to {0,0,0}
Code: Select all
change margins with {left_margin, top_margin, right_margin, bottom_margin} set to {0,0,0}
Expected end of line, etc. but found "set".
- forum_adm
- Site Admin
- Posts: 1818
- Joined: Fri Dec 23, 2016 9:41 am
- Location: Germany
- Country: Germany
- Contact:
Re: Setting Canvas Size via AppleScript
The background color is a window property. Just set it before the change margin comand:
-
- Posts: 9
- Joined: Mon Dec 31, 2018 6:54 pm
- Country: Canada
Re: Setting Canvas Size via AppleScript
OK, that works. Thanks. Unless I'm reading it incorrectly, the dictionary makes it look like it's part of the Change Margins syntax.The background color is a window property. Just set it before the change margin comand:
Now I just have to figure out the color numbering scheme. I thought RGB used values from 0 to 255, however these go up to 65535.
BTW, the hex colors "{0xFFFF,0xFFFF,0xFFFF}" that were mentioned before don't work for me. Script Debugger won't compile the script.
Thanks again for your help,
Frank
- forum_adm
- Site Admin
- Posts: 1818
- Joined: Fri Dec 23, 2016 9:41 am
- Location: Germany
- Country: Germany
- Contact:
Re: Setting Canvas Size via AppleScript
The AppleScript syntax is from MacOS 9.
So, the RGB color has 16 bit component.
So, the range is from 0 to 65535.
Thorsten
So, the RGB color has 16 bit component.
So, the range is from 0 to 65535.
Thorsten