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

A few bugfixes #18

Merged
merged 3 commits into from
Nov 6, 2014
Merged

A few bugfixes #18

merged 3 commits into from
Nov 6, 2014

Conversation

DarwinAwardWinner
Copy link
Contributor

These commits allow img2pdf to work on thousands of files without running out of file descriptiors, and allow it to work on unexpected colorspaces by just converting the image data to RGB. I don't know much about colorspaces or PIL, so this is probably suboptimal, but it seems to work.

This change prevents img2pdf from opening *all* input files at once,
which means it now works with thousands of input files.
Instead of crashing on an unrecognized colorspace, we now do
imgdata.convert('RGB').
@DarwinAwardWinner
Copy link
Contributor Author

This should theoretically address #6.

@josch
Copy link
Owner

josch commented Nov 6, 2014

Hi,
thanks for your pull request.

Instead of writing im = open(imfilename, "rb") could you change your pull request to instead say with open(imfilename, "rb") as im: .... As it is right now you forget to close the file. The with ... as ... idiom avoids running into this problem.

@DarwinAwardWinner
Copy link
Contributor Author

The file does get closed at the end of the loop: https://github.com/DarwinAwardWinner/img2pdf/blob/master/src/img2pdf.py#L289

I wrote it this way to minimize the diff. But I can rewrite it using with if you like.

@josch
Copy link
Owner

josch commented Nov 6, 2014

Indeed it did get closed! Nevertheless, I like the "with" option more even if it makes the diff ugly :)

josch added a commit that referenced this pull request Nov 6, 2014
Avoid leaking file descriptors and convert unrecognized colorspaces to RGB
@josch josch merged commit f881a00 into josch:master Nov 6, 2014
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

Successfully merging this pull request may close these issues.

2 participants