Can I get some sample code in PHP for converting an html table to image
form(.gif,.jpg or any format)? I am using XAMPP on Windows.
Yes, the table is coming from the database.
The best way is to convert first in a .ps, then jpg, pdf, or whatelse you need.
I can suggest you 2 links:
html2ps
wkhtmltopdf
Tested both, and both works perfectly... html2ps is little slow (~30 sec for a 3 pages pdf, dunno about jpg) but more customizable.
Give them a look
you like to have an screenshot from an html-table / html-code?
Thats not possible with php only.
You need a webbrowser or an html-renderer and a program do make an screenshot.
look at
http://www.thumbshots.org/ (onlineservice)
or
http://www.intellitamper.com/webswoon/ (python tool.)
At first glance, that's quite a tall order. Here are some pointers:
You'll probably want to get cosy with the GD library
Where is this table coming from? If it's coming from your database originally, this would be easier to work with. Otherwise...
You'll need to get the remote page (I recommend curl)
Then you'll need to extract the table data
The complexity of the second step really depends on how similar each page and table is going to be. Regex is probably going to be useful though.
Hope this helps,
Tom
As DrFuture mentions, using php only is probably not the best way to go to convert a table into an image. I modified http://www.zubrag.com/scripts/website-thumbnail-generator.php to get it to convert my html into an image (put the html on another webpage and pass that url to the script). I would suggest going with the 'screenshot' route instead of GDI and other drawing tools.
Related
ive been reading up on QR Codes a lot recently, I want to code my own generator with PHP. But i'm having trouble, as they are rather complicated, does anyone know of any tutorials for this sort of thing?
I found this, but I get stuck when trying to convert the result from page 3 to a 11-bit binary result. I'm also confused as to why "H" ASCII value is 17 on that table, but it is 72 on the ASCII table below...
The main issue i'm having is generating it, I was thinking about using a table for the pixels. I want to eventually be able to generate my own QR Code like the one below, but different text in the middle and different content:
I would suggest that you do NOT use tables for generating QR codes. This is way too much overhead for the browser, and if a browser renderes the box model that is off by 1 pixel, your whole image will be crap.
I would take a look at generating your images on the sever in php using GD2.
http://phpqrcode.sourceforge.net/
http://www.youtube.com/watch?v=sFVcOFmnZ9Y
If you really want to generate images inside the browser, you could probably get away with a HTML canvas tag.
If you want to add text I suggest you layer the text on-top using GD2. If you are using an SVG library I'm not exactly sure how to layer, but it should be simple. Here's an example of layering in GD2:
http://phpimageworkshop.com/
The thing to realize about QR codes is that they can store up to 30% redundant data. That means that you can "destroy" 30% of the code by layering an image on-top and it will still work. Here are some guides about customizing QR codes with logos etc:
http://blog.qr4.nl/post/QR-Code-Error-Recovery.aspx
http://mashable.com/2011/04/18/qr-code-design-tips/
There are many php classes and external libraries available to generate QR code using php. I have listed some of them below. You can refer these links.
http://phpqrcode.sourceforge.net/
http://www.phpclasses.org/package/6399-PHP-Generate-QR-Code-images-using-Google-Chart-API.html
http://qrcodescript.com/
I have a tableview, that contain an image for each cell. Since there will be quite a lot of cell, is it possible to package all the images needed, and retrive them with one request, or do you have to request each and every image separate? Trying to reduce the stress for on server. Or is this the normal way to do it?
Thanks in advance
I think you should just load the images asynchronously, more than dealing with such an optimization. As you ask, yes, this is the normal way to do that, unless your server has really huge traffic (huge = google.com, facebook.com, etc.).
I use the SDWebImage open source library and it works really well, making it transparent to you. After importing it, for each cell, you should do:
[cell.myImageView setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:#"MyPlaceholderImage"]];
and it will try to load (and cache) dynamically each image, placing a placeholder image while it's loading.
I use it in a table with 100+ rows and it works like a charm.
Hope this helps!
If you need, you can serve a collection of images as a zip file.
(And how do you do that? It depends. I don't know if the images are static or dynamic.)
try converting the image in base64 formate and then send it
I have following problem. I have txt file here : http://ch1zra.com/d2/runes.txt
I use PHP to loop throgh the file and generate this table : http://ch1zra.com/d2/runes.php
Table uses some basic styles and I like it that way.
txt file is generated and uploaded via python. I would like to create an image that looks like that table. Is there any way using python or PHP to do so ?
Any image format that is acceptable on the web is good, PNG being even quite welcome.
I've read somewhere that python reportlab can make styled tables with alignments and so on, so that could be a good start, but reportlab generates PDF. Of course, if that is just a step between it is also acceptable (if I could do the PDF > img conversion on my machine). ALso, IIRC every PDF contains a "screenshot" of each page for fast browsing, so that would also be cool.
All in all, I have this txt file and this HTML table that I want as image. If any1 can help that would be great :)
thanx in advance!
I can only speak for PHP.
You could try to build the image by hand with PHP's image functions http://www.php.net/manual/en/book.image.php
Or you could try executing a external script like: http://marginalhacks.com/Hacks/html2jpg/
something like painty but with advanced options having div, font, fontsize, style... etc....
I would like to have a coupon design in html and output it as an image.. preferably JPG..
but painty is not supporting those.
you can find here.. http://www.rabuser.info/painty.php the painty code i am using right now.
Thanks and waiting for the reply.
Creating this with pure php is bad idea, this will be slow as hell.
As far as I know in production this is achieved with external screenshot app and standard browser run by exec() or similar function.
There's khtml2png, which renders the whole page and takes a screenshot; however, it's a standalone executable (and it needs an X server or xvfb), so you need to be able to run it on your server (so probably not on a shared hosting). This may be a bit of an overkill, but it gives you complete control over the final appearance.
You could also use some of the HTML to PDF convertors and then use ImageMagick to convert the PDF to JPEG.
In my site i m fetching my mysql data by using PHP. I want open that data in pdf file when i click pdf print button is it possible?
First of all, if you want a high quality professional product to do that. You want Prince XML
If you are looking into some open source tool to achieve something similar. You can look into this SO question.
You could prepare static PDF form file, that just fill it in with values using PHP's FDF module.
It depends which platform are you using. This would be an easy job if you are using Groovy on grails. There are plugins which facilitate pdf reporting like the jasper-plugin.
Luis
Check out jsPDF, an open-source library for generating PDF documents using nothing but JavaScript.
You can process the data with Apache FOP after transforming it to XML. (http://xmlgraphics.apache.org/fop/).
If your page is template based, you may create a template which produces xml output and process that. You'll have extremely well contol over the pdf construction. The tradeoff is that it is not a "plug this in and will work" solution, but I've done that and once its set up, works like charm.
I've used TCPDF in the past, it's a little kludgy but can definitely get the job done. (http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf)
The FPDF module in PHP is simple enough to get the data together. It is a safe option since you know what data you are passing out to the PDF engine. There are some streaming pdf options which can take in a bunch of html and then output that to pdf however they can get it quite wrong without you knowing.
I used, on Linux machines, WKHTMLTOIMAGE/WKHTMLTOPDF a number of times, on many projects. It workes like a charm, easy to use, just a script that you run.