Skip to content

question on usage in layer #22

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
BryanGerre opened this issue Jan 18, 2020 · 7 comments
Open

question on usage in layer #22

BryanGerre opened this issue Jan 18, 2020 · 7 comments

Comments

@BryanGerre
Copy link

I've added the layer using the link ServerlessPub link and clicked deploy which added a layer named image-magick
I then attached the layer to my lambda. In my lambda I have
const gm = require('gm').subClass({imageMagick: true});

Is that using the layer? For some reason I'm unable to see any words on my image using drawText

here is my code in full

const gm = require('gm').subClass({imageMagick: true});

const { IMAGES_DIR, TEXT_SIZE, TEXT_PADDING } = process.env;

const parseText = text => (text || '').toUpperCase();
const getImages = () => fs.readdirSync(IMAGES_DIR);
const parseImage = image => getImages().find(file => file.indexOf(image) === 0);
const random = arr => arr[Math.floor(Math.random() * arr.length)];
const randomImage = () => random(getImages());

module.exports.meme = (event, context, callback) => {
  const input = event.queryStringParameters || {};

  const top = parseText('hello');
  const bottom = parseText('mem');
  const image = parseImage(input.image) || randomImage();
 

  const meme = gm(`${IMAGES_DIR}${image}`);

  meme.size(function (err, { height }) {
    meme
    .font('./impact.ttf', TEXT_SIZE)
    .fill('white')
    .stroke('black', 2)
    .drawText(0, -(height / 2 - TEXT_PADDING), 'hello', 'center')
    .drawText(0, height / 2 - TEXT_PADDING, bottom, 'center')
      .toBuffer(function (err, buffer) {
        callback(null, {
          statusCode: 200,
          headers: { 'Content-Type': 'image/jpeg' },
          body: buffer.toString('base64'),
          isBase64Encoded: true,
        });
      });
  });
}; `

@anija
Copy link

anija commented Feb 14, 2020

I've the same problem: everything is fine, resize and other functions works fine, but the drawText just don't work and doesn't raise any error/warning.

@anija
Copy link

anija commented Feb 14, 2020

Here's the solution: #6

@anija
Copy link

anija commented Feb 14, 2020

The compiled build in #6 is not working for me (buffer is always empty).
I've tried to build the library from 0, without changing anything from the repo, and the result is the same: buffer is always empty. I'm building with MacOs.

Any chance to get a precompiled and working layer zip with freetype?

@anija
Copy link

anija commented Feb 17, 2020

Solved! I was finally able tu build with freetype enabled.
Here's the Layer .zip to be uplaoded on AWS ;)
Archivio.zip

@bruno-smaldone
Copy link

@anija - This one worked for me, thank you very much for sharing it, you saved me a ton of work

@charlie-s
Copy link

charlie-s commented Mar 6, 2020

@anija Any chance we can get a hand with this? Uploaded Archivio.zip as a new layer, linked the layer to our simple Lambda function, and now code that worked with imagemagick-aws-lambda-2 is no longer working – produces Stream yields empty buffer output.

Here's our Lambda function with the extraneous bits removed, but this is the exact gm() call that we're making with this new layer:

const gm = require('gm').subClass({ imageMagick: true });
...
gm(path.join(__dirname, '/file.jpg'))
    .toBuffer('jpeg', (err, buffer) => {
        if (err) return console.error(err); <-- this throws.
        console.log(buffer)
    });

Is there anything else we need to do to use / link this layer and its binaries properly?

@jfederer
Copy link

@anija I'm not following. The .zip that you posted appears to be HarfBuzz OpenType text engine.

How does this work with imagemagick?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants