Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for Paperclip to generate a new image (with no source)?

I'm building an image based off of user input -- the background will either be an image or a color, and then a few other images may or may not be composed on top.

Checking through the paperclip docs, it mentions that you can use ImageMagik to post-process images, and that post-processing will never fire if it doesnt already have an image.

If I am able to make the imagemagik scripts to compose/color/resize an image, is there a way for it to generate the image, or will I need to include some sort of hackish pixel to upload (and then postprocess in to the image I want)?

like image 728
Mike Manfrin Avatar asked Jul 17 '15 00:07

Mike Manfrin


2 Answers

ImageMagick can generate a starting image for you, consisting of a simple rectangle filled with a single color. For example, this will generate a 150x100 red image:

convert -size 150x100 xc:"#ff0000" starting_image.png
like image 135
Glenn Randers-Pehrson Avatar answered Sep 22 '22 13:09

Glenn Randers-Pehrson


I would try the following:

  • Have a default image in my app's assets folder
  • If the model to be saved has no attachment then I would assign it the one mentioned above: a_model.image = File.open('...')
  • Then, upon save of the a_model the post-processing should take place normally
like image 45
Lazarus Lazaridis Avatar answered Sep 22 '22 13:09

Lazarus Lazaridis