[web API] pwg.categories.getImages returns <NULL> if getimagesize() fails #1037

Closed
opened 2026-10-05 00:29:13 +02:00 by adam · 4 comments
Owner

The API method pwg.categories.getImages calls the PHP method getimagesize() in …/include/derivative.inc.php on line 146:

if ( ($size = getimagesize( $this->get_path() )) !== false)
{
    $this->size = array($size[0],$size[1]);
     pwg_query('UPDATE '.IMAGES_TABLE.' SET width='.$size[0].', height='.$size[1].' WHERE id='.$this->id);
}

If getimagesize() encounters an error with an image, the API method pwg.categories.getImages does not return any data, preventing the third party app to retrieve the album image list.

What would be expected is that pwg.categories.getImages forgets the problematic image and returns the rest of the data.

The API method `pwg.categories.getImages` calls the PHP method [`getimagesize()`](https://www.php.net/manual/en/function.getimagesize.php) in …/include/derivative.inc.php on line 146: ``` if ( ($size = getimagesize( $this->get_path() )) !== false) { $this->size = array($size[0],$size[1]); pwg_query('UPDATE '.IMAGES_TABLE.' SET width='.$size[0].', height='.$size[1].' WHERE id='.$this->id); } ``` If `getimagesize()` encounters an error with an image, the API method `pwg.categories.getImages` does not return any data, preventing the third party app to retrieve the album image list. What would be expected is that `pwg.categories.getImages` forgets the problematic image and returns the rest of the data. <!-- github-sync-id:646959466 -->
adam closed this issue 2026-10-05 00:29:13 +02:00
Author
Owner

It happens if there are the corrupted photos or any video files.

It happens if there are the corrupted photos or any video files. <!-- github-comment-id:654825319 -->
Author
Owner

I encounter the same problem again and I realise that the API method pwg.categories.getImages returns no data after an unsuccessful JSON parsing. The server returns the following data when there is a corrupted image file image.jpg in the album:

<br />
<b>Warning</b>:  getimagesize(././upload/2020/08/19/image.jpg): failed to open stream: No such file or directory in <b>[hidden path]/htdocs/Piwigo/include/derivative.inc.php</b> on line <b>146</b><br />
{"stat":"ok","result":{"paging":{"page":0,"per_page":36,"count":32,"total_count":"32"},"images":[{"id":9651,"hit":0,"file":"IMG_1410.JPG",...

Can we prevent the server from returning the HTML code before the JSON data?

I encounter the same problem again and I realise that the API method `pwg.categories.getImages` returns no data **after an unsuccessful JSON parsing**. The server returns the following data when there is a corrupted image file `image.jpg` in the album: ``` <br /> <b>Warning</b>: getimagesize(././upload/2020/08/19/image.jpg): failed to open stream: No such file or directory in <b>[hidden path]/htdocs/Piwigo/include/derivative.inc.php</b> on line <b>146</b><br /> {"stat":"ok","result":{"paging":{"page":0,"per_page":36,"count":32,"total_count":"32"},"images":[{"id":9651,"hit":0,"file":"IMG_1410.JPG",... ``` Can we prevent the server from returning the HTML code before the JSON data? <!-- github-comment-id:676279855 -->
Author
Owner

Hello,

I still have no time to fix the error in PHP but it should be possible.
Getimage size returns an error if the file not exists or you don't have
permission on the file or the file is video. There are two solutions:

  1. Add try - catch statement to prevent this errors
  2. Or find PHP libraries which are capable to read the video files

But on both solutions you will probably prevent the HTMP/ PHP error but you
get the empty JSON response, which is not good. You should get me the JSON
template and I should find time to fix it :-).

Regards.
Jan
---------- Původní e-mail ----------
Od: Eddy Lelièvre-Berna notifications@github.com
Komu: Piwigo/Piwigo Piwigo@noreply.github.com
Datum: 19. 8. 2020 14:35:53
Předmět: Re: [Piwigo/Piwigo] [web API] pwg.categories.getImages returns <
NULL> if getimagesize() fails (#1198)
"

I encounter the same problem again and I realise that the API method pwg.
categories.getImages returns no data after JSON parsing. In fact here is the
beginning of the returned data:



Warning: getimagesize(././upload/2020/08/19/20200819062113-d51ffc4d.jpg): failed to open stream: No such file or directory in [hidden path]/htdocs/Piwigo/include/derivative.inc.php on line 146

{"stat":"ok","result":{"paging":{"page":0,"per_page":36,"count":32,"total_count":"32"},"images":[{"id":9651,"hit":0,"file":"IMG_1410.JPG",...

Can we prevent the server from returning the HTML code before the JSON data?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
(https://github.com/Piwigo/Piwigo/issues/1198#issuecomment-676279855), or
unsubscribe
(https://github.com/notifications/unsubscribe-auth/AB3XG7F34LVWVCUOYNP32KDSBPBKHANCNFSM4OKTICFA)
.
"

Hello, I still have no time to fix the error in PHP but it should be possible. Getimage size returns an error if the file not exists or you don't have permission on the file or the file is video. There are two solutions: 1. Add try - catch statement to prevent this errors 2. Or find PHP libraries which are capable to read the video files But on both solutions you will probably prevent the HTMP/ PHP error but you get the empty JSON response, which is not good. You should get me the JSON template and I should find time to fix it :-). Regards. Jan ---------- Původní e-mail ---------- Od: Eddy Lelièvre-Berna <notifications@github.com> Komu: Piwigo/Piwigo <Piwigo@noreply.github.com> Datum: 19. 8. 2020 14:35:53 Předmět: Re: [Piwigo/Piwigo] [web API] pwg.categories.getImages returns < NULL> if getimagesize() fails (#1198) " I encounter the same problem again and I realise that the API method pwg. categories.getImages returns no data after JSON parsing. In fact here is the beginning of the returned data: <code><br /> <b>Warning</b>: getimagesize(././upload/2020/08/19/20200819062113-d51ffc4d.jpg): failed to open stream: No such file or directory in <b>[hidden path]/htdocs/Piwigo/include/derivative.inc.php</b> on line <b>146</b><br /> {"stat":"ok","result":{"paging":{"page":0,"per_page":36,"count":32,"total_count":"32"},"images":[{"id":9651,"hit":0,"file":"IMG_1410.JPG",... </code> Can we prevent the server from returning the HTML code before the JSON data? — You are receiving this because you commented. Reply to this email directly, view it on GitHub (https://github.com/Piwigo/Piwigo/issues/1198#issuecomment-676279855), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AB3XG7F34LVWVCUOYNP32KDSBPBKHANCNFSM4OKTICFA) . " <!-- github-comment-id:676587580 -->
Author
Owner

I close this issue which is in fact a duplicate of #1566.

I close this issue which is in fact a duplicate of #1566. <!-- github-comment-id:989773640 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1037