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

Close opened image files #31

Merged
merged 1 commit into from
Feb 29, 2020
Merged

Close opened image files #31

merged 1 commit into from
Feb 29, 2020

Conversation

hidakatsuya
Copy link
Owner

@hidakatsuya hidakatsuya commented Feb 29, 2020

This PR fixes #29. See description of #29 for details.

require 'prawn/emoji'

Prawn::Document.generate 'sushi.pdf' do
  font 'DejaVuSans.ttf'
  text '🐟 / 🔪 + 🍚 / 🍾 = 🍣'
end

ObjectSpace.each_object(File) do |f|
  puts "%s: %d" % [f.path, f.fileno] unless f.closed?
end

DejaVuSans.ttf: 26
prawn-emoji-3.1.0/emoji/images/1f35a.png: 29
prawn-emoji-3.1.0/emoji/images/1f37e.png: 30
prawn-emoji-3.1.0/emoji/images/1f363.png: 31
prawn-emoji-3.1.0/emoji/images/1f41f.png: 27
prawn-emoji-3.1.0/emoji/images/1f52a.png: 28

prawn-emoji just passes the path of image file to Prawn#image method but not open image file.

@document.image image.path, at: [x, y], width: image.width

Image files are opened by prawn. See prawnpdf/prawn#975 for details. This issue has been already fixed by prawnpdf/prawn#1090, but not released yet.

The GC should close the file, but fix it so that it explicitly closes the file.

@hidakatsuya hidakatsuya self-assigned this Feb 29, 2020
Prawn 2.2 does not close the image file when Pathname is passed to Document#image method.
@hidakatsuya hidakatsuya added the bug Something isn't working label Feb 29, 2020
@hidakatsuya hidakatsuya merged commit 601351d into master Feb 29, 2020
@hidakatsuya hidakatsuya deleted the close_opened_image_files branch February 29, 2020 19:34
@aried3r aried3r mentioned this pull request Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should draw_image close the file descriptor?
1 participant