annotate proportionnal with lot of image

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
ths
Posts: 3
Joined: 2012-02-01T04:20:16-07:00
Authentication code: 8675308

annotate proportionnal with lot of image

Post by ths »

Hello every body !

I try to use imageready to convert jpg to pdf and annotate them; for the moment, the only way i fund was to get size of picture with identify and after make operation to set size and position to annotate .

For the moment, i'm stay here:

Code: Select all

#get the size of image
largeur=$(echo "$(identify -format "%w" $1)/27.125" | bc)
hauteur=$(echo "$(identify -format "%h" $1)/34" | bc)

#set the size... work in progress ...
convert $1 -gravity southeast -pointsize $largeur/100  -fill white -annotate 90x90+$largeur+$hauteur 'TITRE' test$1 'TITRE' test.jpg

i'm searching the good operation.

Is it exist other way to make proportionnal annotate with imagemagick ?

Thank for your help !
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: annotate proportionnal with lot of image

Post by fmw42 »

I presume by imageready you really mean imagemagick.

Your code is bit confusing. It is usually better to put in explicit values and image names and post a link to your image, so that others can test.
convert $1 -gravity southeast -pointsize $largeur/100 -fill white -annotate 90x90+$largeur+$hauteur 'TITRE' test$1 'TITRE' test.jpg
What is $1

What is test$1

And why do you have

test$1 'TITRE' test.jpg

I presume test.jpg is the output. But why have you repeated 'TITRE' twice and why the test$1


Getting back to your original question, you might be better using -gravity and the annotate arguments are then supposed to be justified relative to the gravity. That seems to work fine if you don't rotate the text. For example

convert logo: -gravity south -pointsize 48 -font Arial -annotate +0+20 "THIS IS A TEST" logo_annotated.png

This centers the text relative to the bottom center and shifts it up 20 pixels vertically.

But it seems to break down when you rotate the text, so that it is not centered in one dimension.

convert logo: -gravity west -pointsize 48 -font Arial -annotate 90x90+45+0 "THIS IS A TEST" logo_annotated.png

This should do the same relative to the left side of the image. It shifts it right by 45 pixels, but does not center the text vertically.

I am not sure if this would be considered a bug or not, because it seems to get confused by the rotation.


If you use -gravity center, then all the justification should be relative to the center of your input image. So this works fine.

convert logo: -gravity center -pointsize 48 -font Arial -annotate +0+0 "THIS IS A TEST" logo_annotated.png

convert logo: -gravity center -pointsize 48 -font Arial -annotate 90x90+0+0 "THIS IS A TEST" logo_annotated.png


But it also fails when rotated for -gravity north and -gravity east.
ths
Posts: 3
Joined: 2012-02-01T04:20:16-07:00
Authentication code: 8675308

Re: annotate proportionnal with lot of image

Post by ths »

Yes, Imagemagick i don't know why i said ImageReady ! Thank you for this very interesting informations !
My code was confuse because i edited my post yesterday afternoon during my tests ... sorry !
Actually, i test this and for the moment it works fine, what do you this about it ?

Code: Select all

#!/bin/bash

#largeur means width
#hauteur means height

largeur=$(echo "$(identify -format "%w" $1)" | bc)
hauteur=$(echo "$(identify -format "%h" $1)" | bc)

x=$(echo "$largeur/15" | bc)
y=$(echo "$hauteur/13" | bc)

pointsize=$(echo "$largeur/20" | bc)

echo "------------"
echo "largeur : "$largeur
echo "hauteur : "$hauteur
echo "pointsize : "$pointsize


convert $1 -gravity Southeast -font Pixelation.ttf -pointsize $pointsize  -fill black -annotate 90x90+$x+$y 'xxx.net' annoted-$1

Last edited by ths on 2012-04-06T05:06:57-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: annotate proportionnal with lot of image

Post by anthony »

fmw42 wrote:I am not sure if this would be considered a bug or not, because it seems to get confused by the rotation.
It is not a bug, but it is not really a feature either. The problem is that the gravity is setting BOTH the relative position, and the justification of the test. West gravity posiion sets a left justification. As such when you rotate it the rotation is about the start of the text.



Here is an animation of rotations of text at various positions, as set by gravity
The point around which the text rotates is the 'gravity set justification' of the text!
Image
It was created by a script "im_annotation" that was contributed a long time ago
http://www.imagemagick.org/Usage/scripts/im_annotation
(two more varients of the same scritp is in IM Exampels script directory
http://www.imagemagick.org/Usage/scripts/

I want to implement a seperation of Gravity (positioning) from Justification (point in the text or image) as part of IMv7. It is something that has been needed all the way back to IMv5 days.

Basically justification should be able to be set seperatally to gravity, but if unset, gravity should be used.


Getting back to the problem at hand
The easiest way to center text on the left edge, is rotate the image 90 degrees, use gravity south, then rotate back.

Code: Select all

convert logo:  -rotate -90  \
            -pointsize 48 -gravity South -annotate +0+5 "This is a Test" \
            -rotate 90  label_center_left.png
The example should have been in Positioning Images and Text with Gravity
http://www.imagemagick.org/Usage/annotating/#gravity
But it seems to no longer be present! I do not know why. That was one on my oldest examples, and one of the ones that even pre-dated IM Examples!

I have re-added the example to the above area. (give it an hour or so).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply