Page 1 of 1

image properties

Posted: Mon Sep 05, 2011 2:10 pm
by kevin11
Hi,

I'm struggling a bit with image sizes. I'd like a set of image containers, set out equally spaced, which will contain a bunch of images. However, the images are not all the same size, so what I would like is each image to be centred within the container. I don't know the size of each image (read in from external jpeg files), but the guts of LC must know, as it can resize images to match the container size so it must know the image starting size. The properties of any image container is in the rect but is the size of the container. I can't see a property that gives the size of the image data. I would like the container sizes to be all the same, but the images not resized to fit. Is there a way of doing this please ?

Kevin

Re: image properties

Posted: Mon Sep 05, 2011 2:56 pm
by Klaus
Hi Kevin,

in the IDE you can press the SHIFT key to resize images proportionally.


You can setup your (empty) images as you described and the via script you can query "the formattedheight of img XYZ"
(and of yourse "the formattedwidth...") which you can use to do the calculations of the new desired size while preserving
the aspect ration, see below...

Some useful hints:
1. to prevent the images from resizing ceck their LOCKLOC!
2. To keep the original position after resizing (which will affect the location, too!)
I usually have this littel function in my stackscript

Code: Select all

...
LOCK SCREEN ##!!!
put the loc of img XYZ into oldloc

put the formattedwidth of img XYZ into OriginalW
put the formattedheight of img XYZ into OriginalH

## Set your image container dimensions here
put 120 into tTargetW
put 120 into tTargetH
## do resizing stuff NOW :-)
put make_ratio(tTargetW,tTargetH,OriginalW,OriginalH) into tNewDimensions
set the width of img XYZ to item 1 of tNewDimensions
set the height of img XYZ to item 2 of tNewDimensions
set the loc img XYZ to oldloc
## DONE, curtain up:
unlock screen
## Or put this into a repeat loop to "fill" all your images in a loop...
...

## Calculates new image dimensions within max height/width while preserving aspect ratio
function make_ratio tW, tH, w, h
  if (w<=tW and h<=tH) = false then
    put min (tW/w,tH/h) into tscaleFactor
    return round(w * tscaleFactor) & "," & round(h * tscaleFactor)
  else

    ## Images that are smaller than the TARGET size are NOT scaled in this function, 
    ## it will return the oroginal dimensions in that case!
    return w & "," & h
  end if
end make_ratio
Best

Klaus

Re: image properties

Posted: Mon Sep 05, 2011 7:34 pm
by kevin11
Hi Klaus,

I'm confused now. I don't want to resize anything. I don't see how your code achieves that ?

Regards

Kevin

Re: image properties

Posted: Mon Sep 05, 2011 7:37 pm
by Luisa Klose
Kevin, like in a thumbnail viewer, where each image fits in the "cell"?

Luisa

Re: image properties

Posted: Mon Sep 05, 2011 7:47 pm
by kevin11
Hi Luisa,

YES !!! Exactly like that. Like in html/css. Where you just centre the image, and you don't have to know the size of the incoming image. I assumed it would be a property of the image container, and was expecting things like padding, centreing, etc. This image container is a bit naff, to be honest.

Kevin

Re: image properties

Posted: Mon Sep 05, 2011 7:53 pm
by Klaus
Hi kevin,
kevin11 wrote:Where you just centre the image, and you don't have to know the size of the incoming image.
put the script into the handler that imports/sets the filename of your image(s)!
This way you CAN set up and center an image without having to know the size of the incoming image(s). :)

Get the picture?


Best

Klaus

Re: image properties

Posted: Mon Sep 05, 2011 8:21 pm
by kevin11
Klaus wrote: put the script into the handler that imports/sets the filename of your image(s)!
This way you CAN set up and center an image without having to know the size of the incoming image(s). :)

Get the picture?
Thank Klaus. I tried it, and it didn't give me what I wanted. The contents were at the correct size, but the container changes size to match the contents, so I end up with correct images(pixels) and incorrect container sizes.

Re: image properties

Posted: Mon Sep 05, 2011 9:33 pm
by Klaus
Hi kevin,

yep, the container = the content!

But you can surely fake what you want by adding an opaque graphic behind the actual images, no?
Please don't give up so early :D


Best

Klaus

Re: image properties

Posted: Tue Sep 06, 2011 8:51 am
by kevin11
Klaus wrote:But you can surely fake what you want by adding an opaque graphic behind the actual images, no?
Please don't give up so early :D
Hi Klaus,

Not giving up ! You are right, I can put fake cells in the background and set their attributes, and hide the foreground containers but not their contents. I knew from looking at your code it wouldn't solve the problem, but didn't realise it would solve 95% of the problem !

Thanks

Kevin