Render swf to png or other image format - linux

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

Related

How to embed an MP4 inside a PDF?

I am a happy user of img2pdf. This tool does the minimal amount of work to put a series of JPEG 2000/JPEG/PNG images into a PDF "enveloppe". However I am now faced with a new challenge: embed a MP4 file into a PDF "enveloppe".
I see that commercial tool can do it, as seen at:
Add audio, video, and interactive objects to PDFs
Here is one such sample PDF file (no Flash required on windows in this sample):
https://gitlab.com/agrahn/media9/-/issues/9#note_345903962
https://gitlab.com/agrahn/media9/uploads/90fddd777e0ec514c39c924cd8d3b688/video_test.pdf
It seems to have been introduced in ISO 32000-1 (PDF 1.7 Extension Level 5)
I am looking for a solution which will use the Rich Media annotation inside the PDF stream.
There are dozen of duplicated questions on superuser/stackoverflow, which all pretty much refer to imagemagick/convert command line tool. But in my case, convert expand the images into a multi-page PDF (which is not my desired behavior):
$ convert input.mp4 output.pdf
$ pdfinfo output.pdf
Title: out
Producer: https://imagemagick.org
CreationDate: Wed Aug 19 15:38:01 2020 CEST
ModDate: Wed Aug 19 15:38:01 2020 CEST
Tagged: no
UserProperties: no
Suspects: no
Form: none
JavaScript: no
Pages: 1601
Encrypted: no
Page size: 352 x 288 pts
Page rot: 0
File size: 534407296 bytes
Optimized: no
PDF version: 1.3
with:
$ convert --version
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib
and
$ file input.mp4
input.mp4: ISO Media, MP4 Base Media v1 [IS0 14496-12:2003]
$ ffprobe -v quiet -print_format json -show_streams input.mp4 | grep codec_long_name
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
How would you embed an MP4 inside a PDF now that Flash support is being removed from Acrobat (Dec 2020) ? The solution should be on the command line (linux based system).
It was common and still possible to use Rich Media Annotation to include 3D animations or Media files within a PDF. Generally you need top end editors such as Acrobat PRO but there are a few LaTeX editor modules that some times work, thus can be PDFLaTeX compiled from Linux command line. for outdated example app see http://www.acrotex.net/blog/?cat=22 for an overflow example see https://www.overleaf.com/project/5ff76fa5686edd3e034cfedb and for prior adobe reply (but did not work for a while) see
> Embedded media, as well as referenced media outside a PDF file, may be played with a variety of player software. (In some situations, the player software may be the conforming reader itself.)
[Later comments] Adobe shot selves in foot with the poor closure of their buggy insecure SWFlash and only improved some rich media handling in more recent Windows Reader versions Acrobat DC - 21.001.20135 plus ! having turned their back on maintaining Portable Document Format Readers for Linux/Mac. What is needed is a push to use HTMLZ as ideal Rich Media Format but that would need Google Chrome to run with the bouton (pun).
Its NOT recommended except for 3D PDF as most methods require manual over-ridding security measures to STOP runtime applications within a PDF.
SWF/Flash is no longer acceptable for that reason. MicroSoft Edge (pre-chrome) made an attempt at imbedding pdf links to You Tube videos but AFAIK that was abandoned. Thus RMA pdfs can not run in more common browsers they need specialist viewers and the best viewer for Linux is possibly Okular but I cannot run that file in my version.
When opening a 3D file you need to jump through multiple hoops to allow and for floating video it may not even run. your links lead to this media example which can run inline (seen above) or better pop out with system application controls.
However in some viewers it needs to be manually exported from the pdf archive as an attachment to be run in a system media player. and for browser presentations it can be a local hyperlink like this.
Using Okular on windows it does not ask prior to running content but that could be because it found no suitable player, however it allows me to link to a local file and run that in system viewer.
For everyday presentations its easier to include the media file in a zip with the pdf or PowerPoint presentation for running locally from the pdf.
[Updated PoC for building using alternative raw mp4's]
It is possible to write a complex PDF in text on the console (Here is a 203 line example in Windows CMD), Typical output I would not normally suggest that as an answer to a highly complex structure such as Rich Media, but a simpler all platforms approach is possible with a small nip and tuck of header & trailer, plus variable mp4 body.
Source modified example spliced as 3 parts https://transfer.sh/8kQIbB/all.pdf
Different body with a small amount of command line math https://transfer.sh/Uqmv6t/all2.pdf
Method
Store the text header as a pre-set template then append the mp4 without changes finally add the PDF trailer with modified values from file lengths. too long to describe its now 216 lines (with comments and notes) and working well for PDFs in xChange as a drag and drop any 1-9 MB.mp4 (need to up that math value to 1999 MB) or send file to or CLI command for single files, but the programming can be done simply as I did using CMD or OS script and the result generated in windows with roughly scripting around
copy /b head2.bin + pixels.mp4 + tail2.bin all2.pdf /b
the secondary part is how to use text to overlay a cover image in as few lines as possible
So that is now scripted to add variable length of any video.mp4 so I simply run or drag and drop per consol and a dialog can show progress and show feedback and get inputs such as names or dimensions via mp4toPDF video.mp4 [output.pdf] so next step is user to add the caption (perhaps other scalars) as variable argument(s).
The number of PDF viewers supporting Rich Media is dwindling, I can't use Acrobat nor Edge either, so it seems I need to use Tracker (below) which is much more versatile and has many other advantages, but is Windows only.
or Cross platform Foxit. However, on Windows Foxit is way inferior with no resize or search bar or other floating controls.
So currently I can add via script and run in either edit viewer a mp4 or wmv or other video under 2GB but the field (locked aspect in Foxit) has no cover (plain white) however if I move an image over the top it seems to block out action but under white its unseen so need to resolve that transparency issue, have settled on stamp bigger white area to keep the run button visible. but having some issues with auto stamping its affecting run button even when the two are not overlapping
Breaking news, OMG, no idea which way this will help any one, other than the "Revenue Men"
Microsoft Edge’s new PDF viewer is powered by Adobe, and it won’t let you forget that. In an announcement on its website, Microsoft says it’s replacing Edge’s existing PDF viewer with one from Adobe Acrobat, which includes some “advanced” features that are available if you’re willing to pay for them.
Video controls support are disabled in Adobe Acrobat, and is not supported by web browsers. Although you want ta add video with video controls, you can use Adobe Actrobat DC Pro, and you can automatize it using Action wizard.
Check this out https://helpx.adobe.com/acrobat/using/action-wizard-acrobat-pro.html
You can make a python script to embed your video.
Thanks to pyPdf2 api, you can use the addAttachment method to embed your video.
https://github.com/mstamy2/PyPDF2

How are images shown in the terminal

Some packages like w3m-img, fim, lsix etc can be used to show the images directly on the terminal itself on linux.
I am not talking about converting the image into an ASCII character version and showing it but the image itself which looks proper without any the artifacts.
so how do these programs actually draw the images onto the terminal?
I've used Feh in the past. It should be already installed on popular Linux distributions. To use it, simply do the following:
feh your-image.jpeg

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.

How can I capture frames from X11 into a file?

I think there should be some sort of internal support on screen capture utilities with X11. So how can I capture frames from X11 frame-buffer into a file, e.g. AVI, JPEG, etc.?
Have a look at these apps:
http://xvidcap.sourceforge.net/
http://www.unixuser.org/~euske/vnc2swf/pyvnc2swf.html
If the apps don't work you can look at their source code to see how to do your own app.

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/

Resources