ImageMosaic
ImageMosaic takes an array of images and returns a collage of the images in a grid format.
Installation
ImageMosaic requires ImageMagick to be installed.
OSX
$ brew install imagemagick
Linux
$ sudo apt-get install imagemagick
Add this line to your application's Gemfile:
gem 'image_mosaic'
And then execute:
$ bundle
Or install it yourself as:
$ gem install image_mosaic
Usage
Create an image from an array of image URLs.
The size of each piece of the final image and the number of columns and rows will vary depending on how many images are provided.
Note: the final image is fixed to 1000x1000 pixels with a white background.
An instance of a Mosaic
object is returned, calling save
on this will save the image to the filesystem with a random name.
images = (0..20).map { 'https://unsplash.it/200/200?random' }
mosaic = ImageMosaic.create(images)
mosaic.save
mosaic.filename
=> "mosaic_9ebfcb8c-b554-4748-9b2e-3d4eb7b8f2b0.png"
If you want to retrieve the instance of MiniMagick::Image
behind and manipulate it further you can.
images = (0..20).map { 'https://unsplash.it/200/200?random' }
mosaic = ImageMosaic.create(images)
mosaic.image
=> #<MiniMagick::Image:0x007fbfb2a6b868 @path="/var/folders/7g/7wdhmvx96856frwy0jf78rsr0000gn/T/mini_magick20170426-64311-eom10b.png", @tempfile=#<Tempfile:/var/folders/7g/7wdhmvx96856frwy0jf78rsr0000gn/T/mini_magick20170426-64311-eom10b.png (closed)>, @info=#<MiniMagick::Image::Info:0x007fbfb2a6b818 @path="/var/folders/7g/7wdhmvx96856frwy0jf78rsr0000gn/T/mini_magick20170426-64311-eom10b.png", @info={}>>
Background Colour
The default background colour is white, background colour can be specified as a valid hex code (with preceeding #). If an invalid code is provided the background will be white.
ImageMosaic.create(images, colour: '#00ff00')
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/dannyguk/image_mosaic.
License
The gem is available as open source under the terms of the MIT License.