I am going to create some images with text using PHP script and want to simplify the process.
Are there any classes/libraries/wrappers for GD and ImageMagick that can help me with this? For example, add some effects, custom fonts, etc.?
This will help you : http://php.net/manual/en/book.image.php
imageloadfont function can be used to load new fonts refer : http://www.php.net/manual/en/function.imageloadfont.php
You could look into using SVG for this. Text items and effects such as blur can be added very easily with simple XML manipulation, and then you could render it with inkscape - in PNG or PDF format.
Related
I'd like to ask whether its possible to take a bit of CSS on a page with a PHP extension, and add the PHP header to define the page as a PNG, and have a dynamic image? From what I've heard this isn't possible, but if it isn't, is there a way easier than the conventional method of creating a PHP image?
Edit*
To elaborate, I want to do something like draw a bordered 200x200p box in CSS with styling and HTML, and have this HTML/CSS box on a .PHP page, and get this page to become a PNG image with the .PNG extension using the PHP header tag.
Thank You!
Karan
You can make use of wkhtmltopdf which can convert html to pdf using webkit (qtwebkit) which supports CSS properly. There even exists a PHP binding for it.
You can then convert the PDF file to a PNG (e.g. with ImageMagick) and serve it from within PHP.
Related: Website screenshots using PHP
If I understand your question properly, I am not sure how this would be possible using only PHP but you could use ImageMagick on server side to convert the HTML page to a png.
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 need some PHP classes that deal with image processing in a good manner. I have made a thumbnail creator myself but the end result quality is just horrible.
Is it also possible to let PHP convert and save all images to one type. For example take an image(jpg,png,gif), compress it, resize it, and save as png.
Can anyone recommend some good classes for this.
Check out https://github.com/avalanche123/Imagine, given you use PHP 5.3, it will solve most of your image processing needs
You can take a look at this one
http://shiftingpixel.com/2008/03/03/smart-image-resizer/
You can look into the php gd library, or imageMagick, which has bindings for php.
If you have access to command-line i'd recommend image magic. The comman-line version has the advantage that it includes several features for batch processing.
I am working on a website in which the client wishes to have users upload background images to a printable design, crop to size, add text. Do this to multiple pages then generate a pdf of the 'book'
I am running into the following issues/questions and just need to see where I can start
Are there any PHP developer packages that can do something similar. I have seen jquery crop tools but something also for adding text to an image?
How would I keep the resolution up? If the final cropped with text image needs to be 150dpi, when cropping I am guessing I would have them working on a 72dpi image, then somehow apply the crop and changes to the large image?
If the resolution issue wasn't a big deal I would go about it this way:
Simple image upload
Use jquery to crop photo to correct dimensions
Mess around with gdlibrary and imagettftext() to get the text onto an image (page)
Use something like FPDF to create a pdf from each 'page'
Is this the right way to go about it and any thoughts on the resolution issue. Thank you for any help!
Your primary tool should be ImageMagick. ImageMagick can do the cropping, resizing, scaling, overlay text or graphics, combining images, and apply special effects. A big advantage of using a separate tool instead of PHP's image manipulation tools is that you can do the same transforms in batch through other mechanisms, or even hand the work over to another server to keep the website more responsive. And if you do want to integrate it tightly into the website, you can use the MagickWand For PHP interface.
Cropping does not change DPI, only the dimensions of the image. Scaling, on the other hand, changed both.
You should take a look at Gallery, a GPLed program with some of the functionality you're looking for, and written in PHP.
domPDF is a good tool for converting HTML to a PDF. this way you can use the image they upload as a background image, then put the text over it in any standard HTML tag.
As far as the resolution/dpi issue goes, I'm not sure if there is much you can do outside of changing the size of the image. I would recommend looking into This PHP Library, which has a lot of good tools for manipulating images.
I think with a combination of these tools, you'll be able to create HTML that can make a PDF that's fit to print, and use that.
I am using php and I want to take a snapshot of my web page using php. Something similar to this
http://www.moneycontrol.com/gd/mail_indices.php
How can i do that?
To take Snapshots of a website, and not as proposed generate an image with text in it, you can use either
http://iecapt.sourceforge.net/ for snapshots using IE's rendering engine or
http://cutycapt.sourceforge.net/ for Webkit (Safari/Chrome) snapshots
I strongly recommend the latter.
The fastest and surest way in PHP to create images is to look at the GD Library. They have tons of functions to help you create your image easily.
Should you need a font that is available in Windows Font but not in PHP font, you can use this tool to convert it: http://www.wedwick.com/wftopf.exe
You can use Imagemagick.
Theres is a comprehensive summary of image creation option in Php here. The other option not already mentioned is Cairo.