Imagick crash with "Uncaught exception 'ImagickException' with message 'UnableToOpenBlob `./_data/i/upload/2014/08/06/20140806153442-076e3cae-th.jpg': No such file or directory"
Steps to reproduce: Any action with imagick on windows.
Additional information: It can be fixed with realpath. There fix:
**Reported by hakastein on 7 Aug 2014 01:26**
**Version:** 2.6.2
Imagick crash with "Uncaught exception 'ImagickException' with message 'UnableToOpenBlob `./_data/i/upload/2014/08/06/20140806153442-076e3cae-th.jpg': No such file or directory"
**Steps to reproduce:** Any action with imagick on windows.
**Additional information:** It can be fixed with realpath. There fix:
file image.class.php
86: $class = 'image_'.$this->library;
87: $source_filepath = realpath($source_filepath);
88: $this->image = new $class($source_filepath);
and
496: file_put_contents($destination_filepath, '');
497: $destination_filepath = realpath($destination_filepath);
[Piwigo Bugtracker #3109](http://piwigo.org/bugs/view.php?id=3109)
<!-- github-sync-id:97226839 -->
So here's some more background. My Linux is NixOS (17.03.1623.138313fe01), which is admittedly a bit strange relative to other distributions, and often exposes upstream bugs/quirks having to do with paths. But otherwise I can't really explain why this appears to work in other Linuxes!
This behavior — that the ImageMagick PHP extension doesn't accept relative paths — is marked WONTFIX in their tracker: https://bugs.php.net/bug.php?id=61583
and moreover they note that realpath isn't always a reliable workaround. For source image files, ImageMagick accepts annotations for page numbers, frames, etc… like foo.pdf[3]. Here, realpath would fail because that file doesn't exist. That shouldn't be an issue in Piwigo; however, it does happen with destination image files: the file img123-89abcdef-th.jpg doesn't exist when being handed to writeImage().
So here's a fix that works for me, relative to the 2.9.1 release; but can we always assume that $_SERVER['DOCUMENT_ROOT'] is correctly defined? I'm happy to put this together as a PR on master if it wouldn't break other installations.
--- /nix/store/155a7n3x86bdrnzq0lkf39m9ccpp67j7-2.9.1.zip/admin/include/image.class.php 1969-12-31 19:00:01.000000000 -0500
+++ image.class.php 2017-07-31 21:51:05.946457697 -0400
@@ -84,6 +84,7 @@
}
$class = 'image_'.$this->library;
+ $source_filepath = realpath($source_filepath);
$this->image = new $class($source_filepath);
}
@@ -491,7 +492,7 @@
{
// use 4:2:2 chroma subsampling (reduce file size by 20-30% with "almost" no human perception)
$this->image->setSamplingFactors( array(2,1) );
- return $this->image->writeImage($destination_filepath);
+ return $this->image->writeImage($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$destination_filepath);
}
}
Thanks.
I'm actually encountering this issue on Linux, here are my specs:
```
Piwigo 2.9.1
Operating system: Linux
PHP: 7.1.7 (Show info) [2017-08-01 01:55:15]
(imagick module version 3.4.3RC1)
MySQL: 10.1.21-MariaDB [2017-07-31 21:55:15]
Graphics Library: ImageMagick 6.9.9-0
```
So here's some more background. My Linux is NixOS (17.03.1623.138313fe01), which is admittedly a bit strange relative to other distributions, and often exposes upstream bugs/quirks having to do with paths. But otherwise I can't really explain why this appears to work in other Linuxes!
This behavior — that the ImageMagick PHP extension doesn't accept relative paths — is marked WONTFIX in their tracker: https://bugs.php.net/bug.php?id=61583
and moreover they note that `realpath` isn't always a reliable workaround. For source image files, ImageMagick accepts annotations for page numbers, frames, etc… like `foo.pdf[3]`. Here, `realpath` would fail because that file doesn't exist. That shouldn't be an issue in Piwigo; however, it does happen with destination image files: the file `img123-89abcdef-th.jpg` doesn't exist when being handed to `writeImage()`.
So here's a fix that works for me, relative to the 2.9.1 release; but can we always assume that `$_SERVER['DOCUMENT_ROOT']` is correctly defined? I'm happy to put this together as a PR on master if it wouldn't break other installations.
```
--- /nix/store/155a7n3x86bdrnzq0lkf39m9ccpp67j7-2.9.1.zip/admin/include/image.class.php 1969-12-31 19:00:01.000000000 -0500
+++ image.class.php 2017-07-31 21:51:05.946457697 -0400
@@ -84,6 +84,7 @@
}
$class = 'image_'.$this->library;
+ $source_filepath = realpath($source_filepath);
$this->image = new $class($source_filepath);
}
@@ -491,7 +492,7 @@
{
// use 4:2:2 chroma subsampling (reduce file size by 20-30% with "almost" no human perception)
$this->image->setSamplingFactors( array(2,1) );
- return $this->image->writeImage($destination_filepath);
+ return $this->image->writeImage($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$destination_filepath);
}
}
```
Thanks.
<!-- github-comment-id:319247781 -->
Oh, I think I understand now the usage of file_put_contents in the snippet above. I figured it could be a stale diff due to drift between 2.6.2 and 2.9.1, but actually it's so that the file exists in order to make realpath work… got it.
Oh, I think I understand now the usage of `file_put_contents` in the snippet above. I figured it could be a stale diff due to drift between 2.6.2 and 2.9.1, but actually it's so that the file exists in order to make `realpath` work… got it.
<!-- github-comment-id:319248930 -->
$_SERVER['DOCUMENT_ROOT'] doesn't work if piwigo is installed in a sub folder of the web server.
The correct call for me was: return $this->image->writeImage(dirname(realpath($_SERVER['SCRIPT_FILENAME'])).DIRECTORY_SEPARATOR.$destination_filepath);
$_SERVER['DOCUMENT_ROOT'] doesn't work if piwigo is installed in a sub folder of the web server.
The correct call for me was:
`return $this->image->writeImage(dirname(realpath($_SERVER['SCRIPT_FILENAME'])).DIRECTORY_SEPARATOR.$destination_filepath);`
<!-- github-comment-id:458603724 -->
I also encountered the same issue on a Slackware distro (14.2).
Wouldn't define('PHPWG_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . './');
on top of i.php be a valid solution? Or would it break other configurations (for example with ext_imagick )?
On my box this works without touching image.class.php.
I also encountered the same issue on a Slackware distro (14.2).
Wouldn't
`define('PHPWG_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . './');`
on top of i.php be a valid solution? Or would it break other configurations (for example with ext_imagick )?
On my box this works without touching image.class.php.
<!-- github-comment-id:841887259 -->
I also encountered the same issue on a Slackware distro (14.2). Wouldn't define('PHPWG_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . './'); on top of i.php be a valid solution? Or would it break other configurations (for example with ext_imagick )? On my box this works without touching image.class.php.
Encountered this same issue running Piwigo on Nginx Windows 10. My images generate fine with GD but once I switched over to ImageMagick, I had to deploy the fix given by @macgherl57 in my i.php to view my images again. Nothing else seems broken so far, Piwigo team should look to deploy this code in release.
> I also encountered the same issue on a Slackware distro (14.2). Wouldn't `define('PHPWG_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . './');` on top of i.php be a valid solution? Or would it break other configurations (for example with ext_imagick )? On my box this works without touching image.class.php.
Encountered this same issue running Piwigo on Nginx Windows 10. My images generate fine with GD but once I switched over to ImageMagick, I had to deploy the fix given by @macgherl57 in my i.php to view my images again. Nothing else seems broken so far, Piwigo team should look to deploy this code in release.
<!-- github-comment-id:2232357485 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Reported by hakastein on 7 Aug 2014 01:26
Version: 2.6.2
Imagick crash with "Uncaught exception 'ImagickException' with message 'UnableToOpenBlob `./_data/i/upload/2014/08/06/20140806153442-076e3cae-th.jpg': No such file or directory"
Steps to reproduce: Any action with imagick on windows.
Additional information: It can be fixed with realpath. There fix:
file image.class.php
86: $class = 'image_'.$this->library;
87: $source_filepath = realpath($source_filepath);
88: $this->image = new $class($source_filepath);
and
496: file_put_contents($destination_filepath, '');
497: $destination_filepath = realpath($destination_filepath);
Piwigo Bugtracker #3109
I'm actually encountering this issue on Linux, here are my specs:
So here's some more background. My Linux is NixOS (17.03.1623.138313fe01), which is admittedly a bit strange relative to other distributions, and often exposes upstream bugs/quirks having to do with paths. But otherwise I can't really explain why this appears to work in other Linuxes!
This behavior — that the ImageMagick PHP extension doesn't accept relative paths — is marked WONTFIX in their tracker: https://bugs.php.net/bug.php?id=61583
and moreover they note that
realpathisn't always a reliable workaround. For source image files, ImageMagick accepts annotations for page numbers, frames, etc… likefoo.pdf[3]. Here,realpathwould fail because that file doesn't exist. That shouldn't be an issue in Piwigo; however, it does happen with destination image files: the fileimg123-89abcdef-th.jpgdoesn't exist when being handed towriteImage().So here's a fix that works for me, relative to the 2.9.1 release; but can we always assume that
$_SERVER['DOCUMENT_ROOT']is correctly defined? I'm happy to put this together as a PR on master if it wouldn't break other installations.Thanks.
Oh, I think I understand now the usage of
file_put_contentsin the snippet above. I figured it could be a stale diff due to drift between 2.6.2 and 2.9.1, but actually it's so that the file exists in order to makerealpathwork… got it.$_SERVER['DOCUMENT_ROOT'] doesn't work if piwigo is installed in a sub folder of the web server.
The correct call for me was:
return $this->image->writeImage(dirname(realpath($_SERVER['SCRIPT_FILENAME'])).DIRECTORY_SEPARATOR.$destination_filepath);I also encountered the same issue on a Slackware distro (14.2).
Wouldn't
define('PHPWG_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR . './');on top of i.php be a valid solution? Or would it break other configurations (for example with ext_imagick )?
On my box this works without touching image.class.php.
as @macgherl57, but on mageia 8
Encountered this same issue running Piwigo on Nginx Windows 10. My images generate fine with GD but once I switched over to ImageMagick, I had to deploy the fix given by @macgherl57 in my i.php to view my images again. Nothing else seems broken so far, Piwigo team should look to deploy this code in release.