vercel-community / php

🐘 PHP Runtime for ▲ Vercel Serverless Functions (support 7.4-8.3)
https://php.vercel.app
MIT License
1.28k stars 295 forks source link

How can I install GD? #60

Open konnorov opened 4 years ago

konnorov commented 4 years ago

How can I remove the error:

Fatal error: Uncaught Error: Call to undefined function imagecreatefrompng() in /var/task/user/api/image.php:8 Stack trace: #0 {main} thrown in /var/task/user/api/image.php on line 8

help plz(

f3l1x commented 4 years ago

Hey @konnorov. GD extension is not bundled in now-php. It requires so many shared libs and Vercel's limit is about 50mb per lambda.

konnorov commented 4 years ago

Sad :(

Are there any other ways to add text to photos supported by ZEIT?

f3l1x commented 4 years ago

I see few options here.

WilliamBlais commented 4 years ago

@f3l1x If I add gd to php.ini, will it work? Do you have any examples on how to add an extension to vercel/php?

f3l1x commented 4 years ago

Hi @WilliamBlais. Problem is not PHP ini, but GD extension it self. It looks like it requires so much filespace (filesize) and many shared libraries installed on platform. We are limited by 50 MB per 1 lambda. So, GD extension is not supported at this moment.

Take a look at FAQ (https://github.com/juicyfx/vercel-php#%EF%B8%8F-faq), there is example how to edit php.ini.

Jobians commented 2 years ago

@f3l1x @WilliamBlais

Please I encounter this issue, have you find any solution for it?

sonaxa commented 2 years ago

Hey @f3l1x Found that the gd extension it is present in an older version Here Would it be possible to include it ? or a way to make it work ? I keep getting the error below when using the older vercel-php version which uses that extension during build

Error: The Runtime @vercel/vc-build is using nodejs12.x, which was discontinued by an upstream provider. In turn, we have to ask you to upgrade your Runtime to a more recent version or consult the author for more details.

f3l1x commented 2 years ago

Hi @sonaxa and @Jobians, there is a problem with size of the lambda.

Problem is not PHP ini, but GD extension it self. It looks like it requires so much filespace (filesize) and many shared libraries installed on platform. We are limited by 50 MB per 1 lambda. So, GD extension is not supported at this moment.

tao commented 3 weeks ago

Imagick is included in the server image, so you can generate thumbnails with spatie/image library or any other library that supports ext-imagick instead of ext-gd. I was able to create thumbnails and watermarks with my Laravel app, you just need to remember to save all the images to the /tmp folder and then if you want to keep them, upload it to S3 afterwards or another storage provider.

My process was

  1. Check if the thumbnails exist on S3... otherwise
  2. Download source image to /tmp
  3. Generate thumbnails in /tmp/thumbnails
  4. Upload thumbnails from /tmp/thumbnails to S3.
  5. Serve thumbnails with the S3 URL.

You can also add text with spatie/image so I'm sure it's possible with other libraries that support imagick.