Intervention\Image\Gd\imagecreatefromjpeg() 函数未定义 - Laravel。

15
我遇到了这个错误信息:

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

这是我的PHP信息:

http://behika.com/

我正在使用Laravel框架(版本5.6)和PHP 7.1。

我想要上传一张图片,但是出现了这个错误。

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 

我的存储函数:

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);
}

我们能看到你的代码吗? - delboy1978uk
更新了我的代码。 - S.M_Emamian
$time = time();否则每次调用time(),时间都可能会改变! - delboy1978uk
1个回答

39

我也遇到了同样的问题。经过几个小时的追踪,我终于找到了原因,因为Image Intervention代码使用了

$core = @imagecreatefromjpeg($path);

因此,错误被抑制了。Apache返回500响应,但没有任何关于原因的消息,没有日志,什么都没有。非常令人沮丧!

你上面包含的GD支持输出中提示了端倪,其中不列出JPG。我的情况类似——JPEG被列出,但未显示为已启用:

// 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] => 
)

我在Docker容器中运行PHP/Apache,对我来说解决方案是在我的Dockerfile中添加JPG支持,如文档中的'PHP Core Extensions'章节所述

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

现在GD支持JPG格式:

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] => 
)

图像干预{{终于}}有效了!


这里不太清楚。你在Dockerfile中添加jpg支持时做了什么? - KinsDotNet
@KinsDotNet 我已经更新了我的答案,它只是从我链接的文档部分复制粘贴而来。 - Don't Panic
@KinsDotNet 这有帮助吗? - Don't Panic
做到了。谢谢。 - KinsDotNet
1
刚按照他的回答更新了我的Dockerfile,现在可以正常工作了。https://github.com/ssi-anik/docker-builds/commit/bbab30e31ae1453a2832bd4773d99dd2d70cd4b2 - ssi-anik
解决方案可行,已更新Docker文件,进行了下/上(不仅仅是重启)操作,并添加了JPEG支持。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接