Page 1 of 1

How to resize an image?

Posted: Wed Apr 21, 2010 3:41 pm
by MasterchiefJB
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

Re: How to resize an image?

Posted: Wed Apr 21, 2010 4:17 pm
by Klaus
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

Re: How to resize an image?

Posted: Thu Apr 22, 2010 9:30 am
by Mark
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