Scaling an Image
Jeanne A. E. DeVoto
jeanne at runrev.com
Mon Dec 2 02:13:04 EST 2002
At 6:06 PM -0800 12/1/02, JamesHBeckmann at aol.com wrote:
> Jeanne A. E. DeVoto helped me by providing the following:
>
> >> answer file empty
> >> put it into thisPict
> >> set the rect of templateimage to the rect of fld pictFld
> >> set the filename of templateimage to thisPict
> >> set the lockLoc of templateimage to true
> >> create image "Holder"
> >> wait 3 secs
> >> hide image "Holder"
> >> send "choose browse tool" to me in 1 tick
>
>Thanks. However on my version of Rev 1.1 this script places the image in the
>fld rect, not scaled but forced to fit the rect ignoring the x/y ratio. It
>also does not "hide the image" as requested. Am I missing something?
This same handler hides the image for me, after the three-second wait, in
Rev 1.1.1r2. (Is your stack doing anything else that might be interfering
with the hide? Do you perhaps have "showInvisibles" set to true?)
The above code just sets the image mechanically to the field's rect,
without attempting to preserve its height/width ratio. To do that, you need
to do a bit more work. This ought to do it:
answer file "Which image do you want to use?"
put it into myImage
create image "Holder"
set the filename of image "Holder" to myImage
-- get the ratio of the natural width/height of the image
put the width of image "Holder"/the height of image "Holder" into imageRatio
put the width of field "My Field"/the height of field "My Field" into
fieldRatio
-- scale the image to respect its aspect ratio
if imageRatio = fieldRatio then -- proportions match
set the rect of image "Holder" to the rect of field "My Field"
set the lockLoc of image "Holder" to true
else if imageRatio > fieldRatio then -- image height is proportionally
greater
set the width of image "Holder" to the width of field "My Field"
set the height of image "Holder" to trunc(the width of image
"Holder"/imageRatio)
else -- imageRatio < fieldRatio, image width is proportionally greater
set the height of image "Holder" to the height of field "My Field"
set the width of image "Holder" to trunc(the height of image "Holder" *
imageRatio)
end if
set the lockLoc of image "Holder" to true -- maintain current size
set the loc of image "Holder" to the loc of field "My Field"
show image "Holder"
wait for 3 seconds
hide image "Holder"
send "choose browse tool" to me in 1 tick
--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
Runtime Revolution Limited - The Solution for Software Development
http://www.runrev.com/
More information about the use-livecode
mailing list