Some functions aren't found
GildedHonour opened this issue · 6 comments
A web app.
I want to take a requested an image file, put watermark on it on the fly via LuaJit and return an output image without creating an image file with a watermark. All via nginx.
I've faced with several "not found this functions" errors.
a part of my code:
local vips = require("vips")
local img = vips.Image.new_from_file("/path/to/image123.png", {access = "sequential"})
local text = vips.Image.text("watermark123", {width = 200, dpi = 200, align = "centre", font = "sans bold"})
-- NOTE 1
text = text:rotate(-45)
-- make the text transparent
text = (text * 0.3):cast("uchar")
-- NOTE 2
text = text:gravity("centre", 200, 200)
-- this block of pixels will be reused many times ... make a copy
--text = text:copy_memory()
text = text:replicate(1 + img:width() / text:width(), 1 + img:height() / text:height())
text = text:crop(0, 0, img:width(), img:height())
-- we make a constant colour image and attach the text mask as the alpha
local overlay = text:new_from_image({255, 128, 128}):copy({interpretation = "srgb"})
overlay = overlay:bandjoin(text)
-- overlay the text
img = img:composite(overlay, "over")
-- buff = img:write_to_buffer(".jpg")
buff = img:write_to_buffer(".png")
ngx.print(buff)
ngx.flush(true)
Errors:
* VipsOperation: class "rotate" not found
stack traceback:
coroutine 0:
[C]: in function 'error'
/usr/local/share/lua/5.1/vips/voperation.lua:155: in function 'rotate'
* VipsOperation: class "gravity" not found
stack traceback:
coroutine 0:
[C]: in function 'error'
/usr/local/share/lua/5.1/vips/voperation.lua:155: in function 'gravity'
* lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/vips/gvalue.lua:76: no such enum over
lua-vips: no such enum type
stack traceback:
coroutine 0:
[C]: in function 'error'
/usr/local/share/lua/5.1/vips/gvalue.lua:76: in function 'to_enum'
/usr/local/share/lua/5.1/vips/Image_methods.lua:555: in function 'composite'
What can cause them?
lua -v
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
luajit -v
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/
# or, obtained via nginx itself
LuaJIT 2.1.0-beta3
Ubuntu 18
I commented out the code with "rotate", then got "gravity" error. Then I commented out "gravity" and got the 3rd error.
vips -v
vips-8.2.2-Sat Jan 30 17:12:08 UTC 2016
My libvips turned out to be outdated
Hi, yes, lua-vips is a dynamic binding, so it presents the operations it find in your libvips at run-time.
Ok
In the documentation there's no mention of how to save to a buffer in the png format, only in the jpg. Is this a correct way
buff = img:write_to_buffer(".png")
?
Hey Alex, yes, it should work.
That will search for a loader that has .png
as a save suffix, then run that for you. You can also just call the PNG saver directly:
buff = img:pngsave_buffer()
Thx