Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PetroGromovo's avatar

Why I got error with image/intervention after I moved laravel site under docker?

I moved laravel site under docker(based on php:8.1.6-apache) under my local ubuntu 20 and I use medialibrary and intervention for images controlling, but I got unexpected error :

Unable to init from given url

on line of code where I try to get properties of an image :

$currencyMedia = $this->getFirstMedia(config('app.media_app_name'));

if ( ! empty($currencyMedia) and File::exists($currencyMedia->getPath())) {
    $currencyImage['url']        = $currencyMedia->getUrl();
    $imageInstance              = Image::load($currencyMedia->getUrl());
    \Log::info( ' $imageInstance::');
    \Log::info( print_r($imageInstance, true) ); // I check what is in $imageInstance

    $currencyImage['width']      = $imageInstance->getWidth(); // I got error on this line
    $currencyImage['height']     = $imageInstance->getHeight();

In log file I see :

 local.INFO:  $imageInstance::
 local.INFO: Spatie\Image\Image Object
(
    [manipulations:protected] => Spatie\Image\Manipulations Object
        (
            [manipulationSequence:protected] => Spatie\Image\ManipulationSequence Object
                (
                    [groups:protected] => Array
                        (
                            [0] => Array
                                (
                                )

                        )

                )

        )

    [imageDriver:protected] => gd
    [temporaryDirectory:protected] =>
    [optimizerChain:protected] =>
    [pathToImage:protected] => http://127.0.0.1:8088/storage/currency_app/31/brazilian_cruzeiro.png
)

In browser I can open valid image in browser by copypasting. Full error log :

[2022-10-18 15:58:31] local.ERROR: Unable to init from given url (http://127.0.0.1:8088/storage/currency_app/31/brazilian_cruzeiro.png). {"userId":1,"exception":"[object] (Intervention\Image\Exception\NotReadableException(code: 0): Unable to init from given url (http://127.0.0.1:8088/storage/currency_app/31/brazilian_cruzeiro.png). at /ProjectPath/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:85)
[stacktrace]
#0 /ProjectPath/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php(335): Intervention\Image\AbstractDecoder->initFromUrl('http://127.0.0....')
#1 /ProjectPath/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php(66): Intervention\Image\AbstractDecoder->init('http://127.0.0....')
#2 /ProjectPath/vendor/intervention/image/src/Intervention/Image/ImageManager.php(54): Intervention\Image\AbstractDriver->init('http://127.0.0....')
#3 /ProjectPath/vendor/intervention/image/src/Intervention/Image/ImageManagerStatic.php(58): Intervention\Image\ImageManager->make('http://127.0.0....')
#4 /ProjectPath/vendor/spatie/image/src/Image.php(93): Intervention\Image\ImageManagerStatic::make('http://127.0.0....')
#5 /ProjectPath/app/Http/Resources/CurrencyResource.php(45): Spatie\Image\Image->getWidth()
#6 /ProjectPath/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php(60): App\Http\Resources\CurrencyResource->toArray(Object(Illuminate\Http\Request))
#7 [internal function]: Illuminate\Support\HigherOrderCollectionProxy->Illuminate\Support\{closure}(Object(App\Http\Resources\CurrencyResource), 1)

Also I run

php artisan storage:link

under docker box.

Why this error and how it can be fixed? When the app was hosted under hosting ubuntu 20 it worked ok...

"laravel/framework": "^v9.6.0",
"spatie/laravel-medialibrary": "^10.0.0",
"intervention/image": "^2.7",

Also, I have both imagick and gd installed and enabled. My Dockerfile.yml :

  FROM php:8.1.6-apache
    RUN apt-get update && \
    apt-get install --assume-yes --no-install-recommends --quiet \
    python \
    libfreetype6-dev \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libzip-dev \
    nano \
    mc \
    git-core \
    libmagickwand-dev \
    curl \
    build-essential \
    libnotify-bin \
    openssl \
    libssl-dev \
    libgmp-dev \
    libldap2-dev \
    netcat \
    locate \
    && git clone https://github.com/nodejs/node.git && \
    cd node  \
    && git checkout v14.18.0 \
    && ./configure \
    && make \
    && make install

  RUN pecl install imagick \
    && docker-php-ext-enable imagick

    RUN npm install cross-env

    RUN npm install -g yarn

    RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp  --with-jpeg

     RUN docker-php-ext-install gd


    RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

    RUN  docker-php-ext-install pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif  \
    && a2enmod rewrite

    RUN apt-get install -y grep mlocate

    COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

Also looking in output of php info :

imagick
imagick module	enabled
imagick module version	3.7.0
imagick classes	Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version	ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org
Imagick using ImageMagick library version	ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org
ImageMagick copyright	(C) 1999-2021 ImageMagick Studio LLC
ImageMagick release date	2021-01-25
ImageMagick number of supported formats:	247
ImageMagick supported formats	3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, AVI, AVIF, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HEIC, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIDEO, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV

and :

gd
GD Support	enabled
GD Version	bundled (2.1.0 compatible)

Thanks in advance!

0 likes
3 replies
PetroGromovo's avatar

Yes, in output of phpinfo I see :

Core

PHP Version	8.1.8
Directive	Local Value	Master Value
allow_url_fopen	On	On
allow_url_include	Off	Off
arg_separator.input	&	&
Snapey's avatar

why not load from path rather than from url?

Please or to participate in this conversation.