How to resize an image?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MasterchiefJB
Posts: 76
Joined: Sat Nov 07, 2009 7:43 pm

How to resize an image?

Post by MasterchiefJB » Wed Apr 21, 2010 3:41 pm

Hi again,
this time I am confronted with the following issue:
I want to import an image (or more) , guess easy thing with the open/import file commands,
check the Resolution size of these images (f.e. 800*600) and resize the image to 68*68 if it exceeds these values.
I don´t have a clue how to archieve that and would be grateful if anyone could help me.

Cheers,
Masterchief

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to resize an image?

Post by Klaus » Wed Apr 21, 2010 4:17 pm

Hi cheif,

do this, and do this behind the screnes :-)

Code: Select all

...
lock screen
## behind the scenes, user will not see any of your magic

## import here your image or set the filename of an existing image...

## Now get the original dimension of this image:
put the formattedwidth of img "your image here" into tWide
put the formattedheight of img "your image here" into tHeigh

## Now check if these values fit
if tWide > 800 AND tHeigh > 600 then
  ## resize the image accordingly
end if
unlock screen
...
You get the picture :-)


Best

Klaus

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to resize an image?

Post by Mark » Thu Apr 22, 2010 9:30 am

Hello JB,

This function calculates the new widh and height of an object:

Code: Select all

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 
usage:
put rescale(the formattedWIdth of img 1,the formattedHeight of img 1,64,64) into myHW
--> myHW example values: 54,64 or 64,48 etc.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply