Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOError: [Errno cairo returned CAIRO_STATUS_WRITE_ERROR: error while writing to output stream] 11 #49

Closed
tooh opened this issue Jan 19, 2015 · 12 comments

Comments

@tooh
Copy link

tooh commented Jan 19, 2015

Environment

OSX Yosemite
System python 2.7

I'm completely new to the use of cairo. I have a case for converting svg files to png.

I found cairosvg as a suitable tool for this.

I had a lot of problems in installing cairo/py2cairo so at the end I decided to use cairocffi.

cairosvg test.svg -o test.png
Traceback (most recent call last):
  File "/usr/local/bin/cairosvg", line 25, in <module>
    cairosvg.main()
  File "/Library/Python/2.7/site-packages/cairosvg/__init__.py", line 92, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 87, in convert
    cls(tree, output, dpi).finish()
  File "/Library/Python/2.7/site-packages/cairosvg/surface/__init__.py", line 421, in finish
    self.cairo.write_to_png(self.output)
  File "/Library/Python/2.7/site-packages/cairocffi/surfaces.py", line 597, in write_to_png
    self._pointer, _encode_filename(target)))
  File "/Library/Python/2.7/site-packages/cairocffi/__init__.py", line 69, in _check_status
    raise exception(message, status)
IOError: [Errno cairo returned CAIRO_STATUS_WRITE_ERROR: error while writing to output stream] 11
@SimonSapin
Copy link
Member

@tooh Does the script have filesystem permissions to create test.png in that current directory? What happens when you run python -c 'open("test.png", "w").close()'?

@liZe, any other idea what this could be?

@tooh
Copy link
Author

tooh commented Jan 19, 2015

Can write file

==> ls *.png
test.png

@SimonSapin
Copy link
Member

Ok… let’s try a smaller test case:

import cairocffi
cairocffi.ImageSurface(cairocffi.FORMAT_ARGB32, 100, 100).write_to_png('test.png')

@tooh
Copy link
Author

tooh commented Jan 19, 2015

file test.png written

@SimonSapin
Copy link
Member

It looks like finding the root cause will unfortunately require non-trivial debugging :/ I can’t do it through github like we’ve done so far.

@liZe
Copy link
Member

liZe commented Jan 19, 2015

No idea. Could you try to use an absolute path? (something like cairosvg test.svg -o /tmp/test.png)

@tooh
Copy link
Author

tooh commented Jan 20, 2015

Same result

@mkv123
Copy link

mkv123 commented May 25, 2015

I had the exact same problem (or at least the same error message) but for what ever reason adding viewBox="0 0 800 800" to the svg element fixed it for me.

Minimal failing case:
<svg baseProfile="full" height="100%" version="1.1" width="100%" xmlns="http://www.w3.org/2000/svg"> <circle cx="50" cy="50" r="40" /> </svg>

Minimal working version:
`

``

@SimonSapin
Copy link
Member

@mkv123 Is this with CairoSVG?

@mkv123
Copy link

mkv123 commented May 25, 2015

Yes. Here's a run with the failing case:

$ cairosvg test.svg -f PNG> test.png
Traceback (most recent call last):
  File "/usr/local/bin/cairosvg", line 25, in <module>
    cairosvg.main()
  File "/usr/local/lib/python2.7/site-packages/cairosvg/__init__.py", line 93, in main
    SURFACES[output_format.upper()].convert(**kwargs)
  File "/usr/local/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 87, in convert
    cls(tree, output, dpi).finish()
  File "/usr/local/lib/python2.7/site-packages/cairosvg/surface/__init__.py", line 421, in finish
    self.cairo.write_to_png(self.output)
  File "/usr/local/lib/python2.7/site-packages/cairocffi/surfaces.py", line 594, in write_to_png
    self._pointer, write_func, ffi.NULL))
  File "/usr/local/lib/python2.7/site-packages/cairocffi/__init__.py", line 69, in _check_status
    raise exception(message, status)
IOError: [Errno cairo returned CAIRO_STATUS_WRITE_ERROR: error while writing to output stream] 11

@liZe
Copy link
Member

liZe commented May 25, 2015

The error is not really explicit in cairocffi, but CairoSVG is the culprit here. If you don't want to check for unusual strange cases (surface with a 0×0 size for example), you can safely close this bug.

@liZe liZe closed this as completed Aug 26, 2016
@kogcyc
Copy link

kogcyc commented Aug 24, 2017

Thanks, mkv123!

Adding the viewbox fixed me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants