php-image-resize icon indicating copy to clipboard operation
php-image-resize copied to clipboard

Call to undefined function Gumlet\imagecreatefromjpeg()

Open Script47 opened this issue 5 years ago • 6 comments

I'm using this library (1.9.*) in Laravel (v6) and getting the following exception:

Call to undefined function Gumlet\imagecreatefromjpeg()

when running the following line of code:

$imgObj = ImageResize::createFromString($var);

The trace narrows it down to ImageResize.php:170, which is:

$img = imagecreatefromjpeg($filename);

If I run php -m the output is:

$ php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zlib

[Zend Modules]

The only thing I can think of is that it's trying to find that method in Gumlet\imagecreatefromjpeg() instead of global PHP namespace.

Thoughts?

Script47 avatar Nov 12 '20 12:11 Script47

We can use the $img = \imagecreatefromjpeg($filename); and it will fix this issue.

The reason is about namespace checking on PHP runtime.

peter279k avatar Nov 12 '20 12:11 peter279k

@peter279k

One thing that remains unclear to me is how this isn't affecting everyone?

Also, out of curiosity when do you think this'll be patched?

Script47 avatar Nov 12 '20 12:11 Script47

Well, it's about the internal PHP version problem.

It will happen on some PHP versions and other will not. I also get this problem on some PHP versions.

peter279k avatar Nov 12 '20 12:11 peter279k

It might be a little late. This usually happens if the gd is configured without jpeg support. You can view the options here (https://www.php.net/manual/en/image.installation.php). For example, in a docker you need to execute docker-php-ext-configure gd --with-jpeg.

FuTuL avatar Aug 10 '21 07:08 FuTuL

Try to use \imagecreatefromjpeg from global PHP namespace - outputs error "attempted to call function imagecreatefromjpeg from global namespace".

In my case the problem was solved in docker PHP 7.4-fpm by adding line before install: docker-php-ext-configure gd --with-jpeg &&
docker-php-ext-install gd \

Sergeyii avatar Aug 10 '21 07:08 Sergeyii

I use Docker image php:8.0-fpm

To solve the problem, I used the following instructions in the dockerfile for JPEG and WebP images:

RUN apt-get update --allow-releaseinfo-change && apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev
RUN docker-php-ext-configure gd --with-jpeg --with-webp && docker-php-ext-install gd

romanzaycev avatar Jan 27 '22 18:01 romanzaycev