MiniMagick Image.create method giving an ArgumentError

℡╲_俬逩灬. 提交于 2019-12-08 05:45:32

问题


I'm creating a collage of thumbnails using Ruby 1.9.3. The thumbnails are being loaded as follows:

image1 = MiniMagick::Image.open("1.jpg")

image2 = MiniMagick::Image.open("2.jpg")
image2.rotate "-45>"

image3 = MiniMagick::Image.open("3.jpg")
image3.rotate "45>"

I've never used ImageMagick or MiniMagick before and I've got the code for compositing images from the minimagick GitHub page.

collage = MiniMagick::Image.create "jpg", false do |c|
    c.size "1024x768"
    c.canvas "white"
end

collage = collage.composite image1 do |c|
    c.gravity "center"
end

collage = collage.composite image2 do |c|
    c.gravity "east"
end

collage = collage.composite image3 do |c|
    c.gravity "west"
end

collage.write("output.jpg")

The problem is coming up on the Image.create command. When I run the file using

$ ruby prog.rb

I get the following error

/Users/vinayshenoy/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/tempfile.rb:250:in `size': wrong number of arguments (1 for 0) (ArgumentError)
from prog.rb:14:in `block in <main>'
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/mini_magick-3.4/lib/mini_magick.rb:158:in `call'
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/mini_magick-3.4/lib/mini_magick.rb:158:in `create'
from prog.rb:13:in `<main>'

The script file is the same directory as the images. I tested by writing image1, image2 and image3 to separate files and they all work. Please help.


回答1:


The error message is a bit strange, but according to the documentation at http://www.imagemagick.org/script/command-line-options.php?#composite composite only takes 3 arguments - the two images you want to combine (the image you create in line 1 and the one called image 1), plus a gray scale 'mask' (image2 in this case).

In other words, it seems like you'll have to save after every single one of the three compositions.



来源:https://stackoverflow.com/questions/9495026/minimagick-image-create-method-giving-an-argumenterror

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