Question

Im using python turtle (Tkinter) to draw some lines which I need to export to a .jpg or .png file. To do so, I'm using python's turtle method to export my canvas to a postscript file:

pen.getcanvas().postscript(file="grafica.ps")

Where pen is just a fancy name for my turtle.

I get my .ps file, I convert it and... surprize! The image gets cut.

I tried some modifications like:

pen.getcanvas().postscript(file="grafica.ps", colormode='color', pagewidth=1600, pageheight=1200, width=1600, height=1200)

Since my turtle's window is 800x600 I thought that maybe twice as much space would be enough space to fit all the image but it still gets cut down...

I'm posting some output examples after the convertion, how my turtle's screen looks like when saving it, and how it should look exported.

Window while saving the image: enter image description here (Yes, there are sliders for the canvas)

How should it look: enter image description here

And this is what I get:enter image description here

I'm wondering how should I call postscript(), any idea?

I don't want to code this again on WxPython or other library :(

thanks!

Était-ce utile?

La solution

This is probably a problem with ImageMagick interacting with the bounding box of the EPS file. My typical workflow for .eps files on Windows may be slightly convoluted, but it works. Similar thing should work for Linux. Install GhostScript (you'll have to make sure the GhostScript executables are on your path), then use the ps2pdf utility from the command line with the -dEPSCrop option:

ps2pdf -dEPSCrop input.eps output.pdf. 

Then, use ImageMagick to convert the PDF to anything else, e.g. PNG

convert output.pdf output.png

You can control the PNG resolution etc. through ImageMagick. Like I said, convoluted, but it works.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top