Corp image with ruby

微笑、不失礼 提交于 2019-12-13 08:51:03

问题


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')

回答1:


You misspelled crop() as corp()

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



来源:https://stackoverflow.com/questions/20401968/corp-image-with-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!