Resizing an image with min and max limits

Mark Schonewille m.schonewille at economy-x-talk.com
Sat Mar 5 06:42:51 EST 2011


Hi Eric,

You might find this function useful:

function rescale theImgWidth,theImgHeight,theCdWidth,theCdHeight
  if theCdWidth/theImgWidth < theCdHeight/theImgHeight then
    put theCdWidth / theImgWidth into myRatio
  else
    put theCdHeight / theImgHeight into myRatio
  end if
  put theImgWidth * myRatio into myNewWidth
  put theImgHeight * myRatio into myNewHeight
  return myNewWidth,myNewHeight
end rescale

TheImgWidth and theImgHeight are the original width and height, e.g. the formattedWidth and formattedHeight of an image object, and the CdWidth and theDcHeight are the width and height of the destination area. It returns the new height and width for your object, with correct aspect ratio.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

New: Download the Installer Maker Plugin 1.6 for LiveCode here http://qery.us/ce

On 5 mrt 2011, at 08:58, Eric Peyron wrote:

> Hi all, 
> 
> I have created an app with multi-touch resizing of images using the "How do I implement a multi-touch pinch motion?" lesson, but I can't seem to set limits to the resizing. What lines could I add to the code of the sample stack from this lesson to have a min size and and a max size for my image?
> 
> Thanks in advance, 
> Eric






More information about the use-livecode mailing list