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

ImageMagick: Receiving invalid filename error when converting first page of pdf to jpg #4771

Open
kevindeleon opened this issue Feb 4, 2015 · 4 comments

Comments

@kevindeleon
Copy link

Environment: Ubuntu 14.04, HHVM 3.5

I'm using ImageMagick to convert a pdf to a jpg in a script I have...it works fine if I give the full server path to the uploaded pdf without the page specifier, but when I add the [0] onto the end of the file path to specify that I only want to read the first page, it bombs out with the following error:

"Fatal error: Uncaught exception 'ImagickException' with message
'Invalid filename provided' Imagick->readImage()"

I've also tried using '/path/to/file.pdf[0]' directly in the constructor with no luck, but without the page specifier, that also works fine.

According to what I've read in the PHP docs and tested, this code should work, but gives the error seen above when using the page specifier.

$doc_preview = new Imagick();
$doc_preview->setResolution(180,180);
$doc_preview->readImage('/path/to/file.pdf[0]');
$doc_preview->setImageFormat('jpeg');
$doc_preview->writeImage('/path/to/file.jpg');
$doc_preview->clear();
$doc_preview->destroy();
@paulbiss
Copy link
Contributor

Looks like we don't properly parse the path because we're lacking GetPathComponent.

https://github.com/ImageMagick/ImageMagick/blob/626a27b7ba3ae0d975e27a546855e3302756ce87/MagickCore/utility.c#L1198-L1361

if (isMagickPseudoFormat(path, 'R')) {
realpath = path;
} else {
auto var = HHVM_FN(realpath)(path);
realpath = var.isString() ? var.toString() : String();
if (realpath.empty() ||
!HHVM_FN(is_file)(realpath) ||
!HHVM_FN(is_readable)(realpath)) {
realpath.reset();
}
}
if (realpath.empty()) {
IMAGICK_THROW("Invalid filename provided");
}
auto status = op(wand, path.c_str());

@paulbiss paulbiss self-assigned this Sep 27, 2016
@xoref
Copy link

xoref commented Dec 7, 2016

Would like to know if there's any progress on this issue. WordPress 4.7 introduced enhanced PDF support by automatically trying to generate a thumbnail of the first page of a PDF file. This fails on HHVM because of this issue.
There's a workaround by using fopen() to open the PDF file and then passing the resource to the readImageFile method of Imagick.

@Swahvay
Copy link
Contributor

Swahvay commented Jan 21, 2019

Just ran into this issue from one of my users as well. (HHVM 3.30.0). Referencing the workaround here: https://stackoverflow.com/questions/28286358/receiving-invalid-filename-error-when-converting-first-page-of-pdf-to-jpg

@Swahvay
Copy link
Contributor

Swahvay commented Jan 21, 2019

Actually, the workaround doesn't work for me either. Only happens with PDFs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants