Page 1 of 1
image and project size settings from lua
Posted: Fri Jun 03, 2005 3:20 pm
by jorgy
Hello,
I've been through the scripting docs a couple of times but didn't seem to find this. I'm looking at a way to change the scale of an imported image layer based on the size of the image in the layer as well as the current size of the project. Are ways to get at both of these from lua?
Thanks,
jorgy
Posted: Fri Jun 03, 2005 3:26 pm
by Lost Marble
Image dimensions are not exposed through the Lua interface, but document dimensions are via the Width() and Height() functions of the MohoDoc class.
Posted: Tue Jun 07, 2005 10:02 am
by jorgy
Lost Marble wrote:Image dimensions are not exposed through the Lua interface, but document dimensions are via the Width() and Height() functions of the MohoDoc class.
I'd like to add image dimensions to the "wish list", so I can do some scaling of the image.
Thanks!
Posted: Wed Jun 08, 2005 5:38 pm
by 7feet
If you really need it now, and you don't mind programming it, if you do the import from within your script you can always pull the info out of the file from the binary info, the same way I have for my parsing of WAV files. As an example, for PNGs the width is an unsigned dword at file offset 12 (the 13th byte of the file), the height at 16. There are a bunch of functions for pulling out that specific sort of info in my function "library" that make it reasonably trivial to do (grab specific number of bytes from a specific file offset, convert them from bytes to Lua numbers, etc). PNG was the only file format that I checked, but they are all probably pretty similar in putting critical info like that at the front of the file in a specific spot. Shouldn't take long to set that up at all if you've got the mind.
Posted: Sat Jul 09, 2005 9:40 pm
by jorgy
Thanks LM, for putting this in version 5.2.
Posted: Tue Jul 19, 2005 2:46 pm
by jorgy
Okay, I've been trying to get the value, and I've been through just about every conceivable lua syntax, and I just can't seem to get it.
After creating my layer from an image, I want to see the size of it:
j_slideshow.lua:199: attempt to index field `ImageLayer' (a nil value)
Any help would be appreciated.
Thanks!
jorgy
Code: Select all
print ("layer width:" .. layer.ImageLayer::PixelWidth() )
print ("layer height:" .. layer.ImageLayer::PixelHeight() )
However, I can't seem to get the syntax right. The error that the above gives is:
Posted: Tue Jul 19, 2005 4:11 pm
by Lost Marble
Yeah, that's not going to work. If the "layer" object is a generic layer type (like the one passed into most script functions), it must first be cast to an ImageLayer, like so:
Code: Select all
local imgLayer = moho:LayerAsImage(moho.layer)
Now you can access the ImageLayer-specific functions:
Code: Select all
print("layer width:" .. imgLayer:PixelWidth())
Posted: Tue Jul 19, 2005 4:16 pm
by jorgy
Thanks!
I had tried that originally, but it returns heights and widths of -1.
Posted: Tue Jul 19, 2005 7:17 pm
by Lost Marble
Hmm, it works here for me. But it will only work if the image has been loaded. If the image is missing, or this script is called before the image has been loaded (which could be the case for an embedded script), then the width and height will come back as -1 : unknown.
The image gets loaded the first time the layer is drawn.
Posted: Thu Jul 21, 2005 12:06 pm
by jorgy
Bingo.
A well-placed MOHO.Redraw() has done the trick.
Thanks!!