image and project size settings from lua
Moderators: Víctor Paredes, Belgarath, slowtiger
image and project size settings from lua
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
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
- Lost Marble
- Site Admin
- Posts: 2356
- Joined: Tue Aug 03, 2004 6:02 pm
- Location: Scotts Valley, California, USA
- Contact:
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.
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
However, I can't seem to get the syntax right. The error that the above gives is:
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() )
- Lost Marble
- Site Admin
- Posts: 2356
- Joined: Tue Aug 03, 2004 6:02 pm
- Location: Scotts Valley, California, USA
- Contact:
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:
Now you can access the ImageLayer-specific functions:
Code: Select all
local imgLayer = moho:LayerAsImage(moho.layer)
Code: Select all
print("layer width:" .. imgLayer:PixelWidth())
- Lost Marble
- Site Admin
- Posts: 2356
- Joined: Tue Aug 03, 2004 6:02 pm
- Location: Scotts Valley, California, USA
- Contact:
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.
The image gets loaded the first time the layer is drawn.