rpidanny / gm-lambda-layer

AWS Lambda layer with GraphicsMagick binaries.
http://www.graphicsmagick.org
MIT License
68 stars 24 forks source link

Issues with shared libraries #1

Closed tunix closed 5 years ago

tunix commented 5 years ago

Hi,

Thank you for your contribution in the first place. I'm trying to watermark (by just writing text with an angle) images using Lambda and S3 and discovered your layer code.

The code I'm using is a nodejs (10.x) app. When using your layer, I got "write EPIPE" error. I tried to simulate the environment like below:

cat ~/Desktop/sampleEvent.json | docker run -i --rm \
    -v "$PWD":/var/task \
    -v $HOME/Desktop/layers:/opt \
    -e DOCKER_LAMBDA_USE_STDIN=1 \
    -e AWS_ACCESS_KEY_ID="XXX" \
    -e AWS_SECRET_ACCESS_KEY="XXX" \
    lambci/lambda:nodejs10.x index.handler

However I see the following error this time:

Error: Command failed: gm: error while loading shared libraries: liblcms2.so.2: cannot open shared object file: No such file or directory

The code itself just uses "gm" and not imagemagick itself. I tried disabling liblcms during compilation but this time got another shared library issue (libtiff).

Here's a sample code:

const gm = require("gm");

...

        gm(response.Body).size({bufferStream: true}, (err, size) => {
            if (err) {
                reject(err);

                return;
            }

            let width = size.width;
            let height = size.height;
            let angle = (Math.atan(height / width) * (180 / Math.PI)) * -1;
            let pointsize = Math.sqrt(width * width + height * height) / text.length;

            gm(response.Body)
                .pointSize(pointsize)
                .gravity("Center")
                .fill(color)
                .draw([`rotate ${angle} text 0,0 "${text}"`])
                .toBuffer((err, buffer) => {
                    if (err) {
                        err.srcKey = srcKey;

                        reject(err);
                    } else {
                        console.log(`Successfully processed ${srcKey}!`);

                        resolve({
                            buffer: buffer,
                            contentType: contentType
                        });
                    }
                });
        });

...
rpidanny commented 5 years ago

Hi @tunix ,

Thanks for submitting the issue.

I have pushed the fixes in a new branch. Can you confirm if it works?

From my tests, it should be working now.

tunix commented 5 years ago

@rpidanny Yes! 🎉 It works just like expected! Thank you very much. Would you mind building and pushing a new version of the layer?

rpidanny commented 5 years ago

@tunix I've pushed the new version.

Should be accessible on arn:aws:lambda:eu-west-1:175033217214:layer:graphicsmagick:2

tunix commented 5 years ago

Thank you very much! 🙏