imagemagick-aws-lambda-2 icon indicating copy to clipboard operation
imagemagick-aws-lambda-2 copied to clipboard

adding freetype support and updating version of ImageMagick

Open sw360cab opened this issue 4 years ago • 24 comments

I think that it may be useful to achieve freetype engine support when dealing with fonts in images. It is worthy since the library compile statically easily as libpng and libjpg and it does slightly increase the final archive.

I took the chance to update also the ImageMagick and libjpg version. I tested and it compile smootly.

sw360cab avatar Jun 05 '20 09:06 sw360cab

I tried this branch but get an error about missing fonts when I try to use the layer in a lambda.

convert: unable to read font `helvetica' @ error/annotate.c/RenderFreetype/1392.
convert: non-conforming drawing primitive definition `text' @ error/draw.c/RenderMVGContent/4434.

is it possible ghostscript is also needed? My research suggests that type.xml must exist and point to actual font files on the system, and those seem to be part of gs.

karpet avatar Jul 20 '20 18:07 karpet

Hi, are you sure you pointed the right path of Helvetica Font when launching the command?

I am unable to try right now. Let m know if you succeed in any way.

sw360cab avatar Jul 21 '20 06:07 sw360cab

Our existing code never makes explicit calls to set the font, so the helvetica must be a default of some kind.

Can you provide an example of setting the font path as you describe? I tried:

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

with no luck.

karpet avatar Jul 21 '20 16:07 karpet

ok I figured out I needed to make the .ttf file available and set it like:

gm.font("path/to/file.ttf")

works wonderfully -- thank you!

karpet avatar Jul 21 '20 19:07 karpet

Are there any plans to merge this in the near future?

RobTS avatar Sep 01 '20 19:09 RobTS

@RobTS it would be nice for me. AFAIK there is not a lot of interest in having FreeType in the state of the art AWS Lambda Layer. Btw if you want you can you use my layer (arn:aws:lambda:eu-west-1:797374828937:layer:image-magick-freetype:3) that is the exact fork of this supporting freetype.

sw360cab avatar Sep 02 '20 17:09 sw360cab

Btw if you want you can you use my layer (arn:aws:lambda:eu-west-1:797374828937:layer:image-magick-freetype:3) that is the exact fork of this supporting freetype.

Hi, and thanks for your work on this. I'm having trouble using this layer in my own app as I keep running into permissions problems like this:

not authorized to perform: lambda:GetLayerVersion on resource

My IAM profile has all the required permissions but still no luck. Do I have to "import" or "clone" this layer into my own account in order to use it?

edjames avatar Oct 21 '20 16:10 edjames

I tried to grant to all (*). Give it a try.

sw360cab avatar Oct 21 '20 18:10 sw360cab

I tried to grant to all (*). Give it a try.

Thanks @sw360cab. Unfortunately still no dice :(

User: arn:aws:iam::*********:user/******** is not authorized to perform: lambda:GetLayerVersion on resource: arn:aws:lambda:eu-west-1:797374828937:layer:image-magick-freetype:3 (Service: AWSLambdaInternal; Status Code: 403; Error Code: AccessDeniedException; Request ID: fad6777e-7094-4c80-9347-f66c9f139ce7; Proxy: null)

Is there any chance you have the zip file available? If so I would very much appreciate it.

edjames avatar Oct 22 '20 06:10 edjames

I would zip it. But I would be more happy if we are able to share it via AWS. In which region are you publishing your Lambda? Because I tried to import the layer in a Lambda in another accout and It works like a charm, but the region is EU-WEST-1 (Ireland). If you are in another region I need to republish the layer there.

sw360cab avatar Oct 22 '20 08:10 sw360cab

Ah good point! I'm in EU-WEST-2. Thanks mate!

edjames avatar Oct 22 '20 08:10 edjames

I will publish the layer there

sw360cab avatar Oct 22 '20 08:10 sw360cab

I will publish the layer there

👍 I will let you know if it works for me. Thanks very much.

edjames avatar Oct 22 '20 08:10 edjames

Give a try to this ARN:

arn:aws:lambda:eu-west-2:797374828937:layer:image-magick-freetype:1

sw360cab avatar Oct 22 '20 08:10 sw360cab

Awesome! That works.

I'm now stuck with a new error with fonts but I think this is ghostrscript:

montage: unable to read font `helvetica'

Ugh! Thanks for your help though.

edjames avatar Oct 22 '20 11:10 edjames

That should be just a matter of font path. Happy it worked almost out of the box

sw360cab avatar Oct 22 '20 12:10 sw360cab

I will publish the layer there

@sw360cab

Will you please publish to us-east-1? How do I include the specific font I want to use?

Zelfapp avatar Oct 27 '20 01:10 Zelfapp

That should be just a matter of font path. Happy it worked almost out of the box

Not sure how to control that though. When I check for available fonts using the below command it does show that Helvetica is available (not sure if this is case-sensitive):

identify -list font

Any help much appreciated.

edjames avatar Oct 27 '20 10:10 edjames

@Zelfapp Here is the ARN for us-east-1 arn:aws:lambda:us-east-1:797374828937:layer:image-magick-freetype:1

@edjames

Have you tried using convert with -font and the absolute path to font as .tff file?

AFAIK Helvetica is not free of download, it has a paid license.

sw360cab avatar Oct 27 '20 14:10 sw360cab

@sw360cab Can you share the zip file? I followed your method to create the layer but the symlink is not being created

abishekaditya avatar Jan 12 '21 20:01 abishekaditya

@abishekaditya tried by following this or this?

sw360cab avatar Jan 14 '21 16:01 sw360cab

yes, unfortunately both didn't work properly because of linking issues. so I ran imagemagick on an Amazon Linux 2 instance in cloud9 and saw which .so files were being accessed. Then I copied these files into /usr/lib/ folder and then it worked

abishekaditya avatar Jan 27 '21 12:01 abishekaditya

ok, Feel free to open a PR on my repo fork

sw360cab avatar Jan 28 '21 08:01 sw360cab

Sure. I was busy with other things till now. Have to work on this again, so will try to fix this

abishekaditya avatar Mar 06 '21 03:03 abishekaditya