Batik svg conversion upon click event - svg

I have a simple webpage with an editable .svg image preview which includes some text, which the user can enter via a standard html form. When they're happy and want to continue to the next step, they click the save button. Theoretically the image would then be converted into a .jpg and saved to the server.
I have just come across Batik svg to image convertor and have successfully used it from the command line, as follows...
C:\inetpub\wwwroot\batik>java -jar batik-rasterizer.jar
samples/input.svg
-d orders
-m image/jpeg
-q 0.99
-dpi 150
My question is... can this batik tool be configured to take the svg, after an onclick event (button) and then convert and save it to a specified folder? In fact, is this the right tool at all?
Any ideas or direction would be greatly appreciated.
cheers
Dec

It should work fine. You just need to deal with getting the text back to the server and updating a server copy of the SVG file. Then raster it with Batik. The first step would be best achieved with AJAX. How you do the server end depends on what sort of server you have running. If it is PHP, Python etc, the simplest way is probably to use the command line interface for Batik (as per your example). If you are running a Java web framework like Jetty or Tomcat, you could use the Batik library directly.

Related

ImageMagick issue on AppEngine Standard (PDFs and NodeJS)

I am using App Engine Standard. Since ImageMagick is available on it, I tried a few PDF manipulation libraries and basically, what I would like to do, is simply converting a PDF into an image.
The issue I am getting is this:
'convert-im6.q16: not authorized /tmp/ygM1sF-Txq00JkGbpal8YWBQ.pdf\'
# error/constitute.c/ReadImage/412.\nconvert-im6.q16: no images
defined/tmp/ygM1sF-Txq00JkGbpal8YWBQ-0.png\' #
error/convert.c/ConvertImageCommand/3258.\n' }
After some research, I found out that post here: Fix for ImageMagick convert errors with pdf files. Here is what he says:
PDF files on Linux systems are usually handled by ghostscript (via the
terminal command gs). And, ImageMagick (done through the terminal
convert command) uses ghostscript for reading and writing PDF files.
Because the security problems are serious and numerous, ImageMagick’s
access to PDF files is then cut off.
Granted, through these security flaws in PDF someone could craft a
malicious image file that, when converted by ImageMagick into a PDF,
will then do very nasty things to your computer.
But, ghostscript has since been updated once and once again with
security fixes. How about a fix for ImageMagick to get PDF
functionality back? Or, at least an explanation of progress towards
fixing this issue?
I can't change the ImageMagick configuration on App Engine Standard, but I wonder if there is something else I can do. Or maybe the engineers at Google would be able to update ImageMagick instead and remove that limitation?
I really need to convert PDF into images, so I wonder if it worth waiting, or if I need to find another solution.
Thanks for your ideas.

Convert Google Docs to Jekyll Markdown

How can I convert a Google Docs, which contains images and tables, into a Markdown file which can be published as a post using Jekyll?
Is it possible to first export the Google Docs into a PDF and then convert the PDF to Markdown? What will happen to the images and tables in that case?
May 2018 Update
The script originally suggested in this answer appears to no longer work and has not been updated for 5 years.
An alternative solution (which is based on the old script) can be found at https://github.com/evbacher/gd2md-html
I tried it out, it works pretty well.
Previous Answer
You can use a Google Script to do the conversion for you!
This one will let you convert to .md and it will email you the converted file. I've tested it and works fine. It works with basic tables, and if you have images in the doc, it will attach them to the email.
Instructions for installing are on the same link, in the GitHub description, but I pasted it here for ease of access:
Add the script:
Open your Google Drive document (http://drive.google.com)
Tools ->
Script Manager > New
Select "Blank Project", then paste this code in
and save.
Clear the myFunction() default empty function and paste the
contents of converttomarkdown.gapps into the code editor
File -> Save
Run the script:
Tools > Script Manager
Select "ConvertToMarkdown" function.
Click Run
button (First run will require you to authorize it. Authorize and run
again)
Converted doc with images attached will be emailed to you.
Subject will be "[MARKDOWN_MAKER]...".
Good luck!
You can export as HTML. Jekyll can serve static HTML files.
Btw, "standard" markdown doesn't have tables. There are implementation that have it, but I'm afraid you'll have to convert them by hand to the right format, which will be implementation dependent. I don't know about Jekyll, maybe it's easiest to just use HTML tables within the markdown text.
You could create a new theme based on the HTML export. The export should contain the stylesheet embedded in a <style> tag within the HTML document. It's not really easy to create new themes, but doable. Or, if you just want the content and don't mind using whatever Jekyll theme you already have, then you can cut out the stylesheet part and keep the html only.
Another option would be to change how files are delimited in Excel on your computer. This guide can help you do that (http://www.howtogeek.com/howto/21456/export-or-save-excel-files-with-pipe-or-other-delimiters-instead-of-commas/)
Then every time you copy and paste from excel to a markdown file/jekyll you automatically have the pipes. All you will need to do is add some dashes to separate your topline..
Google Docs -> docx to Markdown -> md
I myself looked far and wide but I believe the best way to do this is by using Pandoc.
Works for all platforms (check their incredible website ) , what you are looking for is the following command on your cmd or PowerShell (Windows) :
pandoc input_filename.docx -s -o output.md
Pro Tip:
Pandoc comes with a little trick to store up even all of the images in your document to your custom folder and then adding the image tags in the markdown by using relative referencing to those images at the correct places. The amazing line of code is:
pandoc --extract-media ./your_custom_folder input_filename.docx -o output_filename.md

Render swf to png or other image format

How can I, on linux, render a swf to a image file?
I need to be able to load other swfs into that swf and run actionscript code.
Is it even possible on linux? I need to do it from PHP, it's fine if I have to use command-line tools.
swfrender from swftools works for basic SWF files.
swfdec-thumbnailer from swfdec-gnome works though it only gets the first frame of the swf.
To get any frame from swf using swfdec see the C code snippet in the following mailing list post.
gnash from gnash also works gnash -s<scale-image-factor> --screenshot last --screenshot-file output.png -1 -r1 input.swf, last image of the swf.
ffmpeg from ffmpeg also works for some swf formats ffmpeg -i movie.swf -f image2 -vcodec png movie%d.png
Also see the following guide for a commandline pipeline.
In order to call external programs from php you use the exec command documented here.
Note that for security reasons it is important to escape arguments passed to exec with another command like escapeshellcmd or escapeshellarg for security reasons.
Once you have converted to an image format whether for single frame or all frame, you can't run action script. Other non GNU / Linux tools support the export of the action script from from SWF.
If the SWF that you are exporting to PNG is too complicated for the other tools than you can use the Flash Plugin or Gnash and Xvfb along with screen capture software to capture either image frames of the SWF or a video format like avi. Then you can extract the images from the video format.
This virtual framebuffer method will support complicated SWF files, though it requires a lot of work as you need to use either Gnash and Xvfb and Screen Capture, or a browser , Xvfb and Selenium, if you want to capture a certain set of mouse / keyboard interactions with the SWF.
Gnash with and without the Virtual FrameBuffer should load the ActionScript before exporting, but may have issues with complicated ActionScript. Flash Plugin with Virtual Framebuffer will load the ActionScript before exporting.
Also see the following StackOverFlow questions, which you question is a duplicate of
Convert SWF to PNG
Render Flash (SWF) frame as image (PDF,PNG,JPG)
SWF to image (jpg, png, …) with PHP
This is the solution I ended up using.
You can use a tool like Xvfb (X11 server) and run the standalone flash player projector inside it (you may need to install a bunch of 32-bit libraries), then use a screen capture utility like import to capture the screen and crop it to size.
I found this page on rendering swf screenshots in linux helpful. It also says that you can use gnash to do this, however gnash won't work for flash player 9+.
Try this air application http://swfrenderer.kurst.co.uk
It render swf frame by frame

generate image (e.g. jpg) of a web page?

I want to create an image what a web page looks like,
e.g. create a small thumbnail of the html + images.
it does not have to be perfect (e.g. flash /javascript rendering).
I will call use the code on linux, ideally would be some java library, but a command line tool would be cool as well.
any ideas?
Try CutyCapt, a command-line utility. It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.).
you can get it nearly perfect, and cross platform too, by using a browser plugin.
FireShot or ScreenGrab for Firefox.
6 Google Chrome Screenshot Webpage Capture Extensions
BrowserShots is an open source project that may have some code you can use.
also see:
Command line program to create website screenshots (on Linux)
Convert web page to image
How to take screenshot of whole web page, rather than what shows on the screen
What is the best way to create a web page thumbnail?
Convert HTML to an image
To take a screenshot in the terminal with ImageMagick, type the following line into a terminal and then click-and-drag the mouse over a section of the screen:
import MyScreenshot.png
To capture the entire screen and after some delay and resize it, use the following command:
import -window root -resize 400×300 -delay 200 screenshot.png
You may use a mixture of xwininfo and import to retrieve the window id of the browser and make a screenshot of that window. A bash script to automate this process would be something like this:
#!/bin/bash
window_id=`xwininfo -tree -root | grep Mozilla | awk '{print $1}'`
import -window $window_id -resize 100x100 tumb.png
This script will create a 100x100 screenshot of Firefox on the current directory under the name tumb.png
Several sources show how to run a bash script from inside a Java application, google can help you on that. If you are in a hurry, check this and this.
After reading this page, I was thinking, let me fire up midori browser: http://midori-browser.org/ and when I tried the -h option, I have seen:
-s, --snapshot Take a snapshot of the specified URI
QutyCapt is difficult to compile, and has many dependencies. Midori has it less. It outputs the PNG of the website into TMP folder. One can get the file with:
midori -s http://www.rcdwealth.com new.png 2>/dev/null | awk '{ print $4}'
After that, the file can be converted to thumbnail size by using ImageMagick's convert program.
If you're interested in Java, maybe you could look at browser automation using Selenium-RC http://seleniumhq.com
It's a little java server that you can install on the box and the program itself will execute remote commands in a web browser.
Steps like (this is pseudo code by the way, I code my Selenium in php and I can't recall 100% of the specifics off the top of my head)
selenium.location("http://foo.com")
selenium.open("/folder/sub/bar.html")
selenium.captureScreenshot("/tmp/" + this.getClass().getName() + "."
+ testMethodName + ".png");
Actually, I just did a quick websearch for the exact syntax on that last one ... and this guy has a blog with what might actually be working code in java :)
https://dev.youdevise.com/YDBlog/index.php?title=capture_screenshots_of_selenium_browser_&more=1&c=1&tb=1&pb=1
There's also a number of websites that provide this service "cross browser and OS" I just can't recall what they are. Basically they've got a cloud of every single operating system and browser combination, and they log on with each machine, take a screen and store it on their site for you to come back to in a few hours when they're done.
Ahh... another websearch and it's yours :) http://browsershots.org/

Tools for displaying text, powerpoint style, in linux

I have a problem where I need a way to display a repeating series of "images" on a computer monitor. Specifically, given a series of text files, I'd like a way to display the contents of said files on a screen in a way much like a powerpoint would.
My current thoughts are to find some tool that will take in a text file of some format, and then output an image which contains the text from the file. Then I'd put it in a directory and have some Slideshow program continuously go between the images in that directory. It's a very hacky solution, obviously.
So, does anyone know of tools that would do such a thing? Or is there a better way to do this? I've looked into the library libgd2, but it doesn't seem to support text-wrapping for images, which is something I'd need.
Thanks!
MagicPoint is a tool for displaying presentations. Presentations are written in a simple plain text file format, much like HTML.
You could easily generate the MagicPoint file automatically and then run it and display the presentation. You can also generate HTML, PS oder PDF from the presentation and display that.
Are you looking for powerpoint equivalent for linux? Openoffice??
have you tried some magic scripting with TeX?
a chain like
tex file | dvi2ps | ps2jpg > output
and define some TeX-Macros?
Showoff's pretty cool. It uses Markdown-formatted slides to create a simple little Sinatra app that you run (with showoff serve), and then view in a browser.
Docutils. See http://docutils.sourceforge.net/docs/user/slide-shows.html
The text syntax is reStructuredText
another idea:
text2gif
To complement the suggestions given by others, if you were going to write a program to do this, it would probably be more efficient to just render the text to the screen directly, rather than converting it to images first. It could probably be done using a canvas or text box component in a full-screen window on whatever window manager you are using (e.g. KDE or Gnome).
I give presentations with Opera's #media projection CSS support. On http://talks.webconverger.com/ you can find a template and an example which you can load in Opera's full screen mode and start sliding through.
So besides writing in a familiar language HTML, it's dead easy to share the slides and even get your audience to look at the slides as you're going through them.
If you are looking for something more flashy, there are tools on the Web to generate animations and what not, and again you would simply use a full screen browser to play it back to your audience.

Resources