Storing images
Jim Hurley
jhurley at infostations.com
Tue Feb 11 01:30:01 EST 2003
>
>Sannyasin Sivakatirswami wrote:
>
>Ha! Fantastic... what a great support group we have here! ;-)
>
>On Monday, February 10, 2003, at 07:46 AM, J. Landman Gay wrote:
>
>> Actually, it isn't even necessary to store the original image size in
>> a custom property. Rev will automatically save the size so that the
>> script doesn't have to track it. The formattedwidth and
>> formattedheight of the image retain the original dimensions. You can
>> use those properties to get the original size, and toss out a few
>> lines of extra scripting besides:
>>
>> set the width of image theImage to theRatio*the formattedWidth of img
>> theImage
>> set the height of image theImage to theRatio*the formattedHeight of
> > img theImage
>>
>
Sannysasin,
I think the best of both world is to blend Jacqueline's and Mark's
suggestions. Following Jacqueline's suggestion one avoids the need to
assign width and height properties to the images, andy busing the
formatted size properties you preserve the image proportions. And,
following Rick suggestion, you take the more natural approach and fit
the image to the button rather than the other way around.
That resizing script then which preserves the proportions of the
original image and packs it in a given button would looks like this:
on resizeImage theImage
--First get the button width
--The button width is first selected (using the button handles), and
--then the height is programmed to match the proportions of the image.
put the width of button theImage into theButtonWidth
--Reset the image size on the substack card
--so that it will fit inside the button without distortion.
set the defaultStack to "imagesSubstack"
put the formattedWidth of image theImage into tImageWidth
Put the formattedHeight of image theImage into tImageHeight
put tImageHeight/tImageWidth into ratioOfHeightToWidth -- The image ratio
set the width of image theImage to theButtonWidth*.94 -- Leave an edge
set the height of image theImage to theButtonWidth*ratioOfHeightToWidth*.94
--Finally adjust the button height to match the image height.
set the defaultstack to "images"
set the height of button theImage to theButtonWidth*ratioOfHeightToWidth
end resizeImage
Jim
--
Jim Hurley
More information about the use-livecode
mailing list