Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

WOODGRAIN


Simulates a woodgrain texture.

Download Script

last modified: June 02, 2015



USAGE: woodgrain [-p process] [-d dimensions] [-m maincolor] [-g graincolor]
[-t thickness] [-e elongation] [-D densities] [-I intensities] [-c curviness]
[-w wiggles] [-n newseeds] [-a amplify] [-s sharpen] [-r rotation]
[-B brightness] [-S saturation] [-H hue] outfile

USAGE: woodgrain [-help or -h]

-p ... process ....... processing method; choices are 1 or 2; 1 is 1D expand
...................... and 2 is motion blur; default=1
-d ... dimensions .... dimensions of the output image; integers>0;
...................... WIDTHxHEIGHT; default=300x300
-m ... maincolor ..... main (background) color of image; any valid opaque IM
...................... color; default=burlywood
-g ... graincolor .... grain (foreground) color of image; any valid opaque IM
...................... color; default=tan4
-t ... thickness ..... thickness of coarse grain texture; integer>0; default=1
-e ... elongation .... elongation of grain texture; integer>0; default=30
-D ... densities ..... densities for coarse and fine grain textures;
...................... comma separate integers>0; COARSE,FINE densities;
...................... default=50,50
-I ... intensities ... intensities for coarse and fine grain textures;
...................... comma separate integers>0; COARSE,FINE intesities
...................... default=0,1
-c ... curviness ..... curviness of coarse grain texture; integer>=0;
...................... default=5
-w ... wiggles ....... wiggles of coarse grain texture; integer>=0;
...................... default=5
-n ... newseeds ...... new seed values for coarse and fine grain textures;
...................... comma separate integers>0; COARSE,FINE,NOISE texture
...................... seeds; default=100,200,300
-a ... amplify ....... amplification factor for added noise;
...................... float>=0; default=2
-s ... sharpen ....... sharpening of grain textures; integer>=0; default=5
-r ... rotation ...... rotation of texture pattern; 0<=integer<=360;
...................... default=0
-B ... brightness .... brightness factor for output image; integer>=0;
...................... default=100 (nominal value)
-S ... saturation .... saturation factor for output image; integer>=0;
...................... default=100 (nominal value)
-H ... hue ........... hue factor for output image; integer>=0;
...................... default=100 (nominal value)

PURPOSE: To simulate a woodgrain texture.

DESCRIPTION: WOODGRAIN simulates a woodgrain texture. The user may control main (background) and grain (foreground) colors, coarse grain thickness, elongation, density, curviness and other factors. The newseed values allow the grain patterns to change.

ARGUMENTS:

-p process ... PROCESS is the processing method. Choices are 1 or 2. 1 is using 1D expand and 2 is using motion blur. The results are different but comparable. Method 2 is faster, especially when rotations are involved. The default=1

-d dimensions ... DIMENSIONS of the output image. Values are "x" separated integers>0 in the form of WIDTHxHEIGHT (with no spaces). The default=300x300

-m maincolor ... MAIN (background) COLOR of the texture image. Any valid opaque IM color is allowed. The default=burlywood.

-g graincolor ... GRAIN (foreground) COLOR of the texture image. Any valid opaque IM color is allowed. The default=tan4.

-t thickness ... THICKNESS of the coarse grain texture. Values are integers>0. The default=1.

-e elongation ... ELONGATION of grain texture. Values are integers>0. The default=30.

-D densities ... DENSITIES for coarse and fine grain textures. Values are comma separate integers>=0 in the form COARSE,FINE (densities). (with no spaces). The default=50,50. Note a fine density of 0 will disable any fine grain texture.

-I intensities ... INTENSITIES for coarse and fine grain textures. Values are comma separate integers>=0 in the form COARSE,FINE (intensities) (with no spaces). The default=0,1. Note a fine intensity of 0 will disable any fine grain texture.

-c curviness ... CURVINESS of coarse grain texture. Values are integers>=0. The default=5.

-w wiggles ... WIGGLES are the wiggle amount of the coarse grain texture. Values are integers>=0. The default=5.

-n newseeds ... NEWSEEDS are the new seed values for coarse grain, fine grain and noise textures. Values are comma separate integers>=0 in the form COARSE,FINE,NOISE (seeds) (with no spaces). The default=100,200,300. Note that changing these values causes the grain patterns to change. However, using the same value for all three newseeds should be avoided.

-a amplify ... AMPLIFY is the amplification factor for added noise texture. Values are floast>=0. The default=2. Note a value of zero will disable any noise added to the texture.

-s sharpen ... SHARPEN is the sharpening of the grain textures. Values are integers>=0. The default=5.

-r rotation ... ROTATION of the texture pattern. Values are 0<=integer<=360. The default=0.

-B brightness ... BRIGHTNESS factor for the output image. Values are integers>=0. The default=100 (nominal value).

-S saturation ... SATURATION factor for the output image. Values are integers>=0. The default=100 (nominal value).

-H hue ... HUE factor for the output image. Values are integers>=0. The default=100 (nominal value).

NOTE: Results cannot be tiled without special processing.

REFERENCES:
http://www.myinkblog.com/creating-a-realistic-wood-texture-using-photoshop/
http://www.tutorial9.net/tutorials/photoshop-tutorials/custom-wood-texture-in-adobe-photoshop/
http://www.youtube.com/watch?v=_BfQ7IjWt_4
http://www.youtube.com/watch?v=dyaGb6SK7Cw&feature=relmfu
http://www.youtube.com/watch?v=gEkqe6_ZSFk

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Example 1 - Variations in Colors

Arguments:
-m bisque -g tan4

Arguments:
-m bulywood -g tan4

Arguments:
-m peachpuff -g darkorange4

Arguments:
-m peru -g darkorange4

Arguments:
-m "rgb(240,190,57)" -g tan4

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97



Example 2 - Variations in Thickness

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -t 1

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -t 3



Example 3 - Variations in Elongation

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -e 30 -c 5

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -e 10 -c 3



Example 4 - Variations in Curviness and Wiggles

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -c 5 -w 5

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -c 5 -w 10

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -c 10 -w 5

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -c 10 -w 10



Example 5 - Variations in Intensity

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -i 0,1

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -i 3,1



Example 6 - Variations in Seeds

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -n 100,200,300

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -n 1000,2000,3000



Example 7 - Variations in Rotation

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -r 0

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -r 20



Example 8 - Disable Fine Grain

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -D 50,50

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -D 50,0



Example 9 - Disable Fine Grain and Disable Noise

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -D 50,50 -a 2

Arguments:
-m "rgb(240,190,57)" -g tan4 -B 120 -S 80 -H 97 -D 50,0 -a 0



Example 10 - Variation in Method

Arguments:
-m 1

Arguments:
-m 2

Arguments:
-m 1 -r 20

Arguments:
-m 2 -r 20



What the script does is as follows:

  • Creates a random grayscale noise
  • Stretches and rotates and crops the random noise image
  • Blurs the original random grayscale image with larger blur for displacement map
  • Displaces the blurred stretched, rotated, cropped random noise image

  • Creates another random grayscale noise with different noise
  • Stretches and rotates and crops the random noise image
  • Blurs the previous stretched image slightly
  • Subtract the last two to get an edge image

  • Adds the two processed images together
  • Adds noise, sharpens and adds color

This is equivalent to the following IM commands for tint case.

  • ww=`echo "$dim" | cut -dx -f 1`
  • hh=`echo "$dim" | cut -dx -f 2`
  • hh=`convert xc: -format "%[fx:$hh*$elongation]" info:`
  • density1=$((100-density1))
  • density2=$((100-density2))
  • convert \( -size $dim xc: -virtual-pixel tile -seed $newseed1 +noise random \
    -set colorspace RGB -channel g -separate +channel -level ${density1}x100% \) \
    \( -clone 0 -blur 0x$thickness -auto-level -resize ${ww}x${hh}! \
    -compose over -virtual-pixel edge -distort SRT $rotation \
    -gravity center -crop ${dim}+0+0 +repage -level 50x100% -unsharp 0x1+$intensity1% \) \
    \( -clone 0 -blur 0x$curviness -auto-level \) \
    -delete 0 -define compose:args=${wiggles}x${wiggles} -compose displace -composite \
    $tmpA1
  • convert \( -size $dim xc: -virtual-pixel tile -seed $newseed2 +noise random \
    -set colorspace RGB -channel g -separate +channel \) \
    \( -clone 0 -blur 0x1 -auto-level -resize ${ww}x${hh}! \
    -compose over -virtual-pixel edge -distort SRT $rotation \
    -gravity center -crop ${dim}+0+0 +repage -level ${density2}x100% -unsharp 0x1+$intensity2% \) \
    \( -clone 1 -blur 0x1 -auto-level \) \
    -delete 0 +swap -compose minus -composite -auto-level \
    $tmpB1
  • convert $tmpA1 $tmpB1 -compose plus -composite \
    -virtual-pixel tile -attenuate $amplify -seed $newseed3 +noise gaussian -blur 0x1 \
    -sharpen 0x$sharpen +level-colors $maincolor,$graincolor \
    -modulate $bri,$sat,$hue $outfile