Fit the image to the box script - help

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
eye
Posts: 1
Joined: 26 May 2010, 06:46

Fit the image to the box script - help

Post by eye » 14 Feb 2011, 10:31

You are the man!!
It now appear to work exactly as I wished.
Thank you so much for your patience and help.
Well, it took some time to finnish "my" first Quark script, but I've learned a lot. I guess this was not the easiest script to start with.
I'm going to give this a shortcut of ctrl+F or something.
I'd like to give something back to this forum. So for everyone that would like to set up their layout with empty picture boxes and do some quick and dirty image placements (remember to give the images a couple of nudges so you don't cut of someone's head). Here are the finished script.
(with noe warranties, but it works great in my quark 8/snow leopard)
---------------------------
tell application "QuarkXPress"
activate

tell document 1
try
-- This line will get the object of every selected picture box, and will error if no picture boxes are selected
set foundPictBoxes to object reference of every picture box whose selected is true
on error
error "No picture boxes are selected."
end try
repeat with i from 1 to length of foundPictBoxes
tell item i of foundPictBoxes
try
set bounds of image 1 to exact fit
copy (scale of image 1 as list) to {imageHeight, imageWidth}
copy {imageHeight as real, imageWidth as real} to {imageHeight, imageWidth}

--AUTO FIT THE IMAGE TO THE PICTURE BOX
if imageWidth > imageHeight then
set newPercent to imageWidth
else
set newPercent to imageHeight
end if
set scale of image 1 to {newPercent, newPercent}
set bounds of image 1 to centered
on error errmsg number errnum
error errmsg number errnum

end try
end tell
end repeat
end tell
end tell
---------------------------

Jean-Marie Schwartz
Posts: 1168
Joined: 23 Nov 2004, 04:30

Fit the image to the box script - help

Post by Jean-Marie Schwartz » 14 Feb 2011, 21:40

eye wrote:You are the man!!
Thanks! You're welcome. To be honest: I did learn A LOT from Michel (Scripting_Ace) both here and on his forum. I'm thankful to him! (And to some others on both forums too -Emma, JRS, kjeld, larsen67 and more-: many scripters took time to help me at the beginning and it's really great!)

dannykos
Posts: 13
Joined: 07 Nov 2008, 19:48

Fit the image to the box script - help

Post by dannykos » 18 Mar 2011, 13:40

I presume quark still doesn't have an 'Auto Fit Content Proportionally' command like ID does?Shame, as it's a really useful feature.

Jean-Marie Schwartz
Posts: 1168
Joined: 23 Nov 2004, 04:30

Fit the image to the box script - help

Post by Jean-Marie Schwartz » 20 Mar 2011, 22:13

Sure Quark has! Style > Stretch Picture to fit box
Or did you mean sth like Item Styles with Picture > Scale accross = Fit, Scale down > Fit?

eye
Posts: 1
Joined: 26 May 2010, 06:46

Fit the image to the box script - help

Post by eye » 20 Mar 2011, 22:56

Yes, in ID you can "fill frame proportionally". I was missing it in quark to - but not any more. Because this is exactly what this script does. This one also centers the picture inside the frame. And you can apply it to one or multiple selected image frames at ones.

You should really try it out. Inside the Quark-folder (in applications) there is a folder called "Scripts". This is where you put this script. You can name the script as you wish and you will find it on the script-menu in quark.

You can of course assign a shortcut for it in the system prefs > keyboard > shortcuts for applications (hop this is the correct path - cause I have another language in my OS X). I use ctrl-F for this.

dannykos
Posts: 13
Joined: 07 Nov 2008, 19:48

Fit the image to the box script - help

Post by dannykos » 29 Mar 2011, 21:36

I tried this script, but couldn't get it to work? I seemed to stretch one image to fit the box (dis-proportionately) and then didn't touch any other boxes?Not sure what I'm doing wrong. Maybe Quark 9 will have this function inherently built-in?

Jean-Marie Schwartz
Posts: 1168
Joined: 23 Nov 2004, 04:30

Fit the image to the box script - help

Post by Jean-Marie Schwartz » 29 Mar 2011, 22:50

Hi! What script are you refering to now? And what would you like the script to do? What are you expecting exactly? The script eye was asking for would fit the image disproportionally.

eye
Posts: 1
Joined: 26 May 2010, 06:46

Fit the image to the box script - help

Post by eye » 29 Mar 2011, 23:14

Did you use the final version posted on Mon, Feb 14 2011 11:31 PM?If not grab the latest version. If you did use the right one, maby som charecters got distorted by html or some characterset issueI'll try posting it again
------------------------------

tell application "QuarkXPress"
activate

tell document 1
try
-- This line will get the object of every selected picture box, and will error if no picture boxes are selected
set foundPictBoxes to object reference of every picture box whose selected is true
on error
error "No picture boxes are selected."
end try
repeat with i from 1 to length of foundPictBoxes
tell item i of foundPictBoxes
try
set bounds of image 1 to exact fit
copy (scale of image 1 as list) to {imageHeight, imageWidth}
copy {imageHeight as real, imageWidth as real} to {imageHeight, imageWidth}

--AUTO FIT THE IMAGE TO THE PICTURE BOX
if imageWidth > imageHeight then
set newPercent to imageWidth
else
set newPercent to imageHeight
end if
set scale of image 1 to {newPercent, newPercent}
set bounds of image 1 to centered
on error errmsg number errnum
error errmsg number errnum

end try
end tell
end repeat
end tell
end tell

dannykos
Posts: 13
Joined: 07 Nov 2008, 19:48

Fit the image to the box script - help

Post by dannykos » 30 Mar 2011, 05:10

@ eye - thanks for this, i'll give it another try when I get back from work.

herve butaye
Posts: 17
Joined: 19 Jun 2008, 16:54

Fit the image to the box script - help

Post by herve butaye » 31 Mar 2011, 03:20

Thank you for the script. That's exactly what I'm looking for. Will spare much time.

Post Reply

Return to “QuarkXPress 8, 9 & 10: AppleScript”