Help with multiple captions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tre1121

Help with multiple captions

Post by tre1121 »

Hi!

First post here!

Trying to make a php-script that makes two captions, one on the southeast and one on the southwest.
I have got it to work with a caption on southwest and annotate on southeast but that's a little hard to control.

Anyone having a solution for having a caption also at the souteast?

See an example:
Image
http://www.overum.net/displayimage.php? ... fullsize=1

The code:

Code: Select all

shell_exec ("convert -resize ".$s."x".$s." -quality $q% $argv[1] -bordercolor black -border 3 -bordercolor white -border 2 \( -background black -fill white -font Bookman-LightItalic -size $break_length -pointsize $pointsize -kerning 4 caption:' ' -trim +repage -bordercolor black -border 4 \) -gravity Southwest \( -background black -fill white -font Bookman-LightItalic -size $break_length -pointsize $pointsize -kerning 4 caption:'$caption' -trim +repage -bordercolor black -border 15 \) -gravity Southwest -append -bordercolor black -border 10 -gravity southeast -pointsize $pointsize_date -annotate +20+10 '$location\n $img_date $img_time' -gravity South -chop 0x10 $outfile");
Best Regards Martin
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with multiple captions

Post by fmw42 »

use caption: (or label:) rather than annotate to create your captioned text on a transparent background (or whatever color) given a width and pointsize. Let it find the height automatically. then use convert -gravity ... -compose over to place the text image over the background image. repeat for the other caption text or how ever many captions you want to add.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Help with multiple captions

Post by Bonzo »

Something strange is happening; I have tried to create the output all in one command and two command lines and both times the second text will not be displed if I have both pointsizes at 10. If I change the second pointsize to 15 it works !!!

I would go with the two line version below as it makes it easer to automaticaly resize the area below the image but I can not work out how to get both of the texts without different font sizes.

Code: Select all

<?php

$input = "yorkshire.jpg";
$s = "400";
$q = "90";
$argv[1] = "No idea what this is so taken out";
$caption_left = "caption left";
$caption_right = "caption right";
$pointsize = "10";
$pointsize_date = "15";
$location = "The country";
// Did you know you can get the date and time by using php EXIF or IM EXIF ?
$img_date = "2009-01-04";
$img_time = "11:48";
$outfile = "tre.jpg";

$cmd = " $input -resize {$s}x{$s} -bordercolor black -border 3x3 -bordercolor white -border 2x2 -gravity South +repage";

//echo $cmd."<br>";
//yorkshire.jpg -resize 400x400 -bordercolor black -border 3x3 -bordercolor white -border 2x2 -gravity South +repage

shell_exec ("convert $cmd temp.png");

$size = getimagesize("temp.png");
$caption_area = $size[0]."x50";

$cmd = " temp.png ( -size $caption_area xc:black ".
" -font DRAGM.ttf -pointsize $pointsize -kerning 4 -fill white -gravity southwest -annotate +10+10 \"$caption_left\" ".
" -pointsize $pointsize_date -kerning 4 -fill white -gravity southeast -annotate +0+0 \"$location $img_date $img_time\" ) ".
" -append +repage -quality $q ";

//echo $cmd."<br>";
// temp.png ( -size 410x50 xc:black -font DRAGM.ttf -pointsize 10 -kerning 4 -fill white -gravity southwest -annotate +10+10 "caption left" -font DRAGM.ttf -pointsize 15 -kerning 4 -fill white -gravity southeast -annotate +0+0 "The country 2009-01-04 11:48" ) -append +repage -quality 90 

shell_exec ("convert $cmd $outfile");

?>
Note:
jpg quality does not use a % see http://www.imagemagick.org/script/comma ... hp#quality

You should be reading your image in first before the -resize

Also a neater way to write the code is as above; You can always echo $cmd then to confirm it contains what you expect it to.
tre1121

Re: Help with multiple captions

Post by tre1121 »

Thanks for the help!

But my captions is sometimes 1 row, sometimes 3 rows, i would like imagemagick to automatic size the frame to fit. Like it seems to do with caption: or label:

Maybe i should try to learn with some more basic.

Any hint to get some of this to work:

Code: Select all

convert -background '#00000080' -fill white -gravity south label:'Faerie Dragon' -compose over -composite  \
              in.jpg out.jpg

Code: Select all

convert -background '#00000080' -fill white label:'West Dragon' miff:- |\
    composite -gravity west -geometry +0+3 \
	label:'East Dragon' miff:- |\
    composite -gravity east -geometry +0+3 \
              -   in.jpg out.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with multiple captions

Post by fmw42 »

try this

convert logo: \
-background none -fill red -size 50x -pointsize 14 \
caption:"THIS IS TEST 1" -gravity northwest -geometry +10+10 -compose over -composite \
-background none -fill blue -size 50x -pointsize 14 \
caption:"THIS IS TEST 2" -gravity southeast -geometry +10+10 -compose over -composite \
logo_two_captions.png

logo: is an internal IM image see http://www.imagemagick.org/script/forma ... tin-images
tre1121

Re: Help with multiple captions

Post by tre1121 »

Thanks a lot for helping this far, but now i'm getting sleeping problem... :)


This result in no caption:
convert $argv[1] \
-bordercolor black -border 3 -bordercolor white -border 2 \
\( -background none -fill red -size 250x -pointsize 50 \
caption:'THIS IS TEST 1' -gravity northwest -geometry +10+10 -compose over -composite \
-background none -fill blue -size 250x -pointsize 50 \
caption:'THIS IS TEST 2' -gravity southeast -geometry +10+10 -compose over -composite \
-bordercolor black -border 10 \
\) -gravity east \
-append \
-bordercolor black -border 10 \
-gravity South -chop 0x10 \
$outfile


This result in 3 captions. "Hatching" is the one that control size of the bottom border. I want the caption with most text/lines control size.
convert $argv[1] \
-bordercolor black -border 3 -bordercolor white -border 2 \
\( -background black -fill white -pointsize 100 \
label:Hatching \
-bordercolor black -border 10 \
\) -gravity east \
-append \
-bordercolor black -border 10 -background none -fill red -size 250x -pointsize 50 \
caption:'THIS IS TEST 1' -gravity northwest -geometry +10+10 -compose over -composite \
-background none -fill blue -size 250x -pointsize 50 \
caption:'THIS IS TEST 2' -gravity southeast -geometry +10+10 -compose over -composite \
-gravity South -chop 0x10 \
$outfile


This results in two labels, but it makes a newline between the two captions, i can't get them on the same row and can't place them individually with -gravity.
convert $argv[1] \
-bordercolor black -border 3 -bordercolor white -border 2 \
\( -background black -fill white -pointsize 100 \
label:Hatching label:right \
-bordercolor black -border 10 \
\) -gravity east \
-append \
-bordercolor black -border 10 -gravity South -chop 0x10 \
$outfile


Same result as above, but both labels in left corner and with one newline between.
convert $argv[1] \
-bordercolor black -border 3 -bordercolor white -border 2 \
\( -background black -fill white -pointsize 100 \
label:Hatching \
-bordercolor black -border 10 \
\) -gravity east \
\( -background black -fill white -pointsize 100 \
label:Hatcyhing \
-bordercolor black -border 10 \
\) \
-gravity west -append \
-bordercolor black -border 10 -gravity South -chop 0x10 \
$outfile


Please, anymore tips?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with multiple captions

Post by fmw42 »

Are you on Windows? Windows uses different line continuations and escape characters. If so, see http://www.imagemagick.org/Usage/windows/

Furthermore, my command did not use parentheses!

Is argv[1] valid?

test using

echo $argv[1]

to see if it has the filename and possibly the full path to the file you want.
tre1121

Re: Help with multiple captions

Post by tre1121 »

No i'm on linux.

I tried your example without parentheses, worked perfectly, two captions on the logo, thanks!

My goal is to combine your example with this example. (Example also works for me, even with $argv[1])
convert thumbnail.gif \
-bordercolor black -border 3 -bordercolor white -border 2 \
\( -background black -fill white -pointsize 24 \
label:Hatching -trim +repage \
-bordercolor black -border 10 \
\) -gravity South -append \
-bordercolor black -border 10 -gravity South -chop 0x10 \
border_framework.gif
(from http://www.imagemagick.org/Usage/thumbnails/)

Well, maybe i should abandon the idea to do it in a neat one-command way och take it in steps, make small image with captions and append that to a bordered image instead...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with multiple captions

Post by fmw42 »

I am not sure what you are trying to do, but it should be possible with one command. Just explain the steps you want to do and post a link to an example input and output if possible to help me understand what you want.

I don't know which example you are referring from the thumbnails page. Can you post a link to the subsection of the page from the page index?
tre1121

Re: Help with multiple captions

Post by tre1121 »

The example:

http://www.imagemagick.org/Usage/thumbnails/#fluff

scroll down to "Adding Borders" (5 th example)

This is what i've accomplished and what i want (with some modification):
http://www.overum.net/displayimage.php? ... fullsize=1

The right caption is made with annotation, I want to have that done with label or caption to have more flexibility.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with multiple captions

Post by fmw42 »

I cropped out the main part of your image without the borders and text and this is what I used to generate something similar:

convert \( forsbo.jpg -bordercolor black -border 2 -bordercolor white -border 2 \
-bordercolor black -border 10 +gravity -gravity south -background black -splice 0x70 \) \
\( -background none -fill white -size 100x50 -font VerdanaI \
caption:"THIS IS TEST 1" \) -gravity southwest -geometry +20+20 -compose over -composite \
\( -background none -fill white -size 100x50 -font VerdanaI \
caption:"THIS IS TEST 2" \) -gravity southeast -geometry +20+20 -compose over -composite \
forsbo_two_captions.jpg

The first parens sets up all the borders. The second sets up the first caption then overlays it. The third sets up the second caption then overlays it.
Post Reply