Results 1 to 4 of 4

Thread: How do I print strings with spaces in imagemagick?

  1. #1
    Join Date
    Mar 2010
    Location
    Sheffield, UK
    Beans
    19
    Distro
    Ubuntu 10.04 Lucid Lynx

    How do I print strings with spaces in imagemagick?

    Hi, I've been trying for hours to print string variables with imagemagick to make dvd buttons from a shell script. The basic command is:-
    Code:
    ~$ convert -size 720x480 xc:transparent -fill red +antialias -pointsize 48 -draw 'text 100,100 "Button"' image.png
    Now to print a string variable I have been using:-
    Code:
    ~$ string=Button
    ~$ convert -size 720x480 xc:transparent -fill red +antialias -pointsize 48  -draw 'text 100,100 '"$string"' image.png
    However try as I might, when the string has spaces, as in:-
    Code:
    ~$ string="Button One"
    ~$ convert -size 720x480 xc:transparent -fill red +antialias -pointsize 48 -draw 'text 100,100 '"$string" image.png
    Imagemagick strips off the quotes and I get an error:-
    Code:
    convert: Non-conforming drawing primitive definition `One' @ draw.c/DrawImage/3140.
    Does anyone know a trick to escape the spaces?




    Secret to a long life - Don't forget to breathe.

  2. #2
    Join Date
    Mar 2010
    Location
    Sheffield, UK
    Beans
    19
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How do I print strings with spaces in imagemagick?

    Hi again - I found the solution:- the label:"text" command is much simpler than -draw " <parameters> 'text'", and with only one set of quotes, there's no problem putting in a variable such as

    Code:
    $: a="stringy cheese"
    $: convert -size 600x400 -background blue -fill red -pointsize 70 -gravity center label:"$a" picture.png
    $: display picture.png
    The exploration coninues...

  3. #3
    Join Date
    Jul 2011
    Beans
    4

    Re: How do I print strings with spaces in imagemagick?

    It's too late but can be useful for someone.

    You can use the syntax "string '${VAR}' string" with the option "-draw". Like that:

    Code:
    #!/bin/bash
    
    WATERMARK="A very very long string that you want to draw"
    
    W=`exiftool -ImageWidth -s -s -s $1`
    
    H=`exiftool -ImageHeight -s -s -s $1`
    
    convert -size $W"x"$H xc:grey30  -gravity center -draw " fill grey70  text 0,0 '${WATERMARk}'"  stamp_fgnd.png
    
    convert -size $W"x"$H xc:black   -gravity center -draw " fill white    text 1,1 '${WATERMARK}' text  0,0 '${WATERMARK}' fill black  text -1,-1  '${WATERMARK}'"  +matte stamp_mask.png
    
    composite -compose CopyOpacity  stamp_mask.png  stamp_fgnd.png  stamp.png
    
    mogrify -trim +repage stamp.png
    
    composite -gravity south -geometry +0+10 stamp.png  $1 new_$1
    If you save it as - for example - watermark.sh, you can execute it specifing the input image file:

    # . watermark.sh /path_to/my_image.jpg

    Last edited by babixeddu; July 1st, 2011 at 02:48 PM.

  4. #4
    Join Date
    Mar 2010
    Location
    Sheffield, UK
    Beans
    19
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How do I print strings with spaces in imagemagick?

    Babixeddu, yes my problem was that I had the quotes the wrong way round, it works fine if you use double quotes around the arguments for the -draw option and single quotes for the string intself - Thanks a lot!

Tags for this Thread

Bookmarks

Posting Permissions

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