Shrinking an image to a button icon

J. Landman Gay jacque at hyperactivesw.com
Tue Dec 23 01:49:36 EST 2003


On 12/22/03 6:50 PM, Jim Carwardine wrote:

> Now I'm getting unpredictable results and I'm not sure why.  Sometimes my
> picture is 40 pixels too wide in all 4 dimensions, sometimes my picture is
> offset to the top left by 40 pixels and sometimes it's right on.  I'm
> getting an error (can't set that property) on the line "set the rect of card
> 1 of stack "Picture" to it".  Jim
> 
> Here's my script...
> 
> if it is "Enlarge" then
>     lock screen
>     go stack "Picture"
>     put 300 into theTargetSize -- adjust size here
>     set the filename of img "Palette Picture Graphic" to the pictPath of me
>     put theTargetSize/the formattedwidth of img "Palette Picture Graphic"
> into theRatio
>     set the width of img "Palette Picture Graphic" to theTargetSize
>     set the height of img "Palette Picture Graphic" to \
>         round(the formattedheight of img "Palette Picture Graphic" *
> theRatio)
>         set the topleft of img "Palette Picture Graphic" to 0,0
>     get the rect of img "Palette Picture Graphic" of card 1 of stack
> "Picture"
>     set the rect of card 1 of stack "Picture" to it
>     set the topleft of stack "Picture" to 380,310
>     palette stack "Picture"
>   end if


Almost there. You can't set the rect of a card. You have to set its 
width and its height separately. Instead of the line "set the rect of 
card 1..." you need to script as follows (watch for line wrap):

   lock screen
   go stack "Picture"
   put 300 into theTargetSize -- adjust size here
   set the filename of img "Palette Picture Graphic" to the pictPath of me
   put theTargetSize/the formattedwidth of img "Palette Picture Graphic" 
into theRatio
   set the width of img "Palette Picture Graphic" to theTargetSize
   set the height of img "Palette Picture Graphic" to \
       round(the formattedheight of img "Palette Picture Graphic" * 
theRatio)
   -- changes to script start here:
   set the width of cd 1 to the width of img "Palette Picture Graphic"
   set the height of cd 1 to the height of img "Palette Picture Graphic"
   set the topleft of img "Palette Picture Graphic" to 0,0
   set the topleft of stack "Picture" to 380,310
   palette stack "Picture"


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



More information about the use-livecode mailing list