Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function Intervention\\Image\\Gd\\imagecreatefromjpeg() - laravel

Tags:

php

laravel

I got this error message:

Call to undefined function Intervention\\Image\\Gd\\imagecreatefromjpeg()

this is my php info:

http://behika.com/

I'm using laravel framework (version 5.6) and php 7.1.

I want to upload a image but I got this error.

gd
GD Support  enabled
GD Version  bundled (2.1.0 compatible)
GIF Read Support    enabled
GIF Create Support  enabled
PNG Support enabled
libPNG Version  1.6.32
WBMP Support    enabled
XBM Support 

my store function:

public function store(CompanyRequest $request)
{
    $all = $request->except(['category-company', 'flag', 'null', 'file', 'producer-company','manager','address','description','phone']);
    $flag = array_values($request->input('flag'));
    $jsonFlag = json_encode($flag);
    $all['flag'] = $jsonFlag;

    if($request->input('manager')){
        $all['manager']=$request->input('manager');
    }
    if($request->input('address')){
        $all['address']=$request->input('address');
    }
    if($request->input('description')){
        $all['description']=$request->input('description');
    }
    if($request->input('phone')){
        $all['phone']=$request->input('phone');
    }
    $file = $request->file('file');
    $name = $file->getClientOriginalName();
    $dir = '/img/company/';
    $path = $dir . time() . $name;
    $thumbnail = $dir . 'tn-' . time() . $name;
    $all['path'] = $path;
    $all['thumbnail'] = $thumbnail;


    $company = Company::create($all);

    $file->move('img/company', time() . $name);

    $img = Image::make('img/company/' . time() . $name);
    $img->resize(100, 100);
    $img->save('img/company/tn-' . time() . $name);


    $company->categories()->sync($request->input('category-company'));
    $company->producers()->sync($request->input('producer-company'));

    return Response::json($company);
}
like image 888
S.M_Emamian Avatar asked Jul 19 '18 11:07

S.M_Emamian


1 Answers

I had the same problem. It took me some hours of tracing to get here, because the Image Intervention code uses:

$core = @imagecreatefromjpeg($path);

So errors are suppressed. Apache was throwing 500 responses but no messages about why, no logs, nothing. Very frustrating!

The clue is in the GD support output you included above, which does not list JPG. Mine was is similar - JPEG is listed but not shown as enabled:

// I'm using CLI here, use <?php print_r(gd_info()); ?> in an http php page
// to check your web server, CLI PHP config is different to web server config
php -r 'print_r(gd_info());'
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 
    [T1Lib Support] => 
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] =>         // <------ blank
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [WebP Support] => 
    [JIS-mapped Japanese Font Support] => 
)

I am running PHP/Apache in a Docker container, and the solution for me was to add JPG support in my Dockerfile, as described in the 'PHP Core Extensions' section of the docs:

RUN apt-get update && apt-get install -y \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

Now GD shows JPG support:

php -r 'print_r(gd_info());' 
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] => 
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1         // <------ hurray!
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [WebP Support] => 
    [JIS-mapped Japanese Font Support] => 
)

And Image Intervention finally works!

like image 143
Don't Panic Avatar answered Oct 20 '22 15:10

Don't Panic