Math: Check for proportional ratio

It sounds worse than it is, I’m sure.

My script in Quark places images with “exact fit.” Sometimes the image does not match
the box and so it is distorted. Some distortion is fine, but over 10% is unacceptable.

I need a script to tell me if the proportion of resize is greater than 10%.
(i.e. - X%:90 ; Y%: 100 = fine, do nothing
X%: 85 ; Y%: 100 = error, “filename, page #”

The script will need to continue past the error, I just need it to record the error
in a list. I can write the loop and list creation but math is not yet my strongpoint
and I could use some help with the ratio check.

if X% to Y% is greater than 10% then create list of filename and page number

OS9.2.2.
AS 1.6
Quark 4.11

Thank you for all suggestions.

Steven.

Easy-peasy. (Aren’t those famous last words)

You just have to get the scale of the image (the X and Y percents that show in the measurement palette), divide and if the answer is less than .9 or greater than 1.1, do your thing.

tell app "QuarkXPress"
   tell document 1
      copy (scale of image 1 of picture box 1 as list) to {scX, scY}
      set picRatio to (scX as number)/(scY as number)
      if (picRatio is less than .9) or (picRatio is greater than 1.1) then
         --do your stuff here
      end if
   end tell
end tell

This isn’t quite accurate, since 9/10ths isn’t the same distance from 1 as 10/9ths (.1 for the former and .111111111… for the latter), but it’s close enough. If you want to be more accurate, make sure the lesser number is the dividend.

It can’t be that simple!

Thank you for quick response. I’ll try this as soon as possible.

Can’t wait to see how it works.

Steven.

It didn’t quite work. I know there is a conversion or coercion necessary somewhere but I’m not sure where to place it.

I am getting text instead of numbers. The variable is a path. I get:

scale of image 1 of picture box 1 of picture box 1 of page 1 of document 1 of picture box 1 of page 1 of document 1 of application “QuarkXPress™ 4.11”

instead of 66% or 72%, etc.

Any ideas?

Thank you. I know the answer is near.

Steven

I got it!

I wrote it as a subroutine. There is probably an easier way but this one worked for me.

try
set scaleItem to scale of image 1
set scaleItem to coerce scaleItem to list
set verticalScale to item 1 of scaleItem as text
set scX to (characters 1 through -2) of verticalScale as string --this removes the “%”
set horizontalScale to item 2 of scaleItem as text
set scY to (characters 1 through -2) of horizontalScale as string

					end try
					my ratioCheck(scX, scY, theFile, thisPage)

→ RATIO CHECK SUBROUTING
on ratioCheck(scV, scH, theFile, thisPage)
try
set picRatio to (scV as number) / (scH as number)
if (picRatio is less than 0.9) or (picRatio is greater than 1.1) then
set proportionItem to (theFile & " pg. " & thisPage) as text
set proportionList to (proportionList & proportionItem & return)
end if
on error
set picRatio to “”
end try
end ratioCheck

If anyone would like to offer suggestions on how to streamline this I would love it.

Thank you all,

Steven

The coercion is in the math line, “scX as number” forces the percentage into a number. There is no need to parse the % out.

A little hint, look at the Apple Events pane while the script is running (if you have the latest script editor in osX) or put in “display dialog” to see what happens when you use coercions.

display dialog (scX as number)