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.
Related
I have a question about saving text/strings as images in PHP. Since I want to protect data on my site, I want to convert text and save it as image files in a folder on a server (before displaying it). Is there a way to do it, or maybe a better solution? Thanks in advance
If you wish to convert Text/String into image, you can try ImageMagick or GD.
Detail about ImageMagick (Imagick extension) is available at http://php.net/manual/en/book.imagick.php)
Detail about GD at http://php.net/manual/en/book.image.php
getimagettftext() function from GD can be useful, see detail at http://php.net/manual/en/function.imagettftext.php
Imagick::annotateImage() function from Imagick can be useful, see detail at http://php.net/manual/en/function.imagettftext.php
If you want to save text as an image, not overlay it on another image, then you should use label: or caption: or tango: in ImageMagick and not annotate.
See http://www.imagemagick.org/Usage/text/. Then find the equivalent command in Imagick. For example, http://us3.php.net/manual/en/imagick.labelimage.php
You can use the equivalent of -annnotate, but then you have to create an background image onto which to write the text.
The advantage of label: for example is that it creates an image automatically.
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
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
I'm trying to dynamically watermark a pdf file using PHP with Zend_Pdf.
Is there a way to de-layer a PDF file, put something (text, image) between the background and text layer, and then save it?
Is there like a z-index for PDF files?
Any help would be greatly appreciated.
Regards,
Paul
There is a type of Z-index but there's nothing that can actually manipulate it pragmatically. I've been trying to do similar for over a month.
I've tried: Zend, FPDF, AcroJS, PyPDF, ImageMagick and GhostScript with no luck.
The only way I've been able to add something "under" something else in a PDF is to rebuild it from the bottom up.
Example: I needed to add a photograph under an employee barcode.
First I cropped the PDF to the just the barcode (my_crop.py - Python)
Then I converted it to tiff copy (imagemagick)
Next I added the employee photo to the original PDF (Zend framework)
Finally I added the barcode tiff from the first step (Zend framework)
It's not in any way perfect but it's the only thing I could get anywhere near what I wanted.
How to include an image inside another image in PHP? I want to do it like in twitterbackgrounds.com personalized backgroud. there is one main image and we can upload four personal images after that it will show as watermark of the main image.
I never used GD by myself, but look at the example in the manual, wich is about "Using imagecopymerge() to create a translucent watermark".
Well, there are several possibilies to do that. The one that pops into my mind is to use a php page where you can upload all files needed for this. After submission you can use imagemagick to create the new image with watermarks and display it on another webpage or store it to a database.
Here is a good tutorial on how to use imagemagick to create the watermarks in another image.
you may use imagemagick as commandline command from php or use it as a server application on an own server
phpThumb has a watermark feature, if you're looking for something full-featured and ready-made..