Newbie Image Resizing Question...

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
paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Newbie Image Resizing Question...

Post by paulsr » Wed Aug 15, 2012 9:04 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Newbie Image Resizing Question...

Post by jmburnod » Wed Aug 15, 2012 9:26 am

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
https://alternatic.ch

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Newbie Image Resizing Question...

Post by paulsr » Wed Aug 15, 2012 9:52 am

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

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

Re: Newbie Image Resizing Question...

Post by Klaus » Wed Aug 15, 2012 11:55 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Newbie Image Resizing Question...

Post by jmburnod » Wed Aug 15, 2012 2:06 pm

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 :oops:

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
Attachments
stResizeImage.livecode.zip
(2.63 KiB) Downloaded 310 times
https://alternatic.ch

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Newbie Image Resizing Question...

Post by paulsr » Thu Aug 16, 2012 9:20 am

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Newbie Image Resizing Question...

Post by jmburnod » Thu Aug 16, 2012 9:58 am

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
https://alternatic.ch

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Contact:

Re: Newbie Image Resizing Question...

Post by paulsr » Thu Aug 16, 2012 10:09 am

Terima Kasih Jean-Marc,

Your solution would work fine.

--paul

Post Reply