Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Path of least resistance to JPEGs

by smiffy (Pilgrim)
on Feb 11, 2009 at 07:15 UTC ( [id://742995]=perlquestion: print w/replies, xml ) Need Help??

smiffy has asked for the wisdom of the Perl Monks concerning the following question:

The Questions

I have an application that generates a tag cloud with XHTML+CSS. This is all fine and dandy but I now need to be able to render this same tag cloud as an image.

At a pinch, I could probably render the cloud in SVG+CSS and then find a utility to convert this to JPEG, but would this be making unnecessary work for myself? Are there better methods?

The one thing I want to avoid is having to start creating graphics from first principles - I'm looking for quick'n'easy here, so any suggestions would be appreciated!

The Conclusions

Many thanks to those who have responded to this post. It appears to me that SVG is the way to start and Inkscape may be the way to continue. The main thing is to get the SVG part sorted - that's the bulk of the work for me. Then it's a case of testing various conversions from SVG to PNG, or whatever. (Thanks for the tip to avoid JPEG. I'll still use JPEG as an optional end-product because I'll be stuffing it with EXIF metadata which can be viewed when posted to Flickr.)

Unfortunately, tools like GtkMozEmbed are out of the question for web apps due to the server load. As it is, I will probably put the SVG->PNG rendering into a queue to even load rather than displaying it instantly.

Replies are listed 'Best First'.
Re: Path of least resistance to JPEGs
by Corion (Patriarch) on Feb 11, 2009 at 07:24 UTC

    If you're really talking "least resistance", I see some ways:

    • Render to SVG and then convert the SVG into a .png image using Inkscape. I've done this on Windows, and it works, as Inkscape can convert things from the command line. It might be that Inkscape wants a display even though it doesn't need it.
    • Render to a JPG image using Imager. Imager is available on Windows as a PPM, other platforms hopefully provide you with a package manager for all the prerequisite libraries.
    • Render to PostScript and use Ghostscript or ImageMagick+GhostScript to convert the PostScript to an image
    • Render to a GIF or PNG image using GD
Re: Path of least resistance to JPEGs
by bart (Canon) on Feb 11, 2009 at 09:34 UTC
    One remark: stay away from JPEG for images of text. They're inappropriate technology. Rather, use PNG or GIF. (The patent on the latter must have expired by now, hasn't it?)

    According to a Google search result, you can use Imagemagick to convert SVG files to a bitmap format.

    Imagemagick is a pretty standard tool on a lot of servers. The Perl module, PerlMagick is a bit hard to install, in my experience, but the command line tool "convert" works well from within Perl.

      (The patent on the latter must have expired by now, hasn't it?)
      Yes, it has.
      According to a Google search result, you can use Imagemagick to convert SVG files to a bitmap format.

      Last time I tried (2007 I think) that gave very poor results; maybe it's better now...

      Instead I recommend using inkscape --export-png=file.png file.svg - not very fast but always good quality - what Corion already said..

        Well, gee, I'm not convinced. So I tested it a little.

        I went looking for example SVG files, and I found the New Zealand flag on a Wikipedia like site.

        Inkscape (0.45, version of 1 year old) simply doesn't show the stars.

        SVG is the native format of Inkscape. So, what to think of it? I can't say I've ever tried to do anything with Inkscape that it didn't have some kind of trouble with.

        ImageMagick's convert performs slightly better, as it shows the top star. But only that one.

        p.s. the output file sizes from ImageMagick:

        • JPEG: 71kB
        • PNG: 19kB
        • GIF: 10kB
        • Original SVG: 3kB
        showing just how inappropriate JPEG is.

        p.p.s. your Inkscape command line simply doesn't work for me.

        update I got Inkscape to behave, on Windows. Here's what I did:

        • I upgraded to the latest version, 0.46. That one does show all the stars appropriately.
        • I made a copy of inkscape.exe to inkscape-console.exe. With exetype (comes with ActivePerl for Windows) I set its exetype to "console". That way, I can get diagnostic output from the console.
        • It turns out that Inkscape takes relative paths to be relative to the executable! not to your current directory. When I used an absolute path for the SVG file, and just a file name for the PNG file, it placed the PNG file in Inkscape's own directory. Conclusion: always use absolute paths for input and output files, at least on Windows.
        p.p.p.s. Inkscape's PNG file is 25kB, as opposed to ImageMagick's 19kB. And I find it's relatively fast. I doesn't appear to support export to the other bitmap formats.
Re: Path of least resistance to JPEGs
by gwadej (Chaplain) on Feb 11, 2009 at 13:23 UTC

    At the risk of being branded a heretic, I use the Java-based Batik rasterizer to convert SVG to PNG. The results have been consistently good.

    G. Wade
Re: Path of least resistance to JPEGs
by ruoso (Curate) on Feb 11, 2009 at 15:17 UTC

    Are you aware that you could generate that directly from html by using GtkMozEmbed? It should probably be easier than having to deal with re-generating the same thing in other technology

    daniel
Re: Path of least resistance to JPEGs
by doom (Deacon) on Feb 11, 2009 at 21:38 UTC
    I'd try a CPAN search on GraphViz (and maybe Cloud or TagCloud).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://742995]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found