image icon indicating copy to clipboard operation
image copied to clipboard

Unable to init from given binary data.

Open REPTILEHAUS opened this issue 6 years ago • 6 comments

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

REPTILEHAUS avatar Apr 15 '18 14:04 REPTILEHAUS

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 avatar May 21 '18 15:05 ricardotulio

@ricardotulio I am also facing the same issue.

vinayak25 avatar Aug 20 '18 13:08 vinayak25

@ricardotulio Tambem aqui :P

panickz avatar Oct 15 '18 11:10 panickz

[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.

adriandrozdz avatar Dec 27 '18 11:12 adriandrozdz

Same issue here..

tsangaris avatar Jan 10 '19 11:01 tsangaris

I'm running PHP-FPM version 7.4 in Docker. We were too facing this issue, in 2021, and @ricardotulio led me the right way.

However, you'll get an error on 7.4 using his Dockerfile, because they changed the argument naming.

RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install gd

PNG is baked in by default. No need to specify paths manually anymore either.

HSPDev avatar Mar 26 '21 12:03 HSPDev

Here is a working example with support for all image formats from the development environment:

https://github.com/Intervention/image/blob/71bb0e3449bbbfdf47a0d0f2860af7e5e90428e6/Dockerfile#L3-L32

olivervogel avatar Jan 07 '24 11:01 olivervogel