Uncaught ImagickException: UnableToOpenBlob `application/pdf': No such file or directory - php

I want to convert the PDF to JPG by using imagick, but after I press submit it keeps showing a fatal error: uncaught imagick error. Do you guys know if this is code problem or an imagick extension problem?

Your $_FILES['fileToUpload']['type'] stores the MIME type and you are assigning it to the variable $pdf_file and you are trying to read this with imagick. This can't work. You could var_dump($_FILES) and see if you can find the actual file in there.

Related

Gmagick set density before loading PDF

Converting a PDF to an image using Gmagick in PHP renders a very poor quality image.
The solution in Imagick was to call setResolution(x,y) before loading the PDF file. This would change the -density option.
There is no setResolution(x,y) in Gmagick, and unfortunately, calling setimageresolution(x,y) just throws an error:
PHP Fatal error: Uncaught exception 'GmagickException' with message 'Can not process empty Gmagick object'
Calling setimageresolution(x,y) after loading the PDF has no effect, and I can't find a way to set the -density option before loading the file.
EDIT: I would be happy for a way to set the default density system-wide. I do have root access.
I bumped into a similar problem and solved it with the following code:
$image = new \Gmagick();
$image->setresolution(300, 300);
$image->readimage('sample.pdf[0]');
Note that the setresolution method is not documented in PHP anywhere, but it seems to work – at least for me.

Convert pdf to jpg using php Magick

I am looking for a solution to that problem, I am trying to convert pdf to image using php image magic, here is the code, I have tried many solutions but still I am not able to understand why it shows same issue every time
$FILE = realpath(__DIR__ . '/file.pdf');
$im = new Imagick();
$im->pingImage($FILE);
$pageCount = $im->getNumberImages();
echo $pageCount;
If I put jpg file in it, works fine, but if I add file.pdf it shows this error
Fatal error: Uncaught ImagickException: PDFDelegateFailed `The system
cannot find the file specified. ' # error/pdf.c/ReadPDFImage/794
Note: I have installed ghost script 9.52 64 bit , Imagick 7. something! , I am looking for the help
I had the same problem and after a week trying to fix, I discovered that this problem seems to be related to the recents Ghostscript version.
I solved removing it and installing the version 9.26 after trying all of those.

PHP Imagick : RAF file not being processed

I am trying to read a RAF file in php using Imagick but somehow its not working. I have looked into the formats supported by Imagick and RAF is listed.
I later tried to simply read RAF file and echo it out but still no luck.
I keep on getting this error:
Uncaught exception 'ImagickException' with message 'unable to open image `/tmp/magick-H2rs1zGJ.ppm': No such file or directory
I tried rendering a png file saved in the same directory and it worked but somehow its not working for RAF.
$imagePath = "uploaded.raf";
$imagick = new \Imagick($imagePath);
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
Any help is appreciated.
Thank you!

500 error writing to PDF using Zend

I have Zend working properly, and it will open a PDF, and save it, but when I try to actually use drawText to write some text over the PDF, I get this:
PHP Fatal error: Call to undefined method Zend_Pdf::drawText() in /home/whatever/test.php
I don't understand why it won't work, thoughts?

Uncaught exception 'ImagickException' with message 'Failed to read the file'

I'm having problems with reading a file with Imagick. I've installed the imagick and ghostscript extension successfully.
This is what I'm doing:
<?php
$im = new Imagick();
$im->setResolution(300, 300);
$im->readImage('/Applications/MAMP/htdocs/mywebsite/wp-content/plugins/myplugin/uploads/magazine_cover.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>
I'm getting the error:
Fatal error: Uncaught exception 'ImagickException' with message
'Failed to read the file' in /Applications/MAMP/htdocs/imagick.php on
line 10
When I try to execute the following command in my terminal:
convert magazine_cover.pdf magazine_cover.jpeg
I'm getting a warning:
**** Warning: considering '0000000000 XXXXX n' as a free entry.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.11.3 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
But he created the jpeg ... . Why doesn't this work in the browser?
Well the warning is generated by Ghostscript, it says your PDF file is not technically legal, but it should process just fine, unless there are more problems.
I would suggest you find out what command ImageMagick is passing to Ghostscript and try that on the command line. If it works then the problem is most likely at IM's end, otherwise the problem is that Ghostscript doesn't like your PDF file. The command line will probably give you more information. Even if it doesn't with that information and the file you can open a Ghostscript bug report and it can be fixed (if possible).

Categories