display image question

J. Landman Gay jacque at hyperactivesw.com
Sat Sep 1 23:50:45 EDT 2012


On 9/1/12 4:56 PM, Timothy Miller wrote:

> --I'd like to have "grow and "shrink" scripts that will keep the
> center of the image area at some location and that will preserve the
> proportions of the original image. Maybe also a warning if I try to
> grow the display beyond the dimensions of the original
>
> Could someone post an off-the-shelf script that will do this please?

This is from my personal library. It assumes the image is imported into 
the stack. Pass it an image identifier and a target object:


on scaleToFit pImg,pObj -- the image object, the target object
   put the formattedheight of pImg into theFHt
   put the formattedwidth of pImg into theFWd
   put max(the height of pObj/theFHt, the width of pObj/theFWd) into 
theRatio
   set the height of pImg to theFHt*theRatio
   set the width of pImg to theFWd*theRatio
   set the loc of pImg to the loc of pObj
end scaleToFit

This calculates the largest dimension that will fit into the rect of the 
target object, scales the image to fit it, and places the image at the 
location of the target.

The target object is usually a rectangle graphic, a button, or a field. 
You could use an image object as the target but it won't be used except 
to calculate the size. I needed it to place an image inside a 
rectangular "frame".

You call it like this:

scaleToFit the long ID of img "photo",the long ID of grc "frame"

If you don't want to store the image in the stack, you could import it 
temporarily, run the handler, export the resulting image back to disk, 
and delete the temporary image from the stack. Then use the exported 
image as the reference for your image object. If you do that, then it 
does makes sense to use an image object as your target reference, since 
you'd be using it later to display the resized image from disk.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list