Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMagick torn edges

I'm trying to create a torn edge effect in RMagick. Is there a filter similar to photoshop's crystallize?

Also, I found this ImageMagick code that does it here http://www.imagemagick.org/Usage/thumbnails/#torn:

  convert thumbnail.gif \
      \( +clone -alpha extract -virtual-pixel black \
         -spread 10 -blur 0x3 -threshold 50% -spread 1 -blur 0x.7 \) \
      -alpha off -compose Copy_Opacity -composite torn_paper.png

However, I don't understand any of it. Can anyone provide some advice?

like image 874
mlstudent Avatar asked Nov 17 '25 17:11

mlstudent


1 Answers

This command does two main things: create a mask with that torn-paper effect, apply the mask to the image. It does them, fancily, in one line, by using +clone and the parentheses. It's less confusing to do it as two commmands though:

convert thumbnail.gif \
        -alpha extract \
        -virtual-pixel black \
        -spread 10 \
        -blur 0x3 \
        -threshold 50% \
        -spread 1 \
        -blur 0x.7 \
        mask.png

convert thumbnail.gif mask.png \
        -alpha off \
        -compose Copy_Opacity \
        -composite torn_paper.png

The first command is fairly complex. But you can find decent explanations of each of the component commands in the ImageMagick docs:

  • http://www.imagemagick.org/Usage/masking/#alpha_extract
  • http://www.imagemagick.org/Usage/misc/#virtual_examples
  • http://www.imagemagick.org/script/command-line-options.php#blur

Also, by splitting the command into these two pieces, you can see what the mask looks like on its own. It's basically the inverse of the paper effect. White throughout the middle of the images, fading to black around the "torn edges".

The second command is a lot more straightforward. Copy_Opacity, as described in the ImageMagick docs, is a way of making parts of an image transparent or not. Anything that's black in the mask will be made transparent in the resulting image. In effect, the second command uses the mask to "erase" the edges of the original thumbnail in a stylistically interesting way.

like image 119
Jim Lindstrom Avatar answered Nov 19 '25 05:11

Jim Lindstrom