Question

I try to corp an image how you can see in my last line of code i trigger:

p.corp!(0,0,p.width,black_last).save('bearbeitet.png')

But somehow i get this error:

bild.rb:29:in `<main>': undefined method `corp!' for #<ChunkyPNG::Canvas:0x24f34
50> (NoMethodError)

Why? The docu for corp: http://rdoc.info/gems/chunky_png/ChunkyPNG/Canvas/Operations#crop-instance_method

My whole code: Thanks!

require 'mini_magick'
require 'chunky_png'

i = MiniMagick::Image.open("a.jpg")

i.format('png')

p = ChunkyPNG::Canvas.from_io(StringIO.new(i.to_blob))

black = 0
white = 0
black_last = 0

p.height.times do |y|
  p.width.times do |x|
    if ChunkyPNG::Color.to_hex(p[x, y]) == '#ffffffff'
        white = white + 1
    else
        black = black + 1
        black_last = x
    end
  end
end

p.corp!(0,0,p.width,black_last).save('bearbeitet.png')
Was it helpful?

Solution

You misspelled crop() as corp()

Try p.crop!(0,0,p.width,black_last).save('bearbeitet.png').

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top