On Wed, Jun 19, 2013 at 11:29 AM, David Vincent-Jones
<davi...@frontier.com> wrote:
>   OK Jeremy, thanks .... I did see the posted example but, as a newcomer
> to Lua, I found it a more than a tad difficult to follow ... and I had
> hoped that an  example relating to print output might also be available.

In a nutshell, the script is building a linux shell command, and executing
it.  It's the same concept you'd need for printing -- you'd just need a
different command line.

  1    dt = require "darktable"

Pulls in the darktable module (or whatever it's called in Lua --
I've never used it before, either).

  2    dt.register_storage("module_stitcher","mosaic generator",nil,

Registers the following function with darktable, making it accessible
as "mosaic generator" when exporting.  The "module_stitcher" is
the darktable internal name, that has to be unique.  The first "nil"
is a slot for a function that will get called for each image.  For
printing, you'd probably want to use this slot, rather than the
next one.

  3       function(storage,image_table)

This function will get called once all the images have been exported.
Since the goal of this lua script is to genarate a contact sheet of
all the images printed out, it obviously needs all the images on disk,
before it can work.

  4            dt.print_error("Will try to stitch now")
  5            command = "gm convert "

Start of the shell command that will be called.  This is using "gm".
You'd replace this with whatever command it is you'd use to print an
image from the command line.

  6            for _,v in pairs(image_table) do
  7                    command = command..v.." "
  8            end
  9            command = command.."-append -resize 15%
"..dt.configuration.tmp_dir.."/tmp.png"

Building up the command line, by looping through all the pairs in the
image_table.  That table is two columns, the image object, and the
filename of the exported image.  Since we don't care about the object,
that's just stored in "_" (lua convention for a dummy variable).

For printing in a function in the "store" callback slot, you don't have
to do all of this, because the arguments to the "store" callback are
different (see the api wiki page for that), and you can just use the
filename directly.

 10            dt.print_error("this is the command: "..command)
 11            os.execute(command)

Call the shell command...

 12
 13            dt.print("Stitching saved to
"..dt.configuration.tmp_dir.."/tmp.png")
 14        end
 15    )

So, for a simple lua script that would print images as they're exported:

  1 dt = require "darktable"
  2 dt.register_storage("module_printpix","print images",
  3    function(storage,image,format,filename,num,total,high_quality)
  4         dt.print_error("Printing "..num.." of "..total..": "..filename)
  5         os.execute("lpr "..filename)
  6     end,
  7     nil
  8 )

Hopefully that syntax is correct. Not sure about the comma after the
end, but I'm assuming that's correct for anonymous functions passed in
as an argument.  Obviously, I know nothing about the complexities of
printing images from the command line. :)

Cheers,
Ammon

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
darktable-devel mailing list
darktable-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/darktable-devel

Reply via email to