Fred's ImageMagick Tidbits


 



Graphics Processing



Creating Bold Text

This is a quick and dirty approach. The best technique is really to find a bold font and specify that using -font

Normal Weight Text

convert -background white -font Arial -pointsize 48 label:"Test" text.jpg

Bold Text (add -stroke black)

convert -background white -font Arial -pointsize 48 -stroke black label:"Test" textbold.jpg

top



Aligning Text Vertically

  • Use space and newline character, \n, between each letter, then -trim

convert -background white -fill blue -font Arial -pointsize 24 -gravity center \
label:'V\ne\nr\nt\ni\nc\na\nl' label_vertical.gif

top



Rainbow And Step Gradients

Cyclic Color Rainbow

  • create a pure red (any non-gray) color image and convert to HSL colorspace
  • at the same time create a grayscale gradient of the same size
  • use the gradient to replace the hue channel of red image
  • convert the HSL image back to RGB and rotate 90 degrees
  • convert -size 30x600 xc:"rgb(100%,0%,0%)" -colorspace hsl gradient: \
    -compose CopyRed -composite \
    -colorspace RGB -rotate 90 rainbow1.jpg

Non-Cyclic Color Rainbow

  • create black, red, orange, yellow, green1, cyan, blue, blueviolet and black images
  • append them together horizontally and resize using a Cubic interpolation filter to the desired size
  • convert xc:black xc:red xc:orange xc:yellow xc:green1 xc:cyan xc:blue xc:blueviolet xc:black \
    +append -filter Cubic -resize 600x30! rainbow2.jpg

10 Step Red, Blue, Green And Gray Gradient

  • create a 1x10 red-black, green1-black, blue-black, gray gradients
  • append them together horizontally, rotate 90 degrees and scale to desired size
  • convert -size 1x10 gradient:red-black gradient:green1-black gradient:blue-black gradient: \
    +append -rotate 90 -scale 600x120! step_gradient.jpg

Circular Color Rainbow

  • create a pure red (any non-gray) color image and convert to HSL colorspace
  • create a circular grayscale gradient
  • use the gradient to replace the hue channel of red image
  • convert the HSL image back to RGB to create a rainbow image
  • create a circular mask and apply to rainbow image
  • convert \( -size 151x151 xc:"rgb(100%,0%,0%)" -colorspace hsl \) \
    \( -size 100x300 gradient: -rotate 90 +distort Polar '75,0,.5,.5' +repage -rotate 90 \) \
    -compose CopyRed -composite -colorspace RGB \
    \( -size 151x151 xc:black -fill white -draw "circle 75.5,75.5 75.5,151" -alpha off \) \
    -compose copy_opacity -composite polar_rainbow.png

top



Random Color Squares Image

  • Create a 16x16 image, fill with random noise, scale a factor 10
    to make a 160x160 image of random 10x10 color squares
  • convert -size 16x16 xc: +noise Random -scale 1000% random_squares.gif

top



Convert Colors To RGB(A) Values In Range 0 to 255

IM Commands Only

color="some_color_value"
convert -size 1x1 xc:$color \
-format "(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)])" info:

color="red" => (255,0,0)

color="skyblue" => (135,206,235)

color="#fe9843" => (254,152,67)

color="rgb(75%,50%,25%)" => (191,127,63)

color="hsl(180,100%,50%)" => (0,255,255)

color="cmyk(100%,100%,0%,50%)" => (0,0,127)

color="rgba(100%,75%,50%,0.25)" => (255,191,127,63)

color="hsla(180,100%,50%,0.5)" => (0,255,255,127)

color="cmyka(100%,100%,0%,50%,0.25)" => (0,0,127,63)

color="#fe9843ca" => (254,152,67,202)

color="gray75" => (191,191,191)

color="graya(50%,0.25)" => (127,127,127,63)

IM & Sed Commands

color="some_color_value"
convert -size 1x1 xc:$color -depth 8 txt: | \
sed -n 's/ //g; s/^.*[^(]\((.*)\)[^)].*$/\1/p'

color="red" => (255,0,0)

color="skyblue" => (135,206,235)

color="#fe9843" => (254,152,67)

color="rgb(75%,50%,25%)" => (191,127,63)

color="hsl(180,100%,50%)" => (0,255,255)

color="cmyk(100%,100%,0%,50%)" => (0,0,127)

color="rgba(100%,75%,50%,0.25)" => (255,191,127,64)

color="hsla(180,100%,50%,0.5)" => (0,255,255,128)

color="cmyka(100%,100%,0%,50%,0.25)" => (0,0,127,64)

color="#fe9843ca" => (254,152,67,202)

color="gray75" => (191,191,191)

color="graya(50%,0.25)" => (127,127,127,64)

top