brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.15k stars 365 forks source link

Support imagettftext by compiling GD with freetype #497

Closed dwahlqvist closed 3 years ago

dwahlqvist commented 5 years ago

Use case: I'm trying to migrate an image manipulation service that's adding text to an animated gif.

My code works on my regular Ubuntu18 PHP install, but not with Bref 0.5.10 & Lambda.

I get the error message Call to undefined function ...\\imagettftext()".

imagettftext is included in GD, but according to php.net "This function is only available if PHP is compiled with freetype support (--with-freetype-dir=DIR )" .

It seems to me GD is already included in Bref so, I believe the solution is to compile PHP with freetype support.

I understand it should be technically possible for me to achieve this, by adding a custom layer, as described on bref.sh. I have spent many hours trying, but didn't succeed. There are just too many moving parts for me who is new to both serverless and compiling PHP.

mnapoli commented 4 years ago

Hi! Yes, that's something that we can look into adding (I actually would use this myself).

The question would be: how bigger would the layer be with the freetype included? If it's acceptable, then we can add it directly in Bref. If it's too heavy, we should either not include it, or create a separate layer providing just that (better).

Nyholm commented 4 years ago

Maybe we should remove GD from core an add it in the bref/extra-php-extensions.

mnapoli commented 4 years ago

We could, but is it worth the bc break and the trouble for users (having to install an extra layer)? (since GD is used by a few people)

Ideally we should check if we would save a lot of space? (trimming the layer would help bring cold starts down too) Especially if we take into account this issue (freetype) as well as #531 (that add more to the size of the layer)

rkitron commented 4 years ago

Hi,

Do you have an ETA for this ? I have an issue with GD and truetype ..

Do you have a contribute guide ? As I need it quickly, I can work on it :)

Thanks,

victormacko commented 4 years ago

@benoitmenard best approach is just to compile it on your end, post the layer sizes for both uncompressed and compressed (compared with the later sizes before any changes were made) -- that's the first step with the majority of extension additions.

(oh - and put through a pull-request as well!)

To quote mnapoli in another post;

When you build the layers with Bref, you have to do:

cd runtime make runtimes The generated layers will be in the runtime/export/ directory.

What you can do is ls -la and paste the result in the pull request (that you can create over the Bref repository).

That way we can see the new size of the layers. We can then compare that with the current layers (I will do that, I have them already built on my machine).

rkitron commented 4 years ago

I did some test and its works well for me; but only for 7.3.

Quick question but not related, I saw that the PHP version used is 7.3.7 and 7.3.17 is available; how do handle the upgrade of PHP; and also related things (libssh, postgres, etc ...)

Thanks

Nyholm commented 4 years ago

Have a look here: https://github.com/brefphp/bref/blob/master/runtime/base/php-73.Dockerfile#L16

drAlberT commented 4 years ago

We could, but is it worth the bc break and the trouble for users (having to install an extra layer)? (since GD is used by a few people)

Ideally we should check if we would save a lot of space? (trimming the layer would help bring cold starts down too) Especially if we take into account this issue (freetype) as well as #531 (that add more to the size of the layer)

@mnapoli do you think that making it a "shared object" would make it possible to unload the bundled one and load the layers one? This would make the change BC ...

Ppl needing truetype will require an additional bref layer, while the others would continue as usual using the bundled (shared, .so) GD extention ...

mnapoli commented 4 years ago

We could do like imagick though: deprecate the built-in gd extension, and work on the extension in the "extra" layer.

In the next major release, the gd extension could be completely removed from the main layer.

drAlberT commented 4 years ago

@mnapoli any ETA? I already started to work on the layer at https://github.com/brefphp/extra-php-extensions/pull/37 (it has to be tested, but it could already work)

mnapoli commented 4 years ago

Hi, no ETA at the moment.

mnapoli commented 3 years ago

Done in https://github.com/brefphp/extra-php-extensions/pull/76