When I use a php script using imagick basics in the same folder where the image is and using the filename the output is perfect, it outputs the image of the PDF's 1st page:
// Read page 1
$im = new imagick( 'Miami_Guide.pdf[0]' );
// Convert to png
$im->setImageFormat( "png" );
// Send out
header( "Content-Type: image/png" );
echo $im;
Here is the challenge: how do I move this script to a different directory AND using a fieldname called $uploaded from a database record instead? I tried this but it didn't work:
$path: '../../otherplace/';
// $uploaded is the field with the filename value
$fileloc: $path . $uploaded;
// Read page 1
$im = new imagick( '$fileloc[0]' );
// Convert to png
$im->setImageFormat( "png" );
// Send out
header( "Content-Type: image/png" );
echo $im;
I get a "Fatal error: Uncaught exception 'ImagickException' with message 'Unable to read the file: $fileloc' in /home/user/public_html/dir/folder/script.php:334 Stack trace: #0 /home/user/public_html/dir/folder/script.php(334): Imagick->__construct('$fileloc') #1 /home/user/public_html/dir/folder/script.php(226): show_record(Array) #2 {main} thrown in /home/user/public_html/dir/folder/script.php on line 334
Also tried pathinfo() and fatal error again
I made a few tweaks but now Imagick is returning gibberish instead of image:
$sourcePath = 'dir/folder/'; // Path of original image
$sourceUrl = 'http://www.site.com/';
$thumbPath = $sourcePath; // Writeable thumb path
$thumbUrl = $sourceUrl . $thumbPath . $uploaded ;
$im = new Imagick($thumbUrl);
$im->setImageFormat( "jpg" );
$im->thumbnailImage(100, 100);
header("Content-type: image/jpg");
echo "$im";
"No error" but outputs gibberish instead of image:
ÿÛCÿÀdd"ÿÄÿÄ9 !1"#A2QVh‘•¦Ôä$Waq±ÓÿÄÿÄ)!1Qq"A‘Òar’¡áÿÚ?Íkßµ+¾;é=oÕÜŽW#ü–ÙænÝ»ë‘çOo´OÒÝr2_^¬ÇiÓFãaR›5$ò~\’0#Ïn¢—·©ÕuµðGMXÍ«ùÛæÿÃ'g§lfÍ,Ø”Sú*¥Áw“h‡/qk,=Ýržzï–>~ÂÒút ƒÔ«á3žŽÃ‹¶s8yd“4–ݤ®§‚ÇqW¼ºÎ£‹Áß~.—´¤ŸÅKn@ «DE ±gÄ©"hm&㥰öÔ«b¬..........
Any help?
Here is the solution:
instead of:
you should echo:
This solved my Imagick problem, I hope it will help others.
One thing that I made sure was to test the basics: test.pdf > test.jpg, also tested: test.pdf > test.png, test.pdf > test.tiff - once I was sure that all the extensions were in the delegates and working fine, I moved to different dir and pulling the file from someplace else.
Brief of all the steps:
1- installed imagick (php) - I believe it was devel
2- set the path to the file thru http://
3- the rest was pretty much Imagick basics: