Intervention error: Unable to init from given binary data. #2244

Closed
opened 2026-02-05 03:26:50 +03:00 by OVERLORD · 8 comments
Owner

Originally created by @TheMightyOnyx on GitHub (May 12, 2021).

https://flareapp.io/share/67O6nykP

Describe the bug
Error while changing book cover image.

Steps To Reproduce
Change book cover image.

Configuration:

  • Exact BookStack Version: v21.04.4
  • PHP Version: PHP 7.4.19 (php:7.4.19-fpm-alpine3.13)
  • Hosting Method: Docker

Additional context
Uploading images to pages doesn't work either, the image itself is uploaded and copied to the storage directory correctly, but no thumbs or scaled directories are created. I checked the permissions and everything and it seems fine, I even chmoded the dir to 777 and it still doesn't work. Considering the image is copied but no thumbs are created I imagine the error happens at some point during the thumbnail creation. I imagine there's some php module missing or something misconfigured, but I followed the list of requirements on docs/installation page and it seems all fine. I checked if all modules are enabled and it seems to be the case.

I enabled debugging and linked the stack trace above.

Originally created by @TheMightyOnyx on GitHub (May 12, 2021). https://flareapp.io/share/67O6nykP **Describe the bug** Error while changing book cover image. **Steps To Reproduce** Change book cover image. **Configuration:** - Exact BookStack Version: v21.04.4 - PHP Version: PHP 7.4.19 (php:7.4.19-fpm-alpine3.13) - Hosting Method: Docker **Additional context** Uploading images to pages doesn't work either, the image itself is uploaded and copied to the storage directory correctly, but no thumbs or scaled directories are created. I checked the permissions and everything and it seems fine, I even chmoded the dir to 777 and it still doesn't work. Considering the image is copied but no thumbs are created I imagine the error happens at some point during the thumbnail creation. I imagine there's some php module missing or something misconfigured, but I followed the list of requirements on docs/installation page and it seems all fine. I checked if all modules are enabled and it seems to be the case. I enabled debugging and linked the stack trace above.
Author
Owner

@ssddanbrown commented on GitHub (May 13, 2021):

Hi @TheMightyOnyx,
Are you using a common docker image at all? Or are you able to share the scripts/Dockerfile to build your docker image at all? This kind of error can some down to the exact version/build of the GD php extension.

@ssddanbrown commented on GitHub (May 13, 2021): Hi @TheMightyOnyx, Are you using a common docker image at all? Or are you able to share the scripts/Dockerfile to build your docker image at all? This kind of error can some down to the exact version/build of the GD php extension.
Author
Owner

@TheMightyOnyx commented on GitHub (May 13, 2021):

This is the php part that installs the modules and composer etc. It's based on FROM php:7.4.19-fpm-alpine3.13. If this is not enough and you need to test it yourself I can grant you access to the repository, it's on Gitlab though, so I would need your Gitlab username.

....
ARG PROJECT_VERSION=21.04.4
ARG PROJECT=https://github.com/bookstackapp/bookstack/archive/v${PROJECT_VERSION}.tar.gz
....
RUN \
# install dependencies
apk add --no-cache gettext libpng-dev oniguruma-dev libxml2-dev wget && \
# create project directory and download the project files, su into user otherwise umask is ignored
mkdir -p /usr/share/project && \
chown ariamis:ariamis /usr/share/project && \
wget -qO- "${PROJECT}" | su ariamis -s /bin/sh -c "tar -xzf - -C /usr/share/project --strip-components=1" && \
# install php extensions
docker-php-ext-install pdo_mysql mbstring tokenizer gd simplexml dom && \
# remove uneccesary data
apk del libpng-dev oniguruma-dev libxml2-dev wget && \
apk add --no-cache libpng oniguruma libxml2 && \
# copy php configuration
mv $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini && \
# install composer
cd /tmp && \
curl -sS https://getcomposer.org/installer | php && \
mv /tmp/composer.phar /usr/local/bin/composer && \
# install composer dependencies
s6-setuidgid ariamis composer install -d /usr/share/project/ --no-dev && \
# remove uneccesary data
rm -rf /root/.composer /tmp/*

Thanks for looking into this.

@TheMightyOnyx commented on GitHub (May 13, 2021): This is the php part that installs the modules and composer etc. It's based on `FROM php:7.4.19-fpm-alpine3.13`. If this is not enough and you need to test it yourself I can grant you access to the repository, it's on Gitlab though, so I would need your Gitlab username. ``` .... ARG PROJECT_VERSION=21.04.4 ARG PROJECT=https://github.com/bookstackapp/bookstack/archive/v${PROJECT_VERSION}.tar.gz .... RUN \ # install dependencies apk add --no-cache gettext libpng-dev oniguruma-dev libxml2-dev wget && \ # create project directory and download the project files, su into user otherwise umask is ignored mkdir -p /usr/share/project && \ chown ariamis:ariamis /usr/share/project && \ wget -qO- "${PROJECT}" | su ariamis -s /bin/sh -c "tar -xzf - -C /usr/share/project --strip-components=1" && \ # install php extensions docker-php-ext-install pdo_mysql mbstring tokenizer gd simplexml dom && \ # remove uneccesary data apk del libpng-dev oniguruma-dev libxml2-dev wget && \ apk add --no-cache libpng oniguruma libxml2 && \ # copy php configuration mv $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini && \ # install composer cd /tmp && \ curl -sS https://getcomposer.org/installer | php && \ mv /tmp/composer.phar /usr/local/bin/composer && \ # install composer dependencies s6-setuidgid ariamis composer install -d /usr/share/project/ --no-dev && \ # remove uneccesary data rm -rf /root/.composer /tmp/* ``` Thanks for looking into this.
Author
Owner

@ssddanbrown commented on GitHub (May 15, 2021):

Hi @TheMightyOnyx,
I suspect you either need to configure gd with jpeg support and/or you need to not remove the libraries required by gd (So try not deleting the various *-dev packages required used by PHP extensions).

I tested things with the below basic Dockerfile and exporting a page containing a PNG and JPG image seemed to work.

FROM php:7.4.19-fpm-alpine3.13

RUN apk add libpng-dev libjpeg-turbo-dev zlib-dev oniguruma-dev libxml2-dev
RUN docker-php-ext-configure gd --with-jpeg
RUN docker-php-ext-install -j$(nproc) pdo_mysql gd
@ssddanbrown commented on GitHub (May 15, 2021): Hi @TheMightyOnyx, I suspect you either need to configure gd with jpeg support and/or you need to not remove the libraries required by gd (So try not deleting the various `*-dev` packages required used by PHP extensions). I tested things with the below basic Dockerfile and exporting a page containing a PNG and JPG image seemed to work. ```dockerfile FROM php:7.4.19-fpm-alpine3.13 RUN apk add libpng-dev libjpeg-turbo-dev zlib-dev oniguruma-dev libxml2-dev RUN docker-php-ext-configure gd --with-jpeg RUN docker-php-ext-install -j$(nproc) pdo_mysql gd ```
Author
Owner

@TheMightyOnyx commented on GitHub (May 16, 2021):

Thanks a lot, looks like installing gd with jpeg support fixed it. I'm installing dev versions of those packages, removing them and then installing non dev versions to save some space. Probably not worth the hassle, but it doesn't appear to be causing any issues.

I went ahead and made a pull request https://github.com/BookStackApp/website/pull/96 that adds "(with jpeg)" to gd, just in case anyone else runs into this.

Thank you for your help.

@TheMightyOnyx commented on GitHub (May 16, 2021): Thanks a lot, looks like installing gd with jpeg support fixed it. I'm installing dev versions of those packages, removing them and then installing non dev versions to save some space. Probably not worth the hassle, but it doesn't appear to be causing any issues. I went ahead and made a pull request https://github.com/BookStackApp/website/pull/96 that adds "(with jpeg)" to gd, just in case anyone else runs into this. Thank you for your help.
Author
Owner

@ssddanbrown commented on GitHub (May 17, 2021):

@TheMightyOnyx Happy to hear you got things working. Will therefore close this off.

@ssddanbrown commented on GitHub (May 17, 2021): @TheMightyOnyx Happy to hear you got things working. Will therefore close this off.
Author
Owner

@Scemist commented on GitHub (Aug 3, 2023):

I'm also with this issue, I'm surprise there is no more issues related opened, I tried in many environments, although always in Docker with Ubuntu.

The error throws every time I try to upload a JPG/JPEG file, PNG works fine.

Intervention\Image\Exception\NotReadableException

Unable to init from given binary data.

As example to reproduce it, you can just use the dev Dockerfile and try to upload a jpg file;

https://github.com/BookStackApp/BookStack/blob/development/dev/docker/Dockerfile

Is there some dependence missing in this Dockerfile?

@Scemist commented on GitHub (Aug 3, 2023): I'm also with this issue, I'm surprise there is no more issues related opened, I tried in many environments, although always in Docker with Ubuntu. ## The error throws every time I try to upload a JPG/JPEG file, PNG works fine. ``` Intervention\Image\Exception\NotReadableException Unable to init from given binary data. ``` As example to reproduce it, you can just use the dev Dockerfile and try to upload a jpg file; https://github.com/BookStackApp/BookStack/blob/development/dev/docker/Dockerfile Is there some dependence missing in this Dockerfile?
Author
Owner

@ssddanbrown commented on GitHub (Aug 3, 2023):

Is there some dependence missing in this Dockerfile?

There could possibly be, I have not tested the dev docker environment in a while.
Either way, the dev docker setup in this repo is not for production at all, please don't use this for an actual BookStack instance unless you are intending to only develop.

@ssddanbrown commented on GitHub (Aug 3, 2023): > Is there some dependence missing in this Dockerfile? There could possibly be, I have not tested the dev docker environment in a while. Either way, the dev docker setup in this repo is not for production at all, please don't use this for an actual BookStack instance unless you are intending to only develop.
Author
Owner

@Scemist commented on GitHub (Aug 3, 2023):

Sure, actually we are developing a custom Docker setup over this official repo, just like the other community versions. We used this file to find out any missing dependencies.

I already fix it, really just missing dependencies, I sent a Pull Request #4422 , cause is just a few lines of code, but not easy to find out the solution.

@Scemist commented on GitHub (Aug 3, 2023): Sure, actually we are developing a custom Docker setup over this official repo, just like the other community versions. We used this file to find out any missing dependencies. I already fix it, really just missing dependencies, I sent a Pull Request #4422 , cause is just a few lines of code, but not easy to find out the solution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2244