Page 1 of 1
Newbie Image Resizing Question...
Posted: Wed Aug 15, 2012 9:04 am
by paulsr
I'm struggling to understand the numerous things I can do with images.
If I create an Image Area on a card that is, say, 200x100px, and I place an image in there, using "set the filename of img" (to some url) the remote image gets resized to 200x100 before it is displayed.
That's fine if the image was 400x200, or some exact multiple, but not if it was 600x200, coz then it gets squished.
Could someone please explain, or point me to a tutorial that explains, how I can resize the image to a max width of 200 and a max height of 100px before it's displayed.
Many tkx...
--paul
Re: Newbie Image Resizing Question...
Posted: Wed Aug 15, 2012 9:26 am
by jmburnod
Hi Paul,
This function return the max width and height proportional
Code: Select all
function PourCrop pWidthSource,pHeightSource,pWidthDest,pHeightDest,pMarge
if pWidthSource ≤ pWidthDest-pMarge and pHeightSource ≤ pHeightDest-pMarge then
put pWidthSource into LaWdef
put pHeightSource into LaHdef
else
if pWidthSource = pHeightSource then -- that is a square
put pWidthDest-pMarge into LaWdef
put pHeightDest-pMarge into LaHdef
return LaWdef,LaHdef
exit PourCrop
end if
subtract pMarge from pWidthDest
subtract pMarge from pHeightDest
put (pWidthDest/pWidthSource) into LeDivW
put (pHeightDest/pHeightSource) into LeDivH
put min(LeDivW,LeDivH) into LeDiv
put trunc(pWidthSource*LeDiv) into LaWdef
put trunc(pHeightSource*LeDiv) into LaHdef
end if
return LaWdef,LaHdef
end PourCrop
Best regards
Jean-Marc
Re: Newbie Image Resizing Question...
Posted: Wed Aug 15, 2012 9:52 am
by paulsr
Merci Jean-Marc...
But, maybe I'm not understanding something, it looks like the image has been resized before it is displayed on the card.
Using my example: if my image area is 200x100 and the remote image is 600x200, what is see in my image area is 200x100. If I inspect its size, it is 200x100. So I can no longer resize it in the way I want.
I must be missing something?
--paul
Re: Newbie Image Resizing Question...
Posted: Wed Aug 15, 2012 11:55 am
by Klaus
Hi Paul
paulsr wrote:...
Using my example: if my image area is 200x100 and the remote image is 600x200, what is see in my image area is 200x100. If I inspect its size, it is 200x100. So I can no longer resize it in the way I want.
I must be missing something?--paul
This sound as if your image is "locLock"ed!
In the Inspector of your image: Size & Position: "lockloc" (Lock size and position)
Here is what you need to do:
1. Set the filename of your image (load the image into the image object)
2. get "the formattedwidth" and "formattedheight" of the image (= original dimensions in Pixels)
3. apply the "rule of three" to get the new width and height so it fits into the 200*100 image area WITHOUT getting distorted
4. set the new computed width and height of the image
Please work through these stacks if not done already:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: Newbie Image Resizing Question...
Posted: Wed Aug 15, 2012 2:06 pm
by jmburnod
Hi Paul,
The stack in attachment play with some ways to resize an image
I hope this help
I changed the PourCrop function its did'nt work with squares
Code: Select all
function PourCrop pWidthSource,pHeightSource,pWidthDest,pHeightDest,pMarge
if pWidthSource ≤ pWidthDest-pMarge and pHeightSource ≤ pHeightDest-pMarge then
put pWidthSource into LaWdef
put pHeightSource into LaHdef
else
if pWidthSource = pHeightSource then -- that is a square
put min(pWidthDest,pHeightDest) into t
put t-pMarge into LaWdef
put t-pMarge into LaHdef
return LaWdef,LaHdef
exit PourCrop
end if
subtract pMarge from pWidthDest
subtract pMarge from pHeightDest
put (pWidthDest/pWidthSource) into LeDivW
put (pHeightDest/pHeightSource) into LeDivH
put max(LeDivW,LeDivH) into LeDiv
put trunc(pWidthSource*LeDiv) into LaWdef
put trunc(pHeightSource*LeDiv) into LaHdef
end if
return LaWdef,LaHdef
end PourCrop
Best regards
Jean-Marc
Re: Newbie Image Resizing Question...
Posted: Thu Aug 16, 2012 9:20 am
by paulsr
Thanks Guys, I've got the hang of this now.
But a related question, if I may...
I want my image to be resized and to fit in an area 200x100. Let's say the resized image is 200x50.
Is there a (hopefully easy!) way to expand the image to 200x100 by inserting white space top & bottom?
I'm not asking for an instant solution... Just point me to the right commands and I'll try to figure it for myself.
Thanks...
--paul
Re: Newbie Image Resizing Question...
Posted: Thu Aug 16, 2012 9:58 am
by jmburnod
Selamat Datang Paul,
But a related question, if I may...
This forum is made for that
Why not a white graphic like frame 200X100 and setting the loc of the image to the loc of the graphic ?
Best regards
Jean-Marc
Re: Newbie Image Resizing Question...
Posted: Thu Aug 16, 2012 10:09 am
by paulsr
Terima Kasih Jean-Marc,
Your solution would work fine.
--paul