Resizing an image with min and max limits
J. Landman Gay
jacque at hyperactivesw.com
Sat Mar 5 14:36:08 EST 2011
On 3/5/11 5:01 AM, eps11 at mac.com wrote:
> Thanks for your answer. I have been trying to add limits in this
> section, but the results are... strange.
>
> I am trying to put a max limit on the width of image "Small" (which
> is 320x480) by entering :
>
> if the width of image "Small"< 480 then set the width of image
> "Small" to round(sFRAMEWIDTH * (tPercentage / 100)) if the width of
> image "Small">= 480 then
>
> After this latest "then", I have tried everything I know (but I am
> still a beginner)
>
> "set the width of image "Small" to 480" or "set the maxwidth of image
> "Small" to 480" works, but block the resizing at 480 "put 100 into
> tPercentage" blocks the resizing at 480 too
>
> At this stage, I think I would need to find a way to enter a fixed
> value for either the percentage or the maxwidth, then reset this
> value so that the resizing could continue, but there might be a
> better way to do all this.
>
> I am not sure about what to do next.
Here is a handler I use that scales an image to fit into a specified
rectanglular area, preserving proportions. You pass a long image
reference (like "the name of image 1" or "image 'Small'") and the rect
you want it to fit into. In your case it sounds like that may be the
screenrect. Images that are already smaller than the target rect are not
changed. Larger ones get scaled to fit. The location of the image is
preserved so it doesn't move around the screen.
on scaleToFit pImg,pRect -- pass an image reference & a target rect
put the formattedHeight of pImg into tFHt
put the formattedWidth of pImg into tFWd
put item 3 of pRect - item 1 of pRect into tTargetWd
put item 4 of pRect - item 2 of pRect into tTargetHt
set the rect of pImg to pRect -- to init;
put the loc of pImg into tLoc
set the width of pImg to tFWd
set the height of pImg to tFHt
if tTargetHt < tFHt or tTargetWd < tFWd then
put min(tTargetHt/tFHt, tTargetWd/tFWd) into theRatio
set the height of pImg to tFHt*theRatio
set the width of pImg to tFWd*theRatio
end if
set the loc of pImg to tLoc
end scaleToFit
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list