I'm having a hard time converting a pdf file to jpg using the php Imagick Library on a wordpress based web site.
I have done some reading and I think I need to install Ghostscript to achieve my goal.
Is that the case or I can do it without Ghostscript.
My code looks like that:
$img = new Imagick();
$img->setResolution(200,350);
$img->readImageFile($link.'[0]');
$img->setImageFormat('jpeg');
$img->destroy();
$img->clear();
I can successfully run the above code without the setImageFormat. setImageFormat produces an error. All other commands run successfully though.
Any ideas??
Thanks
You'll need to install GhostScript. PDF is handled by the GhostScript interpreter.
Related
i have problem with magick tool on php
use this tool on my laptop and my server (bluehost)
the weird part is the function work on laptop but it doesn't work on the server
here command on my laptop
$gp= "C:\Program Files (x86)\ImageMagick-6.8.0-Q16\convert.exe ";
$ch=" -density 300 upload\\temp_img\\*.png";
$ch.=" upload\\pdf_created\\".$id_pro."_".$id.".pdf";
$gp=escapeshellarg($gp);
echo exec($gp.$ch);
and the command on the server
$gp= "convert upload/temp_img/*.png upload/pdf_create/".$id_pro."_".$id.".pdf";
echo shell_exec($gp);
in addition to this problem
convert -resize
doesn't work on the server
but i used other function to resize
Imagemagick is a raster image processor only. PDF is not a raster image, therefore it has to be converted to it before further processing. Imagemagick uses ghostscript to handle this.
So if you can convert images like jpg's with the mentioned command, but not pdf's, it's very likely that ghostscript is missing.
There is problem with the path on the server, On server there is no "C:\Program Files (x86)" path.
Give the relative path like this
$path= realpath(__DIR__.'/../'));
I'm using ImageMagick 6.7.7-10 2012-06-27 Q16 on a windows 2012 server and with fastcgi and PHP Version 5.4.22.
I'm trying to use this command (inside a PHP file) to convert a pdf to a jpg but it doesn't work, nothing happens.
echo shell_exec("convert image.pdf image.jpg");
This command line work perfectly inside a command shell (msdos command shell).
I tried to convert a jpg to png and surprisingly it worked !
echo shell_exec("convert image.jpg image.png");
It's also working when I'm converting a png to pdf.
echo shell_exec("convert image.png image.pdf");
Now I'm getting confuse, why is it not working from a pdf to an image ?
Am I missing a php extension or a setting ?
Cheers,
You have to put let PHP know the PATH to the ImageMagic.
You can manullay put that by adding this line in your PHP script.
putenv("PATH=your_path_to_the_bin_folder");
something similar depending on your setup. The gs executable has to be in your script user's path somewhere or ImageMagick will fail to convert PDF or EPS files.
I have an SVG file which contains rotated, semi-transparent, clipped (clip-path) elements (e.g polygons, images). This file is perfectly working in Inkscape but for further image processing I would like to use it in CorelDraw, too. But opening in CorelDraw the result is a mess (X6 actually, but earlier versions do almost the same).
Is there a method to convert SVG to native CDR or any other vector format that is CorelDraw compatible???
The SVG is on an Ubuntu LAMP server and imagemagick, inkscape, libcairo2-dev, librsvg2-bin are installed.
To convert vectors you could use Unicovertor, which is a command-line converter supporting many formats. https://sk1project.net/uc2/
Command in terminal to convert files is
uniconvertor image.svg image.cdr
In php you could then do
system('uniconvertor image.svg image.cdr');
Please note I used this one however it can be sometimes tricky to install on ubuntu, make sure you always have the most updated version (apt-get update).
Multiple distributions are available https://sk1project.net/uc2/download/
You can use inkscape and save SVG image as PDF and import PDF in Corel Draw.
Just a little trick.
It is not the indicated way, nor the correct way. But it works. !!
Rename the file.
myFile.svg to myFile.cdr
our website has a certification image created by PHP GD, and I can print and watch it on a web page. But I couldn't make it a downloadable PDF file. Is there a way I can do that?
You can first save the image somewhere and then use the FPDF lib to write it in a PDF file
you could use imagick to do this..
the below command does the trick if your server is properly configured - Imagick is installed, GhostScript is installed, php is allowed to execute shell commands, etc
shell_exec('convert /path/to/input.png /path/to/output.pdf')
I tried the sample codes for imagemagick and it was able to save out document previews to the folder on the server.
I tried sample code for fpdf and it was able to render the PDF file fine when it is sent but fails when I ask it to save for directory.
Researching online it says the resolution to the fpdf issue is to set file permission to 777 (any source access permitted, as I understand). My default folder permission is 755.
I want to ask if anyone knows why I can save with imagemagick but not with fpdf.
The reason, I suspect, is because imagemagick calls requires exec() which is effectively command line access. As I understand it however, fpdf is just a PHP wrapper for PDF libraries already present on the server so should have the same availability to exec().
Haven't had a chance to go through the code of fpdf yet but as I am a noob to PHP I don't think that is going to be particularly enlightening.
Please help!
EDIT:
As requested
FPDF
$pdf->Output('testdocument.pdf', 'F');
http://www.fpdf.org/en/doc/output.htm
Imagmagick
exec('convert "docprev.pdf[0]" -colorspace RGB -geometry 200 "document2.png"');
So those are the output commands of FPDF and Imagemagick respectively.