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

Rmagick Outputter Deprecation Warning #111

Open
panhandledoor opened this issue Apr 21, 2022 · 1 comment
Open

Rmagick Outputter Deprecation Warning #111

panhandledoor opened this issue Apr 21, 2022 · 1 comment

Comments

@panhandledoor
Copy link

I keep on getting the following warning message:

/home/alexander/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/barby-0.6.8/lib/barby/outputter/rmagick_outputter.rb:56: warning: passing a block without an image argument is deprecated

The code that this error arises from:

    #Returns an instance of Magick::Image
    def to_image(opts={})
      with_options opts do
        b = background #Capture locally because Magick::Image.new block uses instance_eval
        canvas = Magick::Image.new(full_width, full_height){ self.background_color = b }
...

My code:

require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/ascii_outputter'
require 'barby/outputter/html_outputter'
require 'barby/outputter/rmagick_outputter'

class BarcodeGenerator
  def self.generate_barcode_for_lumber_unit(lumber_unit)
    barcode = Barby::Code128B.new(lumber_unit.uuid)
    outputter = Barby::RmagickOutputter.new(barcode)
    filename = "barcode_#{DateTime.now.strftime('%Y%m%d%H%M%S%L')}.png"
    filepath = "app/assets/images/#{filename}"
    f = File.open(filepath, 'wb')
    f.write(outputter.to_png(height: 50))
    f.close

    lumber_unit.barcode.attach(io: File.open(filepath), filename:)
    lumber_unit.save!
  end
end

The line that raises this error:

f.write(outputter.to_png(height: 50))

Can anyone suggest how I might amend my code to stop raising the deprecation warning? I scrutinised the documentation here but I couldn't work it out.

@stlewis
Copy link
Contributor

stlewis commented Sep 5, 2022

@panhandledoor This isn't a you problem, it's a gem problem. I've added a PR here:

#113

That said, I'm pretty sure this gem is no longer maintained by the author, and every other fork of it I've seen is equally ghosted. For what it's worth, the deprecation warning doesn't appear to be hurting anything, so if you can live with the annoyance, you're probably fine.

Beyond that, feel free to use my fork, (which has the fix), or fork it yourself and apply the fix, blah blah blah open source, etc. 😁

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

2 participants