Find the answer to your Linux question:
Results 1 to 4 of 4
I have a bunch of pictures I want to annotate, you know, put silly comments on them. I started using GIMP but it was a time consuming pain, especially because ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    372

    Using ImageMagick to annotate pictures


    I have a bunch of pictures I want to annotate, you know, put silly comments on them. I started using GIMP but it was a time consuming pain, especially because I have a lot of them to do. Don't get me wrong, I love GIMP, but sometimes there is a better way.

    I want black borders without cutting into the picture, so the output image needs to be bigger than the input image. Some get text at the top and bottom, others just at the bottom. Some I don't want the border, but I want the text to look nice, like subtitles, black edges with white fill so it is easily readable on varied color background. All of the text I want nicely centered without having to nudge it by eyeball.

    ImageMagick's "convert" is an amazing utility, and also mind-bogglingly complicated. I just spent the last 6 hours reading docs and tweaking a script to do exactly what I want. Now I can just adjust the values in the script, and feed it a picture, and I have the result I need, without having to do it all manually. It may take a couple of tries to get the values just right, but it's very fast, so no problem.

    I thought I would share the results of my efforts:
    Code:
    #!/bin/sh
    
    # Input file
    IFILE="INeedCaption.jpg"
    
    # Output file
    OFILE="annotated.jpg"
    
    # Your caption here
    # Top of page caption
    CAPTION1="They call me" 
    # Bottom of page caption
    # triple backslashes for double quotes
    CAPTION2="\\\"Miven Dooligan\\\""
    
    FONT="Arial-Bold" # use "convert -list font" to see your fonts
    FONTSZ=48   # Adjust to suit the IFILE size
    XS="0"      # shear on the X axis
    YS="0"      # shear on the Y axis
    X="+0"
    # Adjust (-) or (+) according to last gravity
    Y1="+0"   # Adjust
    Y2="+5"   # Adjust
    # Border sizes
    BDRX=10
    BDRY=60     # Adjust, a bit bigger than FONTSZ
    BDRCOLOR="black"
    
    # If you want just a bottom caption you need to splice
    # a chunk of pixels on the bottom. So make the border
    # 10x10 and add the chunk here
    SPLICE="0x0" # X by Y eg 0x50
    
    # define this to anything if you want the text to have outlines
    # like subtitles, for use on light backgrounds.
    STROKE=
    
    # Build our command
    ARGS="\
    -background ${BDRCOLOR} \
    -bordercolor ${BDRCOLOR} \
    -border ${BDRX}x${BDRY} \
    -gravity south \
    -splice ${SPLICE} \
    -undercolor transparent \
    -gravity center \
    -font ${FONT} \
    -pointsize ${FONTSZ} \
    -fill white"
    if [ -n "$STROKE" ]; then
        ARGS="${ARGS} \
        -stroke black \
        -strokewidth 2"
    fi
    ARGS="${ARGS} \
    -gravity north \
    -annotate ${XS}x${YS}${X}${Y1} \"${CAPTION1}\" \
    -gravity south \
    -annotate ${XS}x${YS}${X}${Y2} \"${CAPTION2}\" \
    "
    
    CMD="convert ${IFILE} ${ARGS} ${OFILE}"
    
    # and run it.
    eval $CMD
    
    # comment this out if you don't have xli viewer
    xli $OFILE
    
    #fin
    As you can see I've tried to add comments to explain what the heck is going on, especially if I don't use it for another 6 months and forget everything I learned this morning.

    If you want to have something oddball, like one word in italics, you're stuck with GIMP, sorry. ImageMagick apparently can do Pango Markup, so a second version of the script will likely implement that. As it is, I wanted to keep it as simple as possible at this time.

    I'll also attach the silly demo pic I used as the input file for this example. Comments are very welcome.

    As an addendum, here's an excellent resource:
    ImageMagick v6 Examples

    Peace and Cheer.
    Attached Images Attached Images

  2. #2
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,310
    OK, who taped the cats ears back?

    I've never used the utility before but I have used the libraries. Good stuff.

  3. #3
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    372
    It's just some silly pic I got from reddit or something.

    Yes, ImageMagick is quite amazing. I'm re-compiling it with pango support right now. It wants pango-1.28.1 but all I have is 1.10.4 so I tweaked the configure script and waiting to see if it works. Then I should be able to get italics/bold/superscript/strikethrough and stuff in the captions.

    Argh! The answer is a firm NO from the make process. Now I have to upgrade pango. That's a major hassle. I think it depends on a bunch of stuff, and I know that a ton of things depend on it. The last time I did it apparently was just back in March. I must've had issues because I compiled an older version of the library instead of the newest one.

    It's that whole gtk suite of libs. They're all inter-dependent. It can take days to upgrade even one of them. Herding cats comes to mind.

  4. #4
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,310
    I love gtk but it is a ball of twine alright. Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •