leafo / magick Goto Github PK
View Code? Open in Web Editor NEWLua bindings to ImageMagick for LuaJIT using FFI
Lua bindings to ImageMagick for LuaJIT using FFI
There's a couple of memory leaks when using ffi.string, because ffi.string makes a copy, you should free original string using MagickRelinquishMemory.
http://www.imagemagick.org/Usage/crop/#border
Any chance we can get support for the border method?
Documentation:
img:composite(source, compose, x, y)
Code:
composite = function(self, blob, x, y, opstr)
Documentation should be:
img:composite(source,x,y,compose)
When I try to load this module. It gives me below error.
loop or previous error loading module 'magick'
So I was attempting to create and edit png images on the fly with magick, but I found that neither the magick.new
or the magick.new_image
function existed.
Would you like me to take a crack at adding them in a PR? I am not familiar with moon or the busted system.
For anyone looking for a really poor performance workaround using os.execute
and imagemagick's convert
, you can use this:
__tmp = '/tmp/pico2png.temp.png'
function new_image(w,h)
os.execute('convert -size '..w.."x"..h..' xc:white '..__tmp)
local png,err = magick.load_image(__tmp)
return png,err
end
__points = {}
__count = 0
function set_pixel(x,y,r,g,b)
table.insert(__points,"fill rgb("..r..","..g..","..b..") point "..x..","..y.." ")
if __count > 2^12 then
__flush_pixels()
__count = 0
end
__count = __count + 1
end
function __flush_pixels()
os.execute("convert -draw '"..table.concat(__points).."' "..__tmp.." "..__tmp)
__points = {}
end
-- run this before reading information about your image object.
function __post()
__flush_pixels()
return magick.load_image(__tmp)
end
Hi leafo,
I have a problem with two consecutive requests, this is my code
local img = assert(magick.load_image(image.jpg))
img:crop(250,250,360,130)
img:resize_and_crop(150, 100)
with this code output is a image with 1x1 pixel,
however, if I do this:
local img = assert(magick.load_image(image.jpg))
img:crop(250,250,360,130)
img = assert(magick.load_image_from_blob(get_blob()))
img:resize_and_crop(150, 100)
It works as expected, why?
Hi,
i am mostly converting camera images that have EXIF information set. Generating jpg thumbs with dimensions 100x75, the image size is ~36KB, but when i strip the EXIF data, the file size reduces to 8KB. (imagemagick's convert -strip option) How do i do that with the lua bindings?
Best
Does magick support thumbnailing the whole gif image with multiple frames?
in addition to individual pixel access with get_pixel() is it possible to add a feature that returns an array of pixels using the
GetAuthenticPixels
GetAuthenticPixelQueue
route?
is there a method that returns the bit depth? particularly since pixel values are returned as doubles from 0 to 1, getting the actual pixel value back as an integer requires this.
Installation instructions is missing in README
I have no idea where to start.
This line sometimes (when testing a fair amount of load) gives an error attempting to index a nil value.
line 162
local lname = get_flags():match("-l(MagickWand[^%s]*)")
I've added the following to see what gave the issue:
if (get_flags() == nil) then return error("Failed to load MagickWand ") end
And indeed this error gets returned, indicating get_flags() is nil.
What could be the problem here?
convert one.png two.png three.png -compose displace -composite cylinderCMD.png
Hello @leafo I'm trying to convert this command into C and later on I want to use it in lua. For that I used below set of methods. Could you help me to do this? I wouldn't have to posted a C
related question over here but my ultimate goal is to use it in lua so I did. And for detail information you can check this link.
MagickCompositeImage(wand, wand2, DisplaceCompositeOp,MagickFalse, 0, 0); MagickCompositeImage(wand, wand3, DisplaceCompositeOp,MagickFalse, 0, 0); MagickWriteImage(wand,"final.png");
Using lapis framework i need to send an image created on-the-fly
local magick = require("magick")
local ngx = ngx
return function(self)
local str_img = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mP8z8BQz0AEYBxVSF+FABJADveWkH6oAAAAAElFTkSuQmCC"
local img = magick.load_image_from_blob(ngx.decode_base64(str_img))
ngx.header["content-type"] = "image/png"
// HERE, HOW TO SEND THE IMAGE TO BROWSER ?
img:destroy()
end
Sample output from luarocks search -all
can be found this gist
using LuaRocks 2.2.2 on OSX (installed via lua homebrew package)
I spend 3 work days trying to realize auto rotate by EXIF info function for this library.
But it is in the library!!!
Please, note this in documentation!
You can use img:auto_orient() function to rotate images by EXIF info!
And check file /usr/local/share/lua/5.1/magick/wand/image.lua before you begin make some new functionality!
I love the magick project! :)
Especialy after a found auto_orient option.
But, whet i resize PDF file to PNG i got the last page. Why?
I really need the first!
And if it possable , it would be grate to get option as
convert source.pdf[0] output.jpeg
Hi,
can you integrate the trim function? i hacked it myself (copy of strip() function) but i'm not a lua programmer.
Thx
Failed to load filter list, can't resize
maybe because of my imagemagick path? It's installed via homebrew
Hi guys,
when calling the thumb function with an webp image an error is raised. Can anyone tell whats wrong ?
im running it inside a docker container:
Dockerfile:
`FROM openresty/openresty:bionic
RUN apt-get update && apt-get install -y libmagickwand-dev libgraphicsmagick1-dev
RUN /usr/local/openresty/luajit/bin/luarocks install magick`
root@a96b53ba6d5c:/# apt-cache policy libmagickwand-dev libgraphicsmagick1-dev
libmagickwand-dev:
Installed: 8:6.9.7.4+dfsg-16ubuntu6.11
Candidate: 8:6.9.7.4+dfsg-16ubuntu6.11
Version table:
*** 8:6.9.7.4+dfsg-16ubuntu6.11 500
500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
100 /var/lib/dpkg/status
8:6.9.7.4+dfsg-16ubuntu6 500
500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
libgraphicsmagick1-dev:
Installed: 1.3.28-2ubuntu0.1
Candidate: 1.3.28-2ubuntu0.1
Version table:
*** 1.3.28-2ubuntu0.1 500
500 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages
100 /var/lib/dpkg/status
1.3.28-2 500
500 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
Version:
openresty/1.19.9.1
built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
OS: Linux 5.10.25-linuxkit
serve_image.lua:
`-- resize the image
local magick = require("magick")
magick.thumb(source_fname, size, dest_fname)
ngx.exec(ngx.var.request_uri)`
the error:
2021/11/11 10:45:48 [error] 12#12: *3 lua entry thread aborted: runtime error: /usr/local/openresty/luajit/share/lua/5.1/magick/thumb.lua:59: unable to open file
/tmp/magick-126rH8Q2ow8ZUn': No such file or directory @ error/constitute.c/ReadImage/544
images_1 | stack traceback:
images_1 | coroutine 0:
images_1 | [C]: in function 'assert'
images_1 | /usr/local/openresty/luajit/share/lua/5.1/magick/thumb.lua:59: in function 'thumb'
images_1 | /serve_image.lua:61: in main chunk, client: 172.20.0.1, server: , request: "GET /YmNiMGI2NzBi/50x50/1656955fcd7fbcaf8ed861f4af9b25b6_36.webp HTTP/1.1", host: "images.dev:81"
`
Can anyone help?
Thanks in advance
Mak
log
$ luarocks install --local https://raw.githubusercontent.com/leafo/magick/master/magick-dev-1.rockspec
Using https://raw.githubusercontent.com/leafo/magick/master/magick-dev-1.rockspec... switching to 'build' mode
Cloning into 'magick'...
remote: Counting objects: 24, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 24 (delta 1), reused 14 (delta 0), pack-reused 0
Receiving objects: 100% (24/24), 52.74 KiB | 0 bytes/s, done.
Resolving deltas: 100% (1/1), done.
Checking connectivity... done.
Error: Build error: Failed installing magick/wand/data.lua in /home/vagrant/.luarocks/lib/luarocks/rocks-5.1/magick/dev-1/lua/magick/wand/data.lua
commenting out those lines in the rockspec solves it for me:
-- ["magick.gmwand.lib"] = "magick/gmwand/lib.lua",
-- ["magick.wand.data"] = "magick/wand/data.lua",
(but probably disables functionality)
hi leafo!
Because WebP lossless images are 26% smaller in size compared to PNGs,so i want to use webp format in lua to scale my image, can you give me some help?
I randomly will get this error when doing a simple require of this magick library
lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/magick/init.lua:148: attempt to index a nil value
If I refresh the page, everything will be fine again.
I am able to run MagickWand-config from console.
Any idea why this would happen?
It looks like Windows has 2 different DLLs that need to be taken into account. The current file structure of this lib doesn't really make it simple to get this working... https://github.com/clementfarabet/graphicsmagick/blob/master/Image.lua#L327-L336
How to install with CentOS 6.6
Online production environment is CentOS 6.6, not ubuntu / Debian
After install
sudo apt-get install luajit
sudo apt-get install libmagickwand-dev
sudo apt-get install luarocks
luarocks install magick
here is error:
local _obj_0 = require("magick.wand.lib")
stack traceback:
[C]: in function 'require'
/usr/local/lib/lua/magick.lua:5: in main chunk
[C]: in function 'require'
I can't find magick.wand.lib in my system.
How to make it work?
Lua current version is 5.3.4 ; do you have any plan to support Lua newest version?
Hi leafo,
Any idea when the current changes may be published to MoonRocks? The current version out there seems to be quite old. I'm currently just copying this file from here to use the strip function on my images. If you need help testing to ensure a clean publish, I may be able to pitch on too.
Thanks!
`local magick = require "magick"
local img = magick.load_image("white.ico")
local blob = img:get_blob()
local img2 = magick.load_image_from_blob(blob)
img2:write("test2.ico")`
error:
luajit: test2.lua:6: attempt to index local 'img2' (a nil value) stack traceback: test2.lua:6: in main chunk [C]: at 0x55d98ce58120
Works fine when I try it with a png format.
The icon is white and of size 1px and was created using GIMP.
The binary seems to have been renamed GraphicsMagickWand-config
in debian/testing.
See here for the content of the package.
image.get_pixel is very handy to read a pixel but there is no way to write a pixel! I'm trying to batch manipulate a bunch of images so I really need the ability to set pixels..
Now I have a requirement, to scan the image of some pixel, to ensure if it is an advertisement image..
I want to rotate image by lua , does the magick support ?
In function get_blob:
local blob = lib.MagickGetImageBlob(self.wand, len)
the blob is a detached one from the original image->blob, so it must be freed by hand or change the above line with:
local blob = ffi.gc(lib.MagickGetImageBlob(self.wand, len), ffi.C.free)
When i add line to code
local magick = require("magick")
nginx log say:
2016/06/29 14:10:38 [info] 5#0: waitpid() failed (10: No child processes)
2016/06/29 14:10:39 [notice] 5#0: signal 17 (SIGCHLD) received
It is normal?
I have installed magick but when I try to access it, it gives me an error says magick not found.
2017/03/09 10:57:15 [error] 27432#0: *1 lua entry thread aborted: runtime error: ...tml/default/image-server-tutorial/magick-master/test.lua:1: module 'magick' not found:
no field package.preload['magick']
no file '/usr/local/openresty/site/lualib/magick.lua'
no file '/usr/local/openresty/site/lualib/magick/init.lua'
no file '/usr/local/openresty/lualib/magick.lua'
no file '/usr/local/openresty/lualib/magick/init.lua'
no file './magick.lua'
no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/magick.lua'
no file '/usr/local/share/lua/5.1/magick.lua'
no file '/usr/local/share/lua/5.1/magick/init.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/magick.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/magick/init.lua'
no file '/usr/local/openresty/site/lualib/magick.so'
no file '/usr/local/openresty/lualib/magick.so'
no file './magick.so'
no file '/usr/local/lib/lua/5.1/magick.so'
no file '/usr/local/openresty/luajit/lib/lua/5.1/magick.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
above is my output. And when I checked "whereis magick", it gives me "magick: /usr/local/bin/magick".
On my machine, resample.h
file is in /usr/include/ImageMagic-6/magick
directory:
root@281ff7a9897e:/home/openresty# find / -name 'resample.h'
/usr/include/ImageMagick-6/magick/resample.h
Here my output of command that get_flags
function uses:
root@281ff7a9897e:/home/openresty# pkg-config --cflags --libs MagickWand
-fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/x86_64-linux-gnu//ImageMagick-6 -I/usr/include/ImageMagick-6 -I/usr/include/x86_64-linux-gnu//ImageMagick-6 -I/usr/include/ImageMagick-6 -lMagickWand-6.Q16 -lMagickCore-6.Q16
As you can see, required directory is the second, while only first include path is used by get_filters
method. So it need to be improved to search for all include path and not only the first.
currently
MagickBooleanType MagickCompositeImage(MagickWand *wand,
const MagickWand *source_wand,const CompositeOperator compose,
const ssize_t x,const ssize_t y);
but by API docs must be
MagickBooleanType MagickCompositeImage(MagickWand *wand,
const MagickWand *source_wand,const CompositeOperator compose,
const MagickBooleanType clip_to_self,
const ssize_t x,const ssize_t y);
Can you please specify the license?
I have been trying to implement MagickGetImageHistogram, so I have changed two files. below is my change.
image.lua
local len = ffi.new("size_t[?]", 5)
local t = handle_result(self, lib.MagickGetImageHistogram(self.wand, len))
lib.lua
ffi.cdef([[ typedef void MagickWand;
typedef void PixelWand;
typedef int MagickBooleanType;
typedef int ExceptionType;
typedef int ssize_t;
typedef int CompositeOperator;
typedef int GravityType;
typedef int OrientationType;
typedef int InterlaceType;
typedef char DistortMethod[];
void MagickWandGenesis();
MagickWand* NewMagickWand();
PixelWand **MagickGetImageHistogram(MagickWand *wand, size_t *number_colors);
]])
But when I called MagickGetImageHistogram function from image.lua, it always return bool true. I don't understand what I missed. In documentation it says
MagickGetImageHistogram() returns the image histogram as an array of PixelWand wands.
So how do I convert it to lua table?
`
local magick = require "magick"
local bg = magick.load_image("bg.png")
local compose = magick.load_image("h1.gif")
bg:composite(compose, 1000, 0, "XorCompositeOp")
compose:destroy()
bg:write("bg.png")
bg:destroy()
`
The image gets drawn but in the incorrect position, it should be (1000, 0) but the result is (0, 0)
with magick.gmwand the program works as intended
How can I make progressive images?
I use
local image = assert(magick.load_image('my_photo.jpg'))
image:set_interlace_scheme('PlaneInterlace')
ngx.say(image:get_blob())
ngx.exit(ngx.OK)
but this service http://highloadtools.com/progressivejpeg put no prograssive image.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.