Scaling images on the fly?

docmann docmann at gmail.com
Mon Jan 3 06:57:30 EST 2005


Jeanne,
Due to some other commitments, it may be a day or so before I can work
it into my existing code, but I'll definitely give it a go.
Thank you very much!
-Doc-

On Sun, 2 Jan 2005 17:19:19 -0800, Jeanne A. E. DeVoto
<revolution at jaedworks.com> wrote:
> At 5:09 PM -0600 1/2/05, docmann wrote:
> >Is there a way to constrain or scale the display image while
> >maintaining the proper size perspective of the original image, to
> >avoid distortion?
> 
> Here's a quick way, assuming you want the image to be 100 pixels x
> 100 pixels or so:
> 
>    create image "Holder" -- optional - if the image object doesn't exist yet
>    set the filename of image "Holder" to myURL
>    -- (myURL contains the URL of the image you want to show)
>    -- get the ratio of the natural width/height of the image:
>    put the width of image "Holder"/the height of image "Holder" into
> naturalRatio
>    -- scale the image to respect its aspect ratio:
>    if naturalRatio = 1 then -- square image
>      set the rect of image "Holder" to (0,0,100,100)
>    else if naturalRatio < 1 then -- image height is proportionally greater
>      set the width of image "Holder" to 100
>      set the height of image "Holder" to trunc(the width of image
> "Holder"/naturalRatio)
>    else -- naturalRatio > 1, image width is proportionally greater
>      set the height of image "Holder" to 100
>      set the width of image "Holder" to trunc(the height of image
> "Holder" * naturalRatio)
>    end if
>    set the lockLoc of image "Holder" to true -- maintain current size
>    set the loc of image "Holder" to 100,100 -- or wherever you want to put it
> 
> The above sets the smaller dimension of the image to 100 pixels. You
> can vary this to set the larger dimension to 100 pixels by setting
> the height to 100 first if naturalRatio < 1, and the width if
> naturalRatio > 1.
> --
> jeanne a. e. devoto ~ revolution at jaedworks.com
> http://www.jaedworks.com
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>


More information about the use-livecode mailing list