Add a unit test for drawing images#572
Conversation
0645eb7 to
765e394
Compare
rahulporuri
left a comment
There was a problem hiding this comment.
LGTM with a few questions.
|
|
||
| if rect is None: | ||
| rect = (0, 0, img.width(), img.height()) | ||
| rect = (0, 0, pil_img.width, pil_img.height) |
There was a problem hiding this comment.
Sigh. I should've caught this in the earlier PR.
There was a problem hiding this comment.
No worries. That's what test coverage is for.
| if not any((line.endswith("fill"), | ||
| line.endswith("stroke"), | ||
| line.endswith("cliprestore"), | ||
| line.endswith("grestore"), |
There was a problem hiding this comment.
not sure what this special incantation is either.
There was a problem hiding this comment.
This is what shows up in the postscript output when you draw an image.
| # been drawn. | ||
| line = content.getData().splitlines()[-2] | ||
| if not any((line.endswith(b'f'), | ||
| line.endswith(b'Q'), |
There was a problem hiding this comment.
not sure what this special incantation is.
There was a problem hiding this comment.
This is what it in the PDF when you draw an image.
| fp = BytesIO() | ||
| pil_img.save(fp, "eps", eps=0) | ||
| self.contents.write(fp.getvalue().decode('utf8')) |
There was a problem hiding this comment.
I'm not entirely sure why we are saving the image to a BytesIO and then decoding it + writing it to self.contents - instead of saving it directly to self.contents.
Is this just best practice or is this preventing any possible issues?
There was a problem hiding this comment.
self.contents is a StringIO and Image.save will fail if you pass it in because this isn't Python 2 where you can write bytes into it. So we create a temporary BytesIO and then write it to self.contents after converting it to unicode.
There was a problem hiding this comment.
Ohh damn. So this was just straight up broken earlier and we just didn't know. Thanks!
|
Thanks for the review |
NOTE: I expect this to fail until #569 is merged. This is due to broken implementations of
draw_imagein the PS and SVG backends.