I have a text files which I'm trying to convert into images. I know how to do this with GD but I'm having trouble finding suitable functions with imagick/imagemagick.
you want annotateImage() there will be more than that you need to do like setFont() ,setTextAlignment() etc... but that should get you going
Related
I want to write text on an image using PHP by calling ImageMagick commands, like uploading an image and editing text on the image. How can I do that?
There are a lot of classes that will help you doing this, my favorite is https://github.com/claviska/SimpleImage. There is also a stackoverflow post how to convert text into an image convert text to image in php. With this combination you are able to reach what you want I think.
You'll need the function ->overlay('watermark.png', 'bottom right') of the SimpleImage class.
If I want to convert a pdf to greyscale whats the best way to go about it. Im currently using tcpdf to convert html to pdf but I also need an option where I can convert it to greyscale. Whats the best way to go about doing this.
If you have Imagick (imagemagick) installed, you can take your generated PDF and save another gray-scaled one.
$image = new Imagick('generatedPDF.pdf');
$image->setColorspace(imagick::COLORSPACE_GRAY);
$image->writeImage('newPic.pdf');
$image->clear();
$image->destroy();
I think the best way is to manipulate the HTML and images and make the HTML grayscale before converting to PDF.
You can run through all your images and pass them through GD to make them all gray
http://php.about.com/od/gdlibrary/ss/grayscale_gd.htm
You will also need to probably create a separate css to use in case you have color applied to your page.
HTH
I have been reading about this but I have to do some thing. I have a table with diagonal text in the heading columns and horizontal text in the rows. I was able to make text diagonal using CSS rotation thing, table data is coming from db and I want to generate the same html into the pdf. I don't know who to write diagonal text in the pdf. The solution is to create an image of the visible html table with data and then store it and then make pdf and embed that image there. I have been reading the GD library but how can I make table in GD library I am stuck , Stack Overflow is the last resort. Please help.
try this ezpdf class http://www.ros.co.nz/pdf/readme.pdf. they got some sample code to rotate text and how to embed image into pdf.
example
for ($angle=0;$angle<360;$angle=$angle+20){
$r=rand(0,100)/100;
$g=rand(0,100)/100;
$b=rand(0,100)/100;
$pdf->setColor($r,$g,$b);
$pdf->addText(300+cos(deg2rad($angle))*40,300-
sin(deg2rad($angle))*40,20,$demotext,$angle);
{
$pdf->stream();
If you want to go directly from your HTML code to PDF, and if you need something entirely in PHP you can try dompdf. The 0.6.0 release will include CSS transform support.
For image generation in PHP you can use GD functions (fast) or iMagick (not so wide spread, docs are WorkInProgress, but you could do almost anything you can imagine with it).
GD should be enough.
A simple idea about making text diagonal would be to just rotate the image, once you output text from the db onto it.
Use wkhtmltoimage or wkhtmltopdf.
Do you need to do this only once or does this need to be an ondemand service? If not why not just load the html page take a screenshot and crop it down to the table?
Instead of trying to convert HTML directly to a PDF document, you might want to try a PDF library for creating the document directly in PHP. This way you will get more control over what the PDF looks like, and it may be a better solution that trying to convert your HTML output.
https://stackoverflow.com/questions/560583/which-is-the-best-pdf-library-for-php
Theres a way, using PHP exec and Image MagicK, to get the first PDF page and convert it to JPG?
To answer your question, you convert just the nth page page as follows:
convert file.pdf[n] output_file.jpg
Note that this is zero based, so for the first page you would want to use file.pdf[0].
If you wish to convert the entire file, you can do:
convert file.pdf output_file.jpg
And this will produce a bunch of files in the form of output_file-0.jpg, output_file-1.jpg, ..., output_file-n.jpg
There are many search results on SO already.
You have the choice between two duplicates:
ImageMagick/Imagick convert PDF to JPG using native PHP API using the PHP IM bindings
Imagemagick convert pdf to png using the command line.
Note that for this to work, you need Ghostscript installed along with ImageMagick. (I think this usually is the case.)
I have an RTF file that I need to display to a user. I know that I need to convert it if I want to display it in the browser. I would like to be able to convert it to JPG so that I can take advantage of other code that I am using that uses ImageMagick to convert JPG to PDF. ImageMagick will convert a PDF to a JPG, but not an RTF :( I am using PHP on a windows box.
****Update****
I have figured out how to convert the RTF to PDF and then I use ImageMagick to convert it to JPG for display. I don't like the fact that I have to go to PDF first, but it works so I am going to stick with it. Thanks to all that have responded.
Perhaps you could convert the RTF to PDF then to JPG. Sure thats more work than going straight from RTF to JPG but it might be an acceptable short term workaround for today.
This might require more that one tool.....
for the rtf to pdf
http://www.linuxquestions.org/questions/linux-software-2/convert-rtf-to-pdf-263247/
http://www.linuxforums.org/forum/linux-applications/141953-looking-convert-rtf-pdf-utility.html
As for the PDF to JPG
you can try convert(linux)...ImageMagick
You might want to consider converting your RTFs to HTML, instead of turning them into images.
This looks promising.