Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How do you export a Tk canvas without postscript?

by LivelyHound (Initiate)
on Nov 08, 2001 at 15:42 UTC ( [id://124043]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I am trying to export a Tk Canvas into either a gif or a jpeg. As far as I can see you have to save the image to a postscript file and then have that converted.
Does anybody know a better way? and if not, is there an easy way to convert from the postscript to another format?

LivelyHound
  • Comment on How do you export a Tk canvas without postscript?

Replies are listed 'Best First'.
Re: How do you export a Tk canvas without postscript?
by jeroenes (Priest) on Nov 08, 2001 at 16:19 UTC
    I was tempted to answer your question with cat /dev/mem > exported_canvas but I got a hold of myself :^P.

    What you want is ghostscript and/or ImageMagick.

Re: How do you export a Tk canvas without postscript?
by clintp (Curate) on Nov 08, 2001 at 19:18 UTC
    I asked this a while back on comp.lang.perl.tk, and as it turns out there's not an easy answer. As I understand it now, there's no bitmap representation of the canvas anywhere: it's drawn on the fly.

    Postscript is used because the same kinds of commands that can be used to draw on the canvas can be used to render postscript. (Postition HERE, put character THERE, draw line from HERE to THERE, put a bitmap over THERE, etc...)

    Two techniques come to mind:

    • (preferable) Capture it in Postscript, and use ghostscript to covert to a bitmap representation. I've had luck using this. Something like:
      gs -dNOPAUSE -sDEVICE=jpeg -sOutputFile=foo.jpg foo.ps
      Should work okay.
    • It might be possible to "scrape" it off the screen directly with a screen capture tool that has a command-line interface. The physical location of the canvas can be computed (you know where the window is, you know where the canvas is in the window, where's the canvas on the screen?) and that might be enough info. Haven't tried this and it sounds messy. But will work. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://124043]
Approved by root
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: (4)
As of 2024-04-23 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found