serverlesspub / imagemagick-aws-lambda-2

ImageMagick for AWS Lambda 2 runtimes
https://serverless.pub
Other
259 stars 162 forks source link

adding freetype support and updating version of ImageMagick #28

Open sw360cab opened 4 years ago

sw360cab commented 4 years ago

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.

karpet commented 4 years ago

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.

sw360cab commented 4 years ago

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.

karpet commented 4 years ago

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 commented 4 years ago

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!

RobTS commented 4 years ago

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

sw360cab commented 4 years ago

@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.

edjames commented 3 years ago

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?

sw360cab commented 3 years ago

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

edjames commented 3 years ago

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.

sw360cab commented 3 years ago

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.

edjames commented 3 years ago

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

sw360cab commented 3 years ago

I will publish the layer there

edjames commented 3 years ago

I will publish the layer there

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

sw360cab commented 3 years ago

Give a try to this ARN:

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

edjames commented 3 years ago

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.

sw360cab commented 3 years ago

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

Zelfapp commented 3 years ago

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?

edjames commented 3 years ago

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.

sw360cab commented 3 years ago

@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.

abishekaditya commented 3 years ago

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

sw360cab commented 3 years ago

@abishekaditya tried by following this or this?

abishekaditya commented 3 years ago

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

sw360cab commented 3 years ago

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

abishekaditya commented 3 years ago

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