Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot make Gregwar/Image working in laravel #165

Open
yelnyafacee opened this issue Aug 14, 2019 · 3 comments
Open

Cannot make Gregwar/Image working in laravel #165

yelnyafacee opened this issue Aug 14, 2019 · 3 comments

Comments

@yelnyafacee
Copy link

I installed the Gregwar/Image package ( https://github.com/Gregwar/Image ) to laravel, I changed the caching directory to $cacheDir = '/public/cache/images/';, I can generate cached image in php artisan tinker, but when I use it in blade template or controller I get the http://localhost/testsite/public/cache/images//f/a/l/l/b/fallback.jpg error url instead, I have narrowed down the problem to: Gregwar\Image\Adapter\GD and this function:

    protected function openJpeg($file)
    {
        if (file_exists($file) && filesize($file)) {
            $this->resource = @imagecreatefromjpeg($file);
        } else {
            $this->resource = false;
        }
    }

code used in blade:

<div class="faceted_objects thumbnail_container" data-url="/pictures/album/test_324716/sorted/new/page/1/">

    <?php

    use Gregwar\Image\Image;

    echo Image::open('public/storage/uploads/images/picture/1/bacon-broccoli-egg-bites21.jpg', 'transparent', 'center', 'center')
        ->zoomCrop(100, 100)
        ->jpeg();

    ?>

    {{--{{ gregwar_image( 100, 100, 'zoomCrop', 'picture/1/bacon-broccoli-egg-bites21.jpg' ) }}--}}

    {!! $image->getOtherImages() !!}

</div>

the code inside if (file_exists($file) && filesize($file)) { never runs and filesize() returns NOTHING using print_r or dd(), I have no idea how to fix this, the weird thing is it works in php artisan tinker but NOT on the actual site

works in php artisan tinker so why does not work in blade template?

@garygreen
Copy link
Contributor

If you get the fallback it's cos gregwar can't find the file.

You should try to use absolute paths always. The Laravel public_path() helper may help you here, or base_path(), depending on where your images are on your server.

public_path('picture/1/bacon-broccoli-egg-bites21.jpg')

@hebertlima
Copy link

same error, but actually work with .png but not work with .jpg

// wBEyifMlUNkqnRGxaPpqUU1RHpgVro1hD1aPzBEu.png #work
// wBEyifMlUNkqnRGxaPpqUU1RHpgVro1hD1aPzBEu.jpg #not work

$image = 'wBEyifMlUNkqnRGxaPpqUU1RHpgVro1hD1aPzBEu.jpg';

// filesystem.php
['articles' => [
     'driver' => 'local',
     'root' => storage_path('app/public/articles')
]];

#full path 
var_dump( \Storage::disk('articles')->path($image) );
# /workspace/storage/app/public/articles/wBEyifMlUNkqnRGxaPpqUU1RHpgVro1hD1aPzBEu.jpg'

\Image::open( \Storage::disk('articles')->path($image) )->zoomCrop(130,75)->guess();
// cache/images/f/a/l/l/b/fallback.jpg

@Nimdoc
Copy link

Nimdoc commented Jun 11, 2023

You will also get the fallback image if the jpeg is unable to be opened but still exists. If you comment out the try/catch statement here, you will see what error is causing the package to be unable to open jpegs. In my case, I did not have gd properly installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants