2

次のimageMagickコマンドは、スプライト画像を均等に分割された複数の画像にトリミングします。

convert image.png -crop 2x3-40-20@ +repage +adjoin tile-%d.jpg

ホット私はRmagickでこれを行いますか?しかし、複数のファイルを作成する代わりに、画像の配列を返す必要があります。

4

1 に答える 1

4

一度に各画像をトリミングすることで、それを成し遂げることができました。

def split_images
  #'image' is a ImageMagick Object
  width  = image.cols/number_cols
  height = image.rows/nubmer_rows
  images = []
  0.upto(number_rows-1) do |x|
    0.upto(number_cols-1) do |y|
      images << image.crop( Magick::NorthWestGravity, x*width, y*height, width, height, true)
    end
  end
end
于 2012-09-10T17:40:56.430 に答える