ruby on rails - Rmagick composite image without source -
i have gallery model , post model. each post has image, , create composite image each gallery based on posts in gallery. have method galleries returns urls top 4 images in gallery:
gallery.images_for_preview # => returns array of 4 image urls (200x200 images)
i'm using carrierwave + rmagick generate composite image. i'm trying follow along here: http://railscasts.com/episodes/374-image-manipulation seems use case different. have:
class galleryimageuploader < carrierwave::uploader::base ... def store_dir "galleries/#{model.obfuscated_id}" end version("full") { process :full_image } def full_image images = model.images_for_preview puts images manipulate! format: "png" image0 = magick::image.read(images[0]).first image1 = magick::image.read(images[1]).first image2 = magick::image.read(images[2]).first image3 = magick::image.read(images[3]).first underlay = magick::image.new(406, 406) { self.background_color = "#333333" } underlay.composite!(image0, 2, 2, magick::overcompositeop).composite!(image1, 204, 2, magick::overcompositeop).composite!(image2, 2, 204, magick::overcompositeop).composite!(image3, 204, 204, magick::overcompositeop) end end
the full_image operation doesn't require source file, way can seem generate composite image like:
gallery.remote_image_url = "path/to/image"
which generates image need @ /galleries/:id/full_image.png
processes , generates image @ /galleries/:id/image.png
is possible skip "source" image , generate composite, upload imageuploader's primary image?
yes, process data on go, no need version itself:
replace line:
version("full") { process :full_image }
with one
process :full_image
Comments
Post a Comment