Scaling an Image to a Rect

FlexibleLearning.com admin at FlexibleLearning.com
Wed Oct 16 00:12:08 EDT 2013


Depends if you mind 'losing the cropped data' or not.

An alternative to Richard's elegant snapshot solution, which would lose the
cropped data, is a fixed location group where the resized image's width or
height fits the group width or height. Any excess image is not lost, simply
not visible. Also means you can use your existing proportional width/height
scaling routines.

Hugh Senior
FLCo



From: Richard Gaskin <ambassador at fourthworld.com>
To: use-livecode at lists.runrev.com
Sent: Tue, 15 Oct 2013 16:00:43 -0700
Subject: Re: Scaling an Image to a Rect

You probably already know this, but in order to make the new Project
Browser the RunRev team added the ability to create thumbnails from the
import and export commands with the addition of "at" args:

    import snapshot [from rect[angle] rectangle] [of object]
      [(with | without) effects] [at size width, height]

You still need to calculate the desired width and height, but the time
saved by letting the engine do this on the image buffer internally
rather than resizing an image and re-setting its contents is pretty amazing.

--
  Richard Gaskin


From: Dan Friedman <dan at clearvisiontech.com>
To: use-livecode <use-livecode at lists.runrev.com>
Sent: Tue, Oct 15, 2013 4:11 pm
Subject: Scaling an Image to a Rect


Greetings!

I have been piddling around with this for weeks and still can't get it
right.  I
kinda got it working... but it's still not always 100% correct.  So, I
thought I
would ask this list for assistance since most of the people here are far
smarter
than I!

You have a rect and an image.  The goal is to completely fill the rect with
the
image.  But, we don't want to distort the image.  So, you need to
proportionally
scale the image up (if the image is smaller than the rect) or down (if the
image
is larger than the rect).   Remember that we want to completely fill rect.
It's
ok (and expected) that some of the image will be cropped.

Think of this as setting the background of a stack with an image.  You want
to
fill the entire background of the stack (regardless of the size of the
stack),
with the image (regardless of the rect of the image).  But we don't want to
distort the image.

Any thoughts?

-Dan





More information about the Use-livecode mailing list