我尝试在我触发的最后一行代码中制作一张图片:
p.corp!(0,0,p.width,black_last).save('bearbeitet.png')
但不知何故我得到了这个错误:
bild.rb:29:in `<main>': undefined method `corp!' for #<ChunkyPNG::Canvas:0x24f34
50> (NoMethodError)
为什么?公司文档: http ://rdoc.info/gems/chunky_png/ChunkyPNG/Canvas/Operations#crop-instance_method
我的整个代码:谢谢!
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')