Sizzling Code
Sizzling Code

Reputation: 6080

Glide library | image not loading up

I'm trying to enable this library for my localhost environment.

http://glide.thephpleague.com/1.0/config/integrations/laravel/

Current Laravel version 5.5

gd2 is enabled in wamp extensions.

I can't seem to find where the problem is.

Path is OK, image exists on it.

See following code for server config.

$server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => $source,
            //'cache' => new Filesystem(new Adapter('../storage/app/cache/')),
            'cache' => $cache,
            'cache_path_prefix' => '.cache',
            'base_url' => 'transform-img',
        ]);

Now I use this

return $server->getImageResponse($path, request()->all());

it does not give any error.

When I dd() this, I get this response.

StreamedResponse {#1151 ▼
  #callback: Closure {#1177 ▶}
  #streamed: false
  -headersSent: false
  +headers: ResponseHeaderBag {#1176 ▶}
  #content: null
  #version: "1.0"
  #statusCode: 200
  #statusText: "OK"
  #charset: null
}

Callback Closure:

#callback: Closure {#1252 ▼
    class: "League\Glide\Responses\SymfonyResponseFactory"
    this: LaravelResponseFactory {#1231 …}
    use: {▼
      $stream: stream resource @543 ▼
        timed_out: false
        blocked: true
        eof: false
        wrapper_type: "plainfile"
        stream_type: "STDIO"
        mode: "rb"
        unread_bytes: 0
        seekable: true
        uri: "D:\wamp\www\Bankrolla\storage\app/public\.cache/img/logo_no_text.png/32c8e67d979eab40a7ef6d1854f1f7cc"
        options: []
      }
    }
    file: "D:\wamp\www\Bankrolla\vendor\league\glide-symfony\src\Responses\SymfonyResponseFactory.php"
    line: "48 to 54"
  }

As statusCode shows 200 and there is no error for file not found, still it does not load any image but shows a placeholder on browser when I navigate.

What might be the issue? If I try to replace image name with any other random string I get error for image not found. so this means it does find the image. Though it fails to render the image.

I have googled, searched on their GitHub comments, could not find any problem similar as mine.

I only get a blank page/image if I load it directly.

enter image description here

Also I looked in to the cache directory, it includes the files and those files dimensions are resized. so I am not sure where it goes wrong even when it generates the cache files.

enter image description here

Maybe I am missing something here?

Update

Value of $source variable:

Filesystem {#1225 ▼
  #adapter: Local {#1226 ▼
    #pathSeparator: "\"
    #permissionMap: array:2 [▼
      "file" => array:2 [▼
        "public" => 420
        "private" => 384
      ]
      "dir" => array:2 [▼
        "public" => 493
        "private" => 448
      ]
    ]
    #writeFlags: 2
    -linkHandling: 2
    #pathPrefix: "D:\wamp\www\Bankrolla\storage\app/public\"
  }
  #plugins: []
  #config: Config {#1229 ▼
    #settings: []
    #fallback: null
  }
}

Storage Directory in my public directory (it's a symbolic link of original storage)

enter image description here

Storage Directory of Laravel

enter image description here

The URL I am calling this from.

{localhostDomainHere}/image/img/logo_no_text.png?w=100&h=100&fit=crop-center

Upvotes: 9

Views: 2874

Answers (2)

Joeri
Joeri

Reputation: 150

Don't know if you already fixed it. But we encountered the same problem a few days ago. After a long search, we found out that the error is caught by a new line in a config:

config file

So check all your config files for space or newline before openings tag. Otherwise, your response is not a valid response anymore and you will get the empty box.

If it is not a config file you need to check all the files that are loaded on the request.

Upvotes: 1

syam
syam

Reputation: 892

the path mentioned by $source => put images there. if it is 1.jpg, then call the url server_url/img/1.jpg . img is from your route for the function you posted in question. In my case $source as well as $cache was /storage/app and i put image in it and called the route on that image. Hope this helps you.

Check this

enter image description here This is my code :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;

class GlideController extends Controller
{
    public function show(Filesystem $filesystem, $path)
    {
        $server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => $filesystem->getDriver(),
            'cache' => $filesystem->getDriver(),
            'cache_path_prefix' => '.cache',
            'base_url' => 'img',
        ]);

        return $server->getImageResponse($path, request()->all());
    }
}

route :

Route::get('/img/{path}', 'GlideController@show')->where('path', '.*');

this is the content of my storage/app

enter image description here

Upvotes: 0

Related Questions