From PHP: how to get a dynamically generated javascript image - javascript

Why would you do such thing??: because in some particular cases I need to hide the source values of a graph generated by dygraph. Since in the case of "not hidden values" I am using dygraphs js libray, using this particular feature would save me a lot of time.
This way I would have the same look and feel, and I would not have to modify the data generation process.
I would like to know if this road is feasible or utter madness:
Steps: (using Yii-PHP over an Apache server)
Generate javascript page on the server side.
Get image as png (somehow), still on the server side.
Send the image to the client as the only thing he can receive.

There's a ton of graphing libraries for PHP, why not use one of those? (e.g. JpGraph, pChart...) Pretty much every one of them can produce an image in PNG.
Feasible steps:
Invoke a PHP graphing library on server side
Render it as PNG and send to the client
If you insist on using a JavaScript library, then I guess PhantomJS is your only option, but it is not exactly optimal.
tl;dr: My vote goes to "utter madness".

Some dygraphs users have built a tool for exporting PNGs: demo and discussion.

Related

How do you insert the values of variables made in a p5.js sketch into a MySQL database?

I have made a sketch in p5.js which the user can manipulate in ways such as creating shapes and dragging them across the screen and controlling a slider. I was wondering if there was a way to insert things like the x and y coordinates of the shapes, their heights and widths, and the position of the scrollbar into a database in MySQL so that I could make a fully functioning site where users can create their sketches, save them and modify them.
I have tried using a JSON file but I have realized that I cannot modify JSON files using p5.js so a user would not be able to modify their sketches and save the changes. I have also searched the web for solutions to this problem but nothing seems to come up.
To interact with a database, you're going to need to run server-side code.
Your P5.js sketch (which is client-side code) would send a request to your server, and your server would store the data in a database.
There are many many many ways to write server code, and listing them all here would not be feasible. Instead, I recommend you start by trying out a few different options: PHP was listed, but there are also Java servers (using JavaEE) and JavaScript servers (using node.js).
Shameless self-promotion:
Here is a tutorial on client-server communication, specifically JavaScript and Java servlets.
Here is a repo that contains a P5.js sketch that stores data in Datastore.

Generate charts without HTML / Browser

I have a node.js application that accesses data of a MySQL database and I want to generate charts from that data dynamically, to pipe it as image (PNG/JPG) through a HTTP server to the user. I've search for a little while now, but I was unable to find a library to do this without the HTML/canvas approach. Since I want to let the server do the rendering to use the graph in emails or also dynamically rendered PDF files, this isn't an option here.
What could be the approach here (with or without a library) ?
Edit to provide proof of own work: I found https://plot.ly, which is in terms of usage and result really close to fulfil my needs, but requires an internet connection, since it calls a remote API.
You could also try asking this in the Software Recs Stack Overflow. But one option that seems like it could fit your needs is ZingChart.
They have a phantomJS build for rendering static versions of charts. In addition, licensed users can access a Node.js build for server side charting.
Full disclosure, I'm on the ZingChart team so please let me know if I can help you review all your options.
There is a node wrapper for the chart library chartist. You could use this library to generate a SVG, and a svg2png lib to convert to PNG.
Well there are multiple options, I would use phantomjs (headless Webkit browser) to render the charts.
Why would this option be good? One of the reasons is that you don't need duplicated code for the server and client side coding, you could simply reuse the code. On server side create a html file with required scripts and data and render it.

Detect Content Embedded in Images

I was wondering if there was any possible way to detect if there is content uploaded into images. For instance, using WinRAR, I could embed any sort of file into an image, while maintaining the images format as an image. Sites like imgur manage to block this. I am wondering how they do this.
I think one possible way would be to upload the image data to a canvas, so that it's represented purely as an array of pixels, and then reconvert the canvas's data back into an image. However, this would be rather time consuming on the server side.
Does anybody know of an efficient way to do this?
As you mentioned node.js and server side you can do the following:
1) Use imagemagic with node binding node-imagemagick - it uses cli imagemagic so it will be fast. Library is widely used so you will find plenty of examples how to remove Exif and unnecessary data from file. In worst case scenario you can recompress file.
2) If you are working with jpeg image only you can use node-jpegoptim and optimise each uploaded file. It is also using cli so will be fast
3) Finally you can use node-smushit and use Yahoo servers to do the job however you need to check if their terms of service are ok with your content.
Those are 3 that came to my mind, I hope one of those will satisfy your needs.

print html page to PDF on a schedule

I have a HTML page that uses javascript to generate dynamic images using a graph handler on a different server. The images will contain the same data for 1 week but will change when the 1 week window expires.
I am trying to come up with a way to automatically save the contents of the page to either a local file on the server or write to a PDF file.
I tried to use a 'web downloader' like HTTTrack, but it does not get the dynamic images...
I am running the html page off IIS.
I have no experience with IIS or ASP.
Thanks!
I'm not sure that I see any way to do this directly off the front end in an automatic manner. The challenge is that any "screen scraper" you have go out and grab the site with would need to be running javascript to get the tables, which isn't how I see many such systems operating. It's partially why you see strangeness on Archive.org when you have a site that's heavily augmented with javascript or flash.
An untested concept you might attempt was posted in this Stack Question
I could see some sort of a system that you rig together with another computer that schedules an browser load then prints to .pdf in some fashion. I've been unable to find any specific software that would automate that process, so you'd be left cobbling such a system together on your own.
Clearly you have the data available to make your dynamic images. The most feature-rich way I could think of would be to use a system like Jasper Reports or Crystal Reports, which you could feed your data, replicate the report, and easily output via pdf, a built-in export in both systems.
Perhaps its worth questioning your end purpose. To me, creating a "snapshot" of the relevant data in another table and using another system to render your graphs from that snapshot data seems far more valuable than just a print of the screen. You can then go back and adjust data as needed, or use it for other reporting purposes, exporting in any number of tools that are even as simple as Access. Heck, 10 years down the road you may want the data to look better than the graph system you're currently using, and you'd have the data to render it any way you want. When the VP of marketing comes looking for his numbers, a simple click would output those numbers that could be manipulated as needed from there.
I was able to accomplish what I wanted to do using wkhtmltopdf to convert my HTML page with Javascript to PDF. I ran the job via a task scheduler to supply my website url and output file name as parameters.
I then used a windows batch file to check if the file was created and then rename/email it to interested parties.
This of course requires that you have the ability to install wkhtmltopdf on your server.

Jquery Table to Excel

I want to add Excel button below the html table, that gives an Excel sheet of the table. I am using C# behind it, but I want it do on client side just using jQuery or Javascript without using PHP or .NET... Not more.
I am searching for hours however I don't find any fix solution. There it said you can use activeX object and CSV however I don't see any running examples.
ActiveX will only run on Internet Explorer so your solution will be limited to that platform.
Without ActiveX or server side scripts there is no way to achieve this due to JavaScript security designs it is not allowed to create files or push in memory files to download streams.
I would not recommend ActiveX or anything that tries to run code outside of the browser on the client system. ActiveX only works on IE not to mention the inherent security risks that brings about.
A possible method would be to use a server side script along with jquery to generate the file and return it without ever leaving the page your on. It looks good and you don't really have to jump through hoops to make it work nor will the user. (if you want an example of the jquery required to do this let me know).
For c# there is alot of tutorials on generating excel files from your data for example here.
The only reason I can think of that you would want to create the file locally is use of resources on your server. C# will be extremly efficient in generating that file not to mention there are a couple things you can do (dependant on the data) to negate any impact it has:
If the data changes are few and far between consider storing the
generated file and directing to that the next time until the data has
been changed.
Limit the data set it returns by way of a search criteria
There are plenty more optimization you could do but you get the idea.

Categories

Resources