libvips/lua-vips

Optional named arguments, not implemented?

uasan opened this issue · 3 comments

uasan commented

Hello.

I try sent {Q = 60, strip = true} to write_to_file(), but does not work

image = vips.Image.thumbnail("somefile.jpg", 128)
image:write_to_file("tiny.jpg", {Q = 60, strip = true, optimize_coding = true})

Then i defined the function vips_jpegsave()

ffi.cdef[[
int vips_jpegsave (VipsImage *in, const char *filename, ...);
]]

Use

vips.vips_jpegsave(image, file_out, "Q", ffi.new('int', 60), "strip", true, nil)

I liked FFI vips = ffi.load("vips"), without helpers vips = require './vips' but how much it is correct and safe?

Thank.

Hello, it should work, what errors did you see?

I made this program:

vips = require "vips"

local image = vips.Image.thumbnail("k2.jpg", 128)
image:write_to_file("x.jpg", {Q = 60, strip = true, optimize_coding = true})

And ran it:

$ luajit x.lua 
$ ls -l x.jpg 
-rw-r--r-- 1 john john 2568 Jun  2 08:48 x.jpg

The result looks fine.

Yes, you can call vips directly yourself, but I think you'll find it's very easy to cause a crash or a memory leak, and you have to write a lot of code.

uasan commented

Hello, it should work, what errors did you see?

Yes, i update lua-vips to master version, is work, thank.

Good! I'll close.