Page 1 of 2

Rubber Stamp Effect

Posted: 2011-12-29T13:17:43-07:00
by sethm
I'm trying to achieve the following affect:
http://graphicssoft.about.com/od/photos ... amp-PS.htm

Here's what I have so far... it takes about 26 seconds to run (maybe I just have a slow processor)

Code: Select all

 convert -font "DejaVu-Sans-Mono-Book" -pointsize 72 -fill red -bordercolor white -border 10x10 label:"STAMP"  under.png
 convert under.png -bordercolor red -border 10x10 under.png
 convert under.png xc: +noise Random -channel R -threshold 1% -channel RG -separate +channel \( +clone \) -compose multiply -flatten -virtual-pixel tile -blur 0x.4 -contrast-stretch .8% mask.png
 convert under.png mask.png -alpha Off -compose CopyOpacity -composite -rotate -15 stamp-DejaVu-Sans-Mono-Book.png
 
Two bits of help:
1. Any way to do this faster in fewer steps?
2. How can I adjust the text to appear in the center of the box? (this I kind of got... I can add a -gravity south in the first step)
3. How to get beveled corners on the border?
4. have the entire image be a transparent png?

Thanks!

Re: Rubber Stamp Effect

Posted: 2011-12-29T14:12:48-07:00
by fmw42
Here is one way. I created my own as I don't have your font. So this is a similar example. You can change the sizes and other parameters to suit. The blur controls the size of the spots, the threshold controls the number of spots and the fuzz value is needed to make sure no white bleeds through.


convert \( -size 600x200 -background white -gravity center \
-fill red -font Arial -pointsize 128 label:"STAMP" \
-fill none -stroke red -strokewidth 10 \
-draw "translate 300,100 roundrectangle -250,-75 250,75 20,20" \) \
\( -size 600x200 xc: +noise random -channel g -separate +channel \
-blur 0x2 -threshold 55% -transparent black \) \
-compose over -composite -fuzz 10% -transparent white stamp.png


Here is another way. This one uses a transparent background for the box and letters. The creates the noise image as before (but negated). Then composites the noise image with the alpha channel of the box and letters image. Then replaces the box and letters alpha channel with the new composited alpha channel. Thus no fuzz factor is involved.


convert \( -size 600x200 -background none -gravity center \
-fill red -font Arial -pointsize 128 label:"STAMP" \
-fill none -stroke red -strokewidth 10 \
-draw "translate 300,100 roundrectangle -250,-75 250,75 20,20" \) \
\( -size 600x200 xc: +noise random -channel g -separate +channel \
-blur 0x2 -threshold 55% -negate \) \
\( -clone 0 -alpha extract -clone 1 -compose multiply -composite \) \
-delete 1 -alpha off -compose copy_opacity -composite stamp2.png

Re: Rubber Stamp Effect

Posted: 2016-02-10T12:28:17-07:00
by atariZen
That's quite useful. I'm trying to take the idea further, and apply the rubber stamp to an existing image (which is likely to be a common use case). So this applies the rubber stamp to the logo, and rotates it 90 degrees and puts it on the right:

Code: Select all

   convert \( -size 500x200 -background white -gravity center \
	    -fill red -font Arial -pointsize 128 label:"STAMP" \
	    -fill none -stroke red -strokewidth 10 \
	    -draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
	    \( -size 500x200 xc: +noise random -channel g -separate +channel \
	    -blur 0x2 -threshold 55% -transparent black \) \
	    -compose over -composite -fuzz 10% -transparent white\
	    -rotate 90 -gravity east magick:logo +swap -composite show:
(i wish I could use color in the code section, to highlight what I've changed). I added the bottom line. My question is, what if I want to add an image to the left of the stamp? This is my attempt at adding a rose:

Code: Select all

   convert \( -size 500x200 -background white -gravity center \
	    -fill red -font Arial -pointsize 128 label:"STAMP" \
	    -fill none -stroke red -strokewidth 10 \
	    -draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
	    \( -size 500x200 xc: +noise random -channel g -separate +channel \
	    -blur 0x2 -threshold 55% -transparent black \) \
	    -compose over -composite -fuzz 10% -transparent white -append magick:rose\
	    -rotate 90 -gravity east magick:logo +swap -composite show:
Doesn't work. I was expecting the rubber stamp was followed by "-append magick:rose" to have the effect of montage, thus attach a rose below the rubber stamp, before the whole thing is rotated 90 degrees and put on the logo.

What is wrong with my use of -append?

Re: Rubber Stamp Effect

Posted: 2016-02-10T15:24:49-07:00
by fmw42
For one thing, your backslashes at the ends of the line MUST have spaces before them and no spaces after them.

You do not say where you want to add the rose image.

But start with this:

Code: Select all

convert \( -size 500x200 -background white -gravity center \
-fill red -font Arial -pointsize 128 label:"STAMP" \
-fill none -stroke red -strokewidth 10 \
-draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
\( -size 500x200 xc: +noise random -channel g -separate +channel \
-blur 0x2 -threshold 55% -transparent black \) \
-compose over -composite -fuzz 10% -transparent white \
-rotate 90 -gravity east magick:logo +swap -composite \
-gravity northwest magick:rose -geometry +50+50 -composite \
show:
Note you can specify the rose: and logo: images with a colon after them as stated here rather than prefacing with magick:rose and magick:logo

Re: Rubber Stamp Effect

Posted: 2016-02-11T12:01:28-07:00
by atariZen
fmw42 wrote:For one thing, your backslashes at the ends of the line MUST have spaces before them and no spaces after them.
Actually the shell simply deletes all occurrences of "\" followed by newline. The space is needed whenever the tokens on either side of it cannot be joined, but the space can appear either before the backslash, or at the beginning of the next line. But if you find the trailing blank more readable, I will stick with that.
fmw42 wrote: You do not say where you want to add the rose image.
I want the rose to be placed immediately below the rubber stamp. Then I want that whole joined piece to be rotated 90 degrees and then put on the far right of the background logo, as a composite.

I'm struggling with just the simple first step. If I forget about the background and rotating, so that I'm only placing the rose below the stamp, I can't even get that much to work. My first attempt was to use montage, like this:

Code: Select all

montage \( -size 500x200 -background white -gravity center \
	    -fill red -font Arial -pointsize 128 label:"STAMP" \
	    -fill none -stroke red -strokewidth 10 \
	    -draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
	    \( -size 500x200 xc: +noise random -channel g -separate +channel \
	    -blur 0x2 -threshold 55% -transparent black \) \
	    -compose over -composite -fuzz 10% -transparent white \
	    rose: show:
That error'd as "montage: unrecognized option `+noise' @ error/montage.c/MontageImageCommand/1268." So then I went back to convert, and tried to use append, like this:

Code: Select all

convert \( -size 500x200 -background white -gravity center \
	    -fill red -font Arial -pointsize 128 label:"STAMP" \
	    -fill none -stroke red -strokewidth 10 \
	    -draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
	    \( -size 500x200 xc: +noise random -channel g -separate +channel \
	    -blur 0x2 -threshold 55% -transparent black \) \
	    -compose over -composite -fuzz 10% -transparent white \
	    -append rose: show:
The rose was neglected in that rendering.

*edit* I see my problem with append.. the "-append" must come after the rose:.

In your example, you use "-composite" to place the rose with hard-coded positioning. I want to avoid that, because conceptually I want to glue two things together, and then treat that whole object as one thing. I hope that I can escape some of the coordinate+offset chaos by defining building blocks that can grow and become part of other building blocks.

I think the best code avoids literal sizes and literal positions as much as possible, and uses relative data as much as possible. Numbers get under my skin.

Anyway, this is closer to the complex thing I'm after:

Code: Select all

   convert \( \( -size 500x200 -background white -gravity center \
	    -fill red -font Arial -pointsize 128 label:"STAMP" \
	    -fill none -stroke red -strokewidth 10 \
	    -draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
	    \( -size 500x200 xc: +noise random -channel g -separate +channel \
	    -blur 0x2 -threshold 55% -transparent black \) \
	    -compose over -composite -fuzz 10% -transparent white \) \
	    magick:rose -append -rotate 90 -gravity east magick:logo +swap -composite show:
My next problem is making the background of the rose transparent.
fmw42 wrote: Note you can specify the rose: and logo: images with a colon after them as stated here rather than prefacing with magick:rose and magick:logo
The documentation said "logo:" exists for "backwards compatibility", so I took that to mean that "magick:logo" might obsolete the other style. But I don't mind using the shorter form.

Re: Rubber Stamp Effect

Posted: 2016-02-11T12:21:34-07:00
by snibgo
"-append" will replace all images that are currently in the list by one image, which is all those images appended together. At that stage in your command, there is only one image in the list, so "-append" has no effect.

"rose": adds a new image to the list. So then the list has two images, so the output has two images.

Re: Rubber Stamp Effect

Posted: 2016-02-11T12:36:00-07:00
by atariZen
Thanks snibgo. I just caught that. It's interesting that the output can have two images.. I didn't realize that!

Re: Rubber Stamp Effect

Posted: 2016-02-11T12:38:56-07:00
by atariZen
I've also just fixed the rose background problem. This is the final product I was going for:

Code: Select all

    convert \( -size 500x200 -background white -gravity center \
	    -fill red -font Arial -pointsize 128 label:"STAMP" \
	    -fill none -stroke red -strokewidth 10 \
	    -draw "translate 250,100 roundrectangle -220,-75 220,75 20,20" \) \
	    \( -size 500x200 xc: +noise random -channel g -separate +channel \
	    -blur 0x2 -threshold 55% -transparent black \) \
	    -compose over -composite -fuzz 10% -transparent white \
            \( magick:rose -background transparent \) \
	    -append -rotate 90 -gravity east wizard: +swap -composite show:
Now to polish the code, there must be a way to remove some of those numbers.

The 500x200 is apparently needed, because the "wizard:" background is mentioned after the rubber stamp. Swapping the order and then getting rid of the "+swap" doesn't work.

Re: Rubber Stamp Effect

Posted: 2016-02-11T15:13:01-07:00
by fmw42
You need the +swap since composite requires the background image to first in the command line and the overlay image second.

Re: Rubber Stamp Effect

Posted: 2016-02-12T11:31:06-07:00
by atariZen
fmw42 wrote:You need the +swap since composite requires the background image to first in the command line and the overlay image second.
Thanks for making that clear. And I suppose being forced to put the background image last means the background cannot be a basis to size the other objects, correct?

There are more problems when stacking a stamp on top of a rose, then on top of another stamp. The background of the rose is white when it should be transparent, and the lower stamp changes fonts, even when Arial is specified. Here is a sample:

Code: Select all

      convert \( \( -size 500x200 -background white -gravity center \
                    -fill red -font Arial -pointsize 128 label:Top \
                    -fill none -stroke red -strokewidth 10 \) \
                 \( -size 500x200 xc: +noise random -channel g -separate +channel \
                    -blur 0x2 -threshold 55% -transparent black \) \
                 -compose over -composite -fuzz 10% -transparent white \) \
              \( -background transparent rose: \) \
              \( \( -size 500x200 -background white -gravity center \
                    -fill red -font Arial -pointsize 128 label:bottom \
		    -fill none -stroke red -strokewidth 10 \) \
	         \( -size 500x200 xc: +noise random -channel g -separate +channel \
	            -blur 0x2 -threshold 55% -transparent black \) \
	         -compose over -composite -fuzz 10% -transparent white \) \
	      -append show:
Result: Image (note that the black is actually transparent - not sure why the file is not displayed correctly here)

Are these bugs, or am I doing something wrong?

BTW, I really appreciate everyones help so far.

Re: Rubber Stamp Effect

Posted: 2016-02-12T12:15:14-07:00
by snibgo
The layout of a complex command is a personal thing. I like to break into logical units, with indentation reflecting the level of parentheses. This helps me understand code, especially months after I first wrote it.

When I do this, I see you apply "-background transparent" to "rose:". This has no effect on the rose. This background setting is quickly overwritten by "-background white". You want the transparent background setting to apply to the append, like this:

Code: Select all

convert \
  \( \
    \( -size 500x200 -background white -gravity center \
       -fill red -font Arial -pointsize 128 label:Top \
       -fill none -stroke red -strokewidth 10 \) \
    \( -size 500x200 xc: \
       +noise random \
       -channel g -separate +channel \
       -blur 0x2 \
       -threshold 55% -transparent black \) \
    -compose over -composite \
    -fuzz 10% -transparent white \
  \) \
  \( rose: \) \
  \( \
    \( -size 500x200 -background white \
       -gravity center \
       -fill red -font Arial -pointsize 128 label:bottom \
       -fill none -stroke red -strokewidth 10 \) \
    \( -size 500x200 xc: \
       +noise random \
       -channel g -separate +channel \
       -blur 0x2 \
       -threshold 55% -transparent black \) \
    -compose over -composite \
    -fuzz 10% -transparent white \
  \) \
  -background transparent -append \
  show:

Re: Rubber Stamp Effect

Posted: 2016-02-12T12:22:59-07:00
by snibgo
This layout exposes other oddities in your command. You do "-stroke red -strokewidth 10" twice, so you must really want it, but what do you want stroked? The only items in your command capable of being stroked is the labels, also two.

But you set the stroke after the first label and after the second. So the first label is stroked, and the second isn't.

Either remove these settings, or move them both before the labels, or just have one at the top.

Re: Rubber Stamp Effect

Posted: 2016-02-12T13:18:19-07:00
by atariZen
snibgo wrote:The layout of a complex command is a personal thing. I like to break into logical units, with indentation reflecting the level of parentheses. This helps me understand code, especially months after I first wrote it.
Agreed. I had sensible indentations in emacs, but the copy into here botched it. I should clean that up when it happens.
snibgo wrote: When I do this, I see you apply "-background transparent" to "rose:". This has no effect on the rose. This background setting is quickly overwritten by "-background white".
I find this disturbing, because I was expecting the parenthesis to create a scope whereby the settings don't influence an outer scope.

I see that background is listed as an "image setting", meaning that it persists "until reset". But that still seems to imply that backgrounds affect the images that are listed before the background is reset. E.g. if i have <image> -background red <image> -background green <image> -background blue <image>, it would be intuitive for the first two images to be red, the 3rd one green, and the last one blue.

Are backgrounds something that should be read from right to left, to know which images they apply to?
snibgo wrote: You want the transparent background setting to apply to the append, like this:
I'm a little astonished, because append is an operation (not an image), so to have a background setting apply to an operation seems to complicate the syntax. It's hard to understand how an append operation would have background as a parameter.
snibgo wrote:This layout exposes other oddities in your command. You do "-stroke red -strokewidth 10" twice, so you must really want it, but what do you want stroked? The only items in your command capable of being stroked is the labels, also two.

But you set the stroke after the first label and after the second. So the first label is stroked, and the second isn't.

Either remove these settings, or move them both before the labels, or just have one at the top.
Now that my idea of thinking of parenthesis as scope to limit settings is destroyed, I can see how one affected the other. I actually didn't even know what stroke was.. I just had it in there because the OP designed it that way. After eliminating stroke and strokewidth completely, the fonts are as expected.

After re-reading the image stack docs, it's clear that the parenthesis are not controlling as much as I would expect. This also gives me the idea that maybe it's a good idea to try to put anything that is not an image operator outside the parenthesis, so I don't later get the false expectation that the parenthesis limits something it doesn't.

Thanks for help!

Re: Rubber Stamp Effect

Posted: 2016-02-12T13:52:18-07:00
by snibgo
In v6, parentheses do not determine the scope of settings, unless you precede them with "-respect parentheses". The purpose of parentheses is: "(" sets aside the current image list, and starts a new temporary list; ")" closes the nested list, moving any images in that list to the end of the outer list.

The "-background" setting is attached as metadata to following images, but in most cases it doesn't modify the image itself. (Notable exceptions are vector files like PDF and SVG.) It doesn't change raster (pixel) images.

Most settings (like "-background") affect operations, not images. Most operations (like "-append") affect images, but the nature of the operation is influenced by settings.

In your case, you have a large image, a small image, and another large image. When these are appended vertically, the result has pixels that that didn't come from any input. These are populated with the background.

Personally, I usually put settings immediately before the operations they affect.

Commands should always be written in logical, chronological order. Do this, then do that, then do something else. Put settings before the operators they should affect, and so on.

Re: Rubber Stamp Effect

Posted: 2016-02-12T14:31:35-07:00
by fmw42
Just a further note, even with -respect parentheses, some settings are not restricted to the parenthesis. For example, certain compose settings in the parenthesis can affect operators such as -flatten outside the parenthesis. So I always add -compose over before -flatten. I am not sure but -gravity may also not be restricted to the parentheses. This is in IM 6. I am not sure about IM 7