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

标签 php laravel

我收到此错误消息:

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

最佳答案

我有同样的问题。我花了几个小时的跟踪才到这里,因为 the Image Intervention code uses :

$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 支持,如 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

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

图像干预终于奏效了!

关于php - 调用未定义的函数 Intervention\\Image\\Gd\\imagecreatefromjpeg() - laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421952/

相关文章:

javascript - Laravel 5 如何让 Controller 显示简单的消息框或警报?

php - 将多个值作为数组插入到一列中

php - 计算数据库中的行数

laravel - 如何使用 Laravel API 资源对加载的关系进行分页

php - SimpleXML 使用 xpath 获取元素内容

bash - 使用 git hooks + laravel artisan 命令创建简单的自动部署

PHP:json_encode() 不显示多维数组的任何内容

PHP 输入值传递给循环

php - 使用php在一页上处理多个表单

PHP fatal error : Allowed memory size of 1073741824 bytes exhausted (tried to allocate 16777216 bytes)