dump newbie image questiosn

Jon jbondy at sover.net
Tue Jun 7 08:09:09 EDT 2005


You remain, in my humble eyes, one of the most prolific and articulate 
contributors to this list.

:)

Jon


J. Landman Gay wrote:

> On 6/6/05 2:37 PM, Jon wrote:
> >
> > J. Landman Gay wrote:
> >
> > <snip>
> >
> >> No, I wasn't joking. I'm not even sure I understand the problem
> >> because I've never seen it. I always scale images by calculating the
> >> desired dimensions and setting the image to that size. For example, if
> >> I want an image to display at 1/3 its natural size, I do this:
> >>
> >> set the width of img 1 to round((the formattedwidth of img 1) * .3)
> >> set the height of img 1 to round((the formattedheight of img 1) * .3)
> >>
> >
> > This is great if you know in advance that there is enough room to
> > display the image in this way, at this particular scale.  What I wanted
> > was something that automatically displayed the image at the largest
> > resolution possible in "the available space".  That's where the
> > confusion comes in: I need to store the "available space" somewhere in
> > the Image object if I am to perform the computations properly.  
> Maybe it
> > is just that simple, at least for me.
>
> I don't usually store "available space", I just recalculate it on the 
> fly. There is almost always a point of reference available to do that.
>
> For example, you mentioned you have a stack with some buttons at the 
> top and the entire lower section available for an image. Or at least, 
> I will assume that for this example. In that case, your reference 
> points are:
>
> the available width is equal to the width of the card
> the available height is equal to the height of the card minus the 
> bottom of your row of buttons, and probably minus a small amount for a 
> margin between the button row and the top of the image.
>
> So your script can do this:
>
> put the width of this cd into tW
> put the height of this cd - the bottom of btn "aTopRowButton" \
>   - 20 into tH
>
> You may want to subtract a bit more from the height calculation so 
> that you have more space between the button row and the top of the 
> image you are about to put in there. I have left a 20-pixel margin. 
> You may also not want the image butted up against the sides of the 
> card, so you could subtract some more from the width to account for a 
> margin there too if you want. Now you have the available space for an 
> image. Then you add the image to the card while the screen is locked 
> so that the resizing won't be noticed. Like this:
>
> lock screen
> set the filename of img 1 to <path to image>
>
> Or you could use "put url <whatever> into img 1" if you want the image 
> to be stored directly in the stack itself. The above method uses a 
> referenced image, pulled from disk on the fly. Referenced images keep 
> your stack size smaller on disk, but you run a higher risk the files 
> will become separated from the place the script expects to find them. 
> You can decide which way you want to use.
>
> Now get the formatted dimensions, and use them to calculate the ratio 
> of the resizing that is required, depending on whether the width or 
> the height fits best:
>
> put the formattedheight of img 1 into tFHt
> put the formattedwidth of img 1 into tFWd
> put max(tH/tFHt, tW/tFWd) into tRatio
> set the height of img 1 to tFHt*tRatio
> set the width of img 1 to tFWd*tRatio
>
> And that's it. If you need to, set the final location of the image, 
> because resizing it may have moved it slightly:
>
> set the loc of img 1 to <whatever> -- or you could set the "topleft"
>
> Here it is all together (watch for line wrap):
>
> *****
>
> put the width of this cd into tW
> put the height of this cd - the bottom of btn "aTopRowButton" \
>    - 20 into tH
> lock screen
> set the filename of img 1 to <path to image>)
> put the formattedheight of img 1 into tFHt
> put the formattedwidth of img 1 into tFWd
> put max(tH/tFHt, tW/tFWd) into tRatio
> set the height of img 1 to tFHt*tRatio
> set the width of img 1 to tFWd*tRatio
> set the topleft of img 1 to (0,the bottom of btn "aTopRowButton" + 20)
> unlock screen
>
> *****
>
> I think that does what you want. No need to alter the lockloc of the 
> image (which should remain true.) Works cross-platform. ;)
>
> Yes?
>


More information about the use-livecode mailing list