Shrinking an image to a button icon

J. Landman Gay jacque at hyperactivesw.com
Mon Dec 22 17:11:43 EST 2003


On 12/22/03 3:26 PM, Jim Carwardine wrote:

> I got that button icon to work, now I want to show the original picture in a
> floating palette that the user can move around.  I chose the palette format
> so they can navigate to different stacks and the picture will still float
> with them.  Is the palette a good strategy for that?

Yes.

> I'm still controlling the size of the picture, but I want to show a larger
> one as an option.  Here's the script.  I can't seem to get the stack window
> to exactly frame the picture.  Should I be changing the card rect?...
> 
> go stack "Picture"
>     put 300 into theTargetSize -- adjust size here
>     create image
>     set the filename of last img to the pictPath of me
>     put theTargetSize/the formattedwidth of last img into theRatio
>     set the width of last img to theTargetSize
>     set the height of last img to \
>         round(the formattedheight of last img * theRatio)
>     get the rect of last img
>     set the rect of stack "Picture" to it
>     palette stack "Picture"

Note that if you only want to show one image at a time, you don't need 
to create a new image object each time. Setting the filename of the 
existing image will change its picture. If the script creates new image 
objects with each iteration, it will just pile new ones on top of old 
ones. So skip the "create image" line unless you really do want to show 
multiple pictures at once. My original script assumed you wanted to 
create a number of different button icons to display on the same card, 
which would require multiple image objects, one for each button icon.

That said, you can't set the rect of a card so you do have to use the 
stack rectangle. But the rect of a stack is measured relative to the 
screen, not relative to the objects on the card. This means that if the 
top of the image on the card is at 10 pixels, the top of your stack 
would be under the menubar on a Mac. What you need to do instead is set 
the size of the stack in two separate steps:

  set the width of stack "picture" to <pixels>
  set the height of stack "picture" to <pixels>

where <pixels> is the measurement you want. You can use the same 
calculations in the above script to figure that out. In addition, you'll 
want to make sure the image itself is located correctly on the card. You 
can do this with:

  set the topleft of img "myImg" to 0,0

Or alternately, after you have resized the stack:

  set the loc of last img of stack "picture" to the loc of this cd of 
stack "picture"

Either way should work.


> 
> Jim
> 
> on 12/21/03 10:52 PM, J. Landman Gay wrote:
> 
> 
>>On 12/21/03 7:49 PM, Jim Carwardine wrote:
>>
>>
>>>Does anyone have scripting to take an image selected by the user, shrink it
>>>to a thumbnail and place it as an icon on a button?  When the button is
>>>clicked, I¹d like to show the picture snapshot size... Jim
>>
>>In the script of the display button:
>>
>>on mouseUp
>> answer file "Choose image:"
>> if it = "" then exit mouseup
>> put it into theImgPath
>> put 75 into theTargetSize -- adjust size here
>> create image
>> hide last img -- you may want to change this
>> set the filename of last img to theImgPath
>> put theTargetSize/the formattedwidth of last img into theRatio
>> set the width of last img to theTargetSize
>> set the height of last img to \
>>     round(the formattedheight of last img * theRatio)
>> set the icon of me to the short id of last img -- or set a different btn
>> choose browse tool
>>end mouseUp
> 
> 


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



More information about the use-livecode mailing list