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

Errors when image field is not correctly formatted or empty #7

Open
Alwyn-RM opened this issue Mar 2, 2021 · 1 comment
Open

Errors when image field is not correctly formatted or empty #7

Alwyn-RM opened this issue Mar 2, 2021 · 1 comment

Comments

@Alwyn-RM
Copy link
Contributor

Alwyn-RM commented Mar 2, 2021

I installed the plugin into an existing project which already has some images set in the tables.
When I call
$image->thumbnail('image','small')
it throws an error ErrorException Undefined offset: 1 on line 197 of drh2so4\thumbnail\src\Traits\Thumbnail.php

this is to be expected of course because there's no check after the explode on "-" character if the length is actually higher than 1. So calling [1] on the split will fail.

I tried to prevent the error by using hasThumbnail but this is using the exact same function so not resolved.
When I clear the image column for that particular row, it also doesn't work when calling "hasThumbnail".

Again because there's no check if result of this search is null

Code:

public function hasThumbnail($fieldname = 'image', $size = null)
{
    return $this->imageDetail($fieldname, $size)->property->has_thumbnail;
}

I can get around it for now by checking the column value on the model.
Maybe if I have time I'll see if I can push a fix but not a lot of time at the moment.

UPDATE
Apparently the issue is because some file in my uploads didn;t follow the correct naming (older upload before adding the library). Still consider this a bug. Also wonder how performant this is but that's another discussion :-)

It's fixed when you add the following to drh2so4\thumbnail\src\Traits\Thumbnail.php (line 197)

if (!isset($image_partition[1])) {
 continue;
};
@Alwyn-RM Alwyn-RM changed the title No checks for errors Errors when image field is not correctly formatted or empty Mar 2, 2021
@pratiksh404
Copy link
Owner

I installed the plugin into an existing project which already has some images set in the tables.
When I call
$image->thumbnail('image','small')
it throws an error ErrorException Undefined offset: 1 on line 197 of drh2so4\thumbnail\src\Traits\Thumbnail.php

this is to be expected of course because there's no check after the explode on "-" character if the length is actually higher than 1. So calling [1] on the split will fail.

I tried to prevent the error by using hasThumbnail but this is using the exact same function so not resolved.
When I clear the image column for that particular row, it also doesn't work when calling "hasThumbnail".

Again because there's no check if result of this search is null

Code:

public function hasThumbnail($fieldname = 'image', $size = null)
{
    return $this->imageDetail($fieldname, $size)->property->has_thumbnail;
}

I can get around it for now by checking the column value on the model.
Maybe if I have time I'll see if I can push a fix but not a lot of time at the moment.

UPDATE
Apparently the issue is because some file in my uploads didn;t follow the correct naming (older upload before adding the library). Still consider this a bug. Also wonder how performant this is but that's another discussion :-)

It's fixed when you add the following to drh2so4\thumbnail\src\Traits\Thumbnail.php (line 197)

if (!isset($image_partition[1])) {
 continue;
};

thank you for the inspection .... your PR will be appriciated ..

Alwyn-RM added a commit to Alwyn-RM/laravel-thumbnails that referenced this issue Mar 30, 2021
Added check to see if image name is formatted correctly. Otherwise it'll skip this asset.
pratiksh404 added a commit that referenced this issue Nov 2, 2021
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

2 participants