Ubuntu 18.04
ImageMagick 6.9.7-4 x86_64
PHP
I have some code to develop some colored blocks, but I'd like to add a bit of texture. I don't want to use a script, I just want to do it in one line. So I'm thinking just add a little noise with lowered opacity as an overlay.
The code looks like this now.
exec('convert -font Times-Bold -pointsize 24 -gravity center -fill "rgba(0,0,0,0.40)" \
\( -size 1x25 xc:#000000 \) \
\( -size 1x25 xc:#' . $this->_m->random_color() . ' \) \
\( -size 1x25 xc:#000000 \) \
\( -size 25x25 xc:#'. $dot_colors[$r1] .' -annotate +0+2 \''.$dot_txt[$r1].'\' \) \
\( -size 1x25 xc:#000000 \) \
\( -size 1x25 xc:#' . $this->_m->random_color() . ' \) \
\( -size 1x25 xc:#000000 \) \
\( -size 25x25 xc:#'. $dot_colors[$r2] .' -annotate +0+2 \''.$dot_txt[$r2].'\' \) \
\( -size 1x25 xc:#000000 \) \
\( -size 1x25 xc:#' . $this->_m->random_color() . ' \) \
\( -size 1x25 xc:#000000 \) \
\( -size 25x25 xc:#'. $dot_colors[$r3] .' -annotate +0+2 \''.$dot_txt[$r3].'\' \) \
\( -size 1x25 xc:#000000 \) \
\( -size 1x25 xc:#' . $this->_m->random_color() . ' \) \
\( -size 1x25 xc:#000000 \) \
+append /tmp/capimg.png');
How could I add a noise layer to it with say 20% opacity? Ignore the php variables, they are just arrays for color and text.
The noise or maybe plasma:fractal overlay would have to start at the top left of the created image. I assume the code would come after the append?
Thanks.
convert command with noise overlay
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: convert command with noise overlay
Assume you know the size of your output. Here is an example adding plasma fractal noise to the lena image.
You simply create a plasma image the size of your image, convert to grayscale if you want, then enable the alpha channel, then select the alpha channel, multiply by 0.2, then enable all channels. Then you composite that over your image.
If you do not know your output size, then you can just use gaussian noise
You can emulate the plasma type result if you do not know the output size, by blurring the gaussian noise example:
Note that in IM 7, you can get the size automatically, so that my first method becomes:
The +clone is needed just to get the dimensions, since the lena image was outside the parentheses. But I do -delete 0 to remove it once its dimensions have been extracted.
Code: Select all
convert lena.png \
\( -size 256x256 plasma: -colorspace gray -alpha set -channel a -evaluate multiply 0.3 +channel \) \
-compose over -composite \
lena_result.png
You simply create a plasma image the size of your image, convert to grayscale if you want, then enable the alpha channel, then select the alpha channel, multiply by 0.2, then enable all channels. Then you composite that over your image.
If you do not know your output size, then you can just use gaussian noise
Code: Select all
convert lena.png \
\( +clone -fill gray -colorize 100 +noise gaussian -colorspace gray -alpha on -channel a -evaluate multiply 0.3 +channel \) \
-compose over -composite \
lena_result2.png
You can emulate the plasma type result if you do not know the output size, by blurring the gaussian noise example:
Code: Select all
convert lena.png \
\( +clone -fill gray -colorize 100 +noise gaussian -colorspace gray -blur 0x2 -level 20x80% -alpha on -channel a -evaluate multiply 0.3 +channel \) \
-compose over -composite \
lena_result3.png
Note that in IM 7, you can get the size automatically, so that my first method becomes:
Code: Select all
magick lena.png \
\( +clone -size "%wx%h" plasma: -colorspace gray -alpha set -channel a -evaluate multiply 0.5 +channel -delete 0 \) \
-compose over -composite \
lena_result7.png
Re: convert command with noise overlay
How do I attach that to the single command above? Is lena.png a sort of temporary file convert uses, or is that supposed to be a real image I have already? Basically, I just want to add some texture to the image I am creating with the converted code I created. I figured adding noise would be the easiest way.
Re: convert command with noise overlay
Oh, ok so lena was the image you used. I guess I can add your code after my +appned maybe? I'll give that a try.
Re: convert command with noise overlay
Got it, thanks