首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用未定义函数Intervention\\Image\\Gd\\imagecreatefromjpeg() - laravel

调用未定义函数Intervention\\Image\\Gd\\imagecreatefromjpeg() - laravel
EN

Stack Overflow用户
提问于 2018-07-19 11:49:32
回答 1查看 10.9K关注 0票数 14

我收到了一条错误消息:

代码语言:javascript
复制
Call to undefined function Intervention\\Image\\Gd\\imagecreatefromjpeg()

这是我的php信息:

http://behika.com/

我使用的是laravel框架(版本5.6)和php7.1。

我想上传一个图片,但我得到了这个错误。

代码语言:javascript
复制
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 

我的商店功能:

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2018-10-19 12:26:51

我也有同样的问题。我花了几个小时的时间追踪到这里,因为图像干预代码使用

代码语言:javascript
复制
$core = @imagecreatefromjpeg($path);

所以错误被抑制了。Apache抛出了500个响应,但是没有关于原因的消息,没有日志,什么也没有。非常令人沮丧!

线索是在上面包含的GD支持输出中,它没有列出JPG。我的是相似的- JPEG被列出,但未显示为已启用:

代码语言:javascript
复制
// 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核心扩展”部分

代码语言:javascript
复制
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的支持:

代码语言:javascript
复制
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] => 
)

图像干预终于见效了!

票数 37
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51421952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档