Cannot make Gregwar/Image working in laravel
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
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')
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
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.
