Announcement

#1 2021-05-15 22:07:42

macgherl63
Member
2021-05-15
2

Problem with i.php and Imagick php extension

Hello everyone,
I am having a weird problem when uploading or adding images thumbnails. I am using ImageMagick php extension, not gd, not ext_imagick.
Here is what is shown in my nginx log file.

Code:

2021/05/15 01:37:05 [error] 28256#0: *11682718 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ImagickException: unable to open image '././upload/2021/05/15/20210515013203-78bfd290.jpg': No such file or directory @ error/blob.c/OpenBlob/3537 in /usr/apache/phprun/fotoclasse/admin/include/image.class.php:400
Stack trace:
#0 /usr/apache/phprun/fotoclasse/admin/include/image.class.php(400): Imagick->__construct()
#1 /usr/apache/phprun/fotoclasse/admin/include/image.class.php(72): image_imagick->__construct()
#2 /usr/apache/phprun/fotoclasse/i.php(511): pwg_image->__construct()
#3 {main}
  thrown in /usr/apache/phprun/fotoclasse/admin/include/image.class.php on line 400" while reading response header from upstream, client: 0.0.0.0, server: xxx.xxx.edu.it, request: "GET /i.php?/upload/2021/05/15/20210515013203-78bfd290-sq.jpg HTTP/2.0", upstream: "fastcgi://unix:/run/www.sock:", host: "xxx.xxx.edu.it", referrer: "https://xxx.xxx.edu.it/admin.php?page=photos_add"

The error is coming from Imagick. The extension is unable to find the file in the upload directory. The file is there, and permissions are correct.
So I modified the definition of PHPWG_ROOT_PATH in i.php from:

Code:

define('PHPWG_ROOT_PATH', './');

to the root dir of my piwigo installation:

Code:

define('PHPWG_ROOT_PATH', '/usr/apache/phprun/fotoclasse/');

, and the php extension has been working perfectly ever since.

I can't say whether this is an actual mangle in my configuration or a bug in piwigo code.
I'd really appreciate someone helping me find out the cause of this behaviour. I know that php 7.4 is not supported yet by piwigo, but I don't think that's really the problem.
Do I need maybe a more precise configuration in my nginx? Why isn't the correct file path passed to the Imagick class?
Thanks everybody in advance for some reply.
MG

Here is my system:

Piwigo 11.5.0
Operating system: Linux
PHP: 7.4.15 (Show info) [2021-05-15 19:55:01]
MySQL: 8.0.23 [2021-05-15 21:55:01]
Graphics Library: ImageMagick 7.0.11-12

Offline

 

#2 2021-05-15 22:21:20

Zentalquabula
Member
2014-05-10
217

Re: Problem with i.php and Imagick php extension

Well, '././upload/2021/05/15/20210515013203-78bfd290.jpg' goes to /admin/include, so no wonder.

What you would want is '../../upload/2021/05/15/20210515013203-78bfd290.jpg'

I have no clue to why Piwigo uses relative paths, but I don't think that is where the problem lies, though.

Offline

 

#3 2021-05-16 02:02:45

erAck
Only trying to help
2015-09-06
1998

Re: Problem with i.php and Imagick php extension

Using relative paths has the advantage that you can move the tree around without having to change a single bit in the source code or configuration. And it works. (except here in this case..?)

I doubt that admin/include/ would be the current working directory, unless PHP Imagick does some odd things to change it; just having admin/include/image.class.php included in i.php does not change CWD. Hence ../../upload/... looks even more wrong to me than having to specify an absolute path as PHPWG_ROOT_PATH.

However, /usr/apache/phprun/fotoclasse/ (or anything under /usr/... for that matter, are you sure you actually *want* that?) is an odd location for a web server's document root. That might be related and something's missing in Apache configuration to cope with it so Imagick sees a different working directory. It may also be that FastCGI sets a completely different CWD, e.g. some executable's directory. To figure out, if you can, you might want to sprinkle some log output with CWD at strategic places where Imagick is actually created and called (with an instance of pwg_image) for an uploaded image to rule out it's somehow Piwigo related.


Running Piwigo at https://erack.net/gallery/

Offline

 

#4 2021-05-17 00:40:01

macgherl63
Member
2021-05-15
2

Re: Problem with i.php and Imagick php extension

Hi erAck,
thank you for your time.
Upon further investigation, I found out that ImageMagick php extension does not accept relative paths, because it considers its CWD the web server's core dir (in my case nginx, not apache, btw):
https://stackoverflow.com/questions/995 … hs-windows
The post refers to a window installation, but the extension exhibits just the same behaviour in Linux as well (at least in my case).
Besides I also found an old post in this forum where some user suggests a modification of image.class.php:
https://piwigo.org/forum/viewtopic.php?id=22796
just for the same reason.
Finally, I discovered this issue on github:
[Github] Piwigo issue #268
which is basically still open, although it goes back to 2015.
My linux distribution is Slackware, whilst @league was reporting NixOS as having the same behavior as Windows installations.
I posted a comment in issue #268, proposing my fix (?):

Code:

define('PHPWG_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . './');

I don't know however if the above breaks things for users having ext_imagick enabled in their configurations.

MacGherl

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact