leafo / magick

Lua bindings to ImageMagick for LuaJIT using FFI
401 stars 79 forks source link

calling thumb function with images in webp format raises an error #65

Closed mskoric closed 2 years ago

mskoric commented 2 years ago

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

alexandrim0 commented 2 years ago

Hi!

Is it works with other type (not webp)? Where from values of source_fname, size, dest_fname comes? It is not clear.

But mainly, you have to set Content-Type header and print image to request response body. When you call ngx.exec file with image thumb is not saved to disk yet. My guess.

mskoric commented 2 years ago

Hi!

Is it works with other type (not webp)? Where from values of source_fname, size, dest_fname comes? It is not clear.

But mainly, you have to set Content-Type header and print image to request response body. When you call ngx.exec file with image thumb is not saved to disk yet. My guess.

hi,

thanks for your answer. yes. it works with jpg format. so it cant be that is something from with source_fname, size, dest_fname . also the mime.type is set correctly through nginx

root@6d7ba1f427a4:/# grep webp /usr/local/openresty/nginx/conf/mime.types image/webp webp;

its really strange. it seems that webp isnt supported from magick with luarocks maybe?

alexandrim0 commented 2 years ago

For webp you need not only libgraphicsmagick1 but libwebp-dev also: RUN apt-get update -y && apt-get install -y git autoconf libtool-bin libmagickwand-dev webp libwebp-dev && rm -rf /var/lib/apt/lists/*

mskoric commented 2 years ago

hi @alexandrim0

great! that worked like a charm. muchas gracias!

Thanks for your time!