Embed text in an old IM version

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
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Embed text in an old IM version

Post by marciano »

Hello, I´ve been trying some commands but they seem only to work on new versions
Mine is 6.2.8 (up-to-date from Centos repositories, I don't want to upgrade for security reasons)
I just want to embed a text in the middle of a bunch of jpegs into a directory. Text length should be 400 pixels or something less.
Thanks for your help
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embed text in an old IM version

Post by fmw42 »

what commands did you try?

see
http://www.imagemagick.org/Usage/text/
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

Hi,
I found a composite way using a png stamp 'composite -gravity Center wm.png source target' but I cannot use it in mogrify applied to a dir content.
Thank you
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embed text in an old IM version

Post by fmw42 »

mogrify only works with one image at a time. No second image is allowed (except is special cases as noted in the second link below). So you have to write a script to loop over your images and process them as desired.

see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
http://www.imagemagick.org/Usage/basics/#mogrify_not
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

Okay, thank you Fred, I got it. Thank you

#!/bin/sh
for f in *.jpg
do {
composite -gravity Center wm.png $f $f
}
done
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embed text in an old IM version

Post by fmw42 »

I think you could have used -draw to composite your image over the other and still use mogrify as described in http://www.imagemagick.org/Usage/basics ... fy_compose
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Embed text in an old IM version

Post by anthony »

fmw42 wrote:mogrify only works with one image at a time. No second image is allowed (except is special cases as noted in the second link below). So you have to write a script to loop over your images and process them as desired.

see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
http://www.imagemagick.org/Usage/basics/#mogrify_not
Though that will change in IMv7 (at some point in the development).
But in the mean time try the above links for alternative methods.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

Thanks for your help.
In my old version 'draw' does not work.

I have another question

Code: Select all

convert  source.jpg -resize 500x500 -composite -gravity Center stamp.png target.jpg
This is a simplified line from real one. The problem I have is that '-gravity Center' does not work. stamp.png is placed up and left (north-west) corner.
Thank you
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embed text in an old IM version

Post by fmw42 »

try

convert \( source.jpg -resize 500x500 \) -gravity Center stamp.png -composite target.jpg

-composite has to be at the end and -gravity center before the second image. If on windows use (...) rather than \(...\) or try without parens, though to be sure that resize does not affect the second image, I always add the parens.

see

http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/layers/#convert
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

It still displays stamp.png at top-left with or w/o parenthesis
Thank you

PS: sorry, I found the error. Your suggestion is good. Thank you. (in some of my tests I accidentally replaced stamp.png by source.png, that with stamp at up-left side)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embed text in an old IM version

Post by fmw42 »

marciano wrote:It still displays stamp.png at top-left with or w/o parenthesis
Thank you

What OS are you on? And more importantly, what version of IM?

Can you provide links to your two images. I am having a hard time believing that it does not work.
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

Fred, I edited my previous post.
I didn't realize that in one of my old tries of convert, stamp.png was substituted by that bad target.jpg and of course, any new attempt composing the bad stamp.png would result in the same not desired image.
Fixing that your suggestion was good.
I appreciate and sorry you took hard time to see what could be happend with that command line.
Thanks again
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Embed text in an old IM version

Post by fmw42 »

marciano wrote:Fred, I edited my previous post.
I didn't realize that in one of my old tries of convert, stamp.png was substituted by that bad target.jpg and of course, any new attempt composing the bad stamp.png would result in the same not desired image.
Fixing that your suggestion was good.
I appreciate and sorry you took hard time to see what could be happend with that command line.
Thanks again
No problem. Glad you fixed it. I see the edit now.
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

This draws a black rectangle and a text on it.

Code: Select all

convert -size 440x290 xc:lightblue \
          -draw "fill black rectangle 420,0 440,150 \
                 font AvantGarde-Demi  font-size 14   \
                 fill white  \
                 translate 435,100 rotate -90 text 0,0 \' Anthony \'" \
          draw_mvg.gif'
As I wrote before I cannot use some new techniques described in IM manual to get this:
White text over rectangle black opacity 0.5 over a 440x290 image instead of c:lightblue

About opacity I've tried to emulate this code (it works) adding -opacity 0.5 to the previous command but no text is printed.

Code: Select all

convert -size 200x200 xc:skyblue -fill white -stroke black \
          -draw "fill -opacity 0.5 rectangle 50,200 50,0 " \
          set_fill_opacity.gif
Thank you
marciano
Posts: 10
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Embed text in an old IM version

Post by marciano »

I found a way. It is highly probably it could be cleaned

Code: Select all

convert -size 440x290 xc:transparent \
          -draw "fill black fill-opacity 0.2 rectangle 420,0 440,150 \
                 font AvantGarde-Demi  font-size 14   \
                 fill white  \
                 translate 435,100 rotate -90 text 0,0 \' Anthony \'" \
          draw_mvg.gif'
composite -gravity Center draw_mvg.png source.jpg  target.jpg
Post Reply