Skip to content

Rmagick Outputter Deprecation Warning #111

Description

@panhandledoor

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions