Image: Unable to init from given binary data.

Created on 15 Apr 2018  路  5Comments  路  Source: Intervention/image

Not sure what the issue is but ive noticed a new site is throwing this error on image uploads.

running nginx/1.13.3, php fpm 7.2.3 and gd bundled (2.1.0 compatible)

running in a docker container if that matters

Most helpful comment

Maybe this problem ocurr because lib jpeg is not installed. I had the same problem and look for this message on source code and find it: https://github.com/Intervention/image/blob/3603dbcc9a17d307533473246a6c58c31cf17919/src/Intervention/Image/Gd/Decoder.php#L114.

Try to use imagecreatefromstring function and check if return the following error message:

ErrorException: imagecreatefromstring(): No JPEG support in this PHP build

In my opinion, would be better if Intervention\Image\Image\Decoder::initFromBinary could check if libraries are instelled and return a more consistently error message.

I was using the following Dockerfile:

FROM php:7.2-fpm-alpine

RUN apk add --update \
        freetype \
    freetype-dev \
    libpng \
    libpng-dev \
    libjpeg-turbo \
    libjpeg-turbo-dev \
        libjpeg \
    libtool \
    libxml2-dev \
    make \
    g++ \
    autoconf \
    imagemagick-dev \
    libtool \
    && docker-php-ext-install gd \
    && docker-php-ext-configure gd \
        --with-gd \
        --with-freetype-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install mbstring \
    && docker-php-ext-install mysqli \
    && pecl install imagick \
    && docker-php-ext-enable imagick \
    && apk del autoconf g++ libtool make \
    && rm -rf /tmp/* /var/cache/apk/*

But instructions to install gd should be after to configure instruction. I just change the position of these lines and it works for me, but I spend some minutes to discovery that wasnt my encoded data.

All 5 comments

Maybe this problem ocurr because lib jpeg is not installed. I had the same problem and look for this message on source code and find it: https://github.com/Intervention/image/blob/3603dbcc9a17d307533473246a6c58c31cf17919/src/Intervention/Image/Gd/Decoder.php#L114.

Try to use imagecreatefromstring function and check if return the following error message:

ErrorException: imagecreatefromstring(): No JPEG support in this PHP build

In my opinion, would be better if Intervention\Image\Image\Decoder::initFromBinary could check if libraries are instelled and return a more consistently error message.

I was using the following Dockerfile:

FROM php:7.2-fpm-alpine

RUN apk add --update \
        freetype \
    freetype-dev \
    libpng \
    libpng-dev \
    libjpeg-turbo \
    libjpeg-turbo-dev \
        libjpeg \
    libtool \
    libxml2-dev \
    make \
    g++ \
    autoconf \
    imagemagick-dev \
    libtool \
    && docker-php-ext-install gd \
    && docker-php-ext-configure gd \
        --with-gd \
        --with-freetype-dir=/usr/include/ \
        --with-png-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install mbstring \
    && docker-php-ext-install mysqli \
    && pecl install imagick \
    && docker-php-ext-enable imagick \
    && apk del autoconf g++ libtool make \
    && rm -rf /tmp/* /var/cache/apk/*

But instructions to install gd should be after to configure instruction. I just change the position of these lines and it works for me, but I spend some minutes to discovery that wasnt my encoded data.

@ricardotulio I am also facing the same issue.

@ricardotulio Tambem aqui :P

[UPDATE]: Just got it solved by adding JPEG support to my PHP-FPM installation 馃憤 馃嵕

I am also facing this.

I am uploading images as DataUrl base64 encoded and most images work fine but when I imported images from my iPhone to my MacbookPro and chose an image made with iPhone it generates this error.

The strange thing is that I am able to encode and decode the same image using codebeautify.org and when I convert the image to base64 the site gives me the same result which I am trying to use to make an image using Image::make() - I hope you understand

I am using Laradock as my local env with PHP71, GD and ImageMagic enabled as well as php exif extension.

Same issue here..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cherrycoding picture cherrycoding  路  3Comments

ludo237 picture ludo237  路  8Comments

dragonfire1119 picture dragonfire1119  路  4Comments

p4bloch picture p4bloch  路  6Comments

samwalshnz picture samwalshnz  路  8Comments