I need to make many tilted text graphics

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
CleverMoniker

I need to make many tilted text graphics

Post by CleverMoniker »

I am new here if you can't tell.

I am creating a web page display of a row and column chart. (think of a spreadsheet)
I would like the top column headers to be tilted (45 or 60 degrees).
I want the text to be a simple font, maybe 10 or 12 pitch. Lines somewhat close together, I might want to place a border line between each one.

I want to go one of a couple ways:
(each user of the web page gets a different graphic, the header texts are kept in a database, some are user defined)
1) At some initialization point, write the text to an image and merge the selected texts at display time.
2) Know the image boundaries of each header text and generate the entire graphic at display time.
Which approach is most valid? Easiest? Cheapest in resources?
(in a way, I don't care about efficiency right now, I just want it to display)

I am having trouble drawing the text and getting the bounding box.

Right now, I am using php and calling the convert.exe in an exec(""); statement. (I don't even know if this is the best way, I just want to get something to work...)

The side row descriptions will be done the same way, but I am sure that it will be easier.

Any and all suggestions will be considered.
Thanks in advance.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: I need to make many tilted text graphics

Post by anthony »

Look at annotate. It has options for rotating the text.

See http://www.imagemagick.org/Usage/text/#annotate
and more specifically
http://www.imagemagick.org/Usage/misc/#annotate


I also added a rotated annotated test example to the first page.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
CleverMoniker

Re: I need to make many tilted text graphics

Post by CleverMoniker »

Anthony,
Thanks for the help, that is part of the answer that I am seeking.

How do I calculate the extreme edges of the text for cropping to the minimum size?

Which would be more efficient...
Making each line of text and merging the individual images when a user changes the settings?
Or, plotting all the texts into a single graphic when the user changes the settings?

Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: I need to make many tilted text graphics

Post by anthony »

As you are doing slanted Text and will be wanting to place them in specific locations
The best idea would be to plot them. The point of rotation depends on gravity
and by default is the baseline just the left of the first character.

To do a whole series of labels at 45 degree across the image juts move the 'start point' to the right by an appropriate amount and draw the next string.

For example

Code: Select all

convert -size 100x60 xc:skyblue \
    -annotate 315x315+10+50 "First" \
    -annotate 315x315+25+50 "Second" \
    -annotate 315x315+40+50 "Third" \
    -annotate 315x315+55+50 "Fourth" \
    labels.jpg
Now added to the annotate examples

You can retrieve bounds in a number of ways. One of the better is to use a specify debugging setting as demonstrated in... Determining Font Metrics
http://www.imagemagick.org/Usage/text/#font_info

however the other way is to just draw the image and do a -trim. The tim size and position can be found by looking at the resulting virtual canvas 'page' information. this is also demonstrated in the above link.


Please let us know what you decide to do, or a demonstration of the final result.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
CleverMoniker

Re: I need to make many tilted text graphics

Post by CleverMoniker »

Thank you!
I did not realize I could use the "-annotate" more than once in a statement.

I will experiment some more.

I will be happy to show you the result soon.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: I need to make many tilted text graphics

Post by anthony »

In that case you may like to at least read 'Basics'. It may open our eyes to just how powerful ImageMagick really is!

http://www.imagemagick.org/Usage/basics/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
CleverMoniker

Re: I need to make many tilted text graphics

Post by CleverMoniker »

I certainly will!
My current problem is centered on the server itself. I am afraid that you most likely cannot assist here...

The host for the system I am developing for has ImageMagick installed (it worked from a telnet session), but for some reason it will not run when called from a php script.
The same script works at a different host.
There is a support ticket being taken out.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: I need to make many tilted text graphics

Post by fmw42 »

If you are using PHP exec command, be sure you get the correct path to IM (convert) to use in your script. Each server may have IM in a different location. Typically it will be either /usr/local/bin or /usr/bin if on unix server, but IM could be installed anywhere.

For example:

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

Should return information about the IM version.
CleverMoniker

Re: I need to make many tilted text graphics

Post by CleverMoniker »

Well that is another clue...
ImageMagick is indeed located at /usr/bin on the server where it does not work.

The script you provided does display the IM version on both servers.
Version: ImageMagick 6.5.0-4 2009-03-22 Q16 http://www.imagemagick.org - for the server that messes up.
Version: ImageMagick 6.2.4 07/28/09 Q16 http://www.imagemagick.org - for the server that works.

The version request works, but creating and modifying an image does not!

This is the command that I am using which works on one server and not on the other:

Code: Select all

exec("\		  
/usr/bin/convert -size 320x320 xc:white -font Veranda -pointsize 10 \
          -annotate 315x315+20+300 'Franchise Chooser Tool' -trim annotate_rotated4.png \
");
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: I need to make many tilted text graphics

Post by fmw42 »

does the directory where you want to put your image have write permissions?

what version of IM are you using?

try specifying the full path to your font file (presumably .ttf)

try adding the

... ,$out,$returnval);
print_r($out[0]);

and see what errors your get?
CleverMoniker

Re: I need to make many tilted text graphics

Post by CleverMoniker »

The image and php scripts are in the same directory.
The permissions are set to 755 for that directory.
(version information below)

I don't really care about the font for now. I assume (stupid me) that if a font is not specified properly, a default font will be used. I saw this behavior previously.
I just tried it after removing the font parameter completely and the behavior does not change.

I tried adding the code to output the result and result code. I will reproduce the script and output below.

I want to thank everyone for the help, I am getting assistance from the server team (Michigan, USA), fmw42 (Sunnyvale, California, USA), and anthony (Brisbane, Australia). The team effort is overwhelming. (I just know it will be something very simple when the problem is solved.)

This is the script that is used on both servers:

Code: Select all

<html>
<body bgcolor="#f0f0f0">

<?php
echo "Hello World\n";
?>

<?php

echo("</br>running the convert program...</br>");
exec("\		  
/usr/bin/convert -size 320x320 xc:white -pointsize 10 \
          -annotate 315x315+20+300 'TEST STRING test string TEST STRING' -trim annotate_rotated4.png ",$out,$returnval);
print_r($out[0]);
echo "<br/>";

echo("</br>running the identify program...</br>");
exec("\		  
/usr/bin/identify  annotate_rotated4.png ",$out,$returnval);
print_r($out[0]);
echo "<br/>";

echo "<br/><br/><br/>this should identify the version of ImageMagick<br/><br/>";
exec("/usr/bin/convert -version",$out,$returnval);
print_r($out[0]);
echo "<br/>";

?>


annotate_rotated4.png<br/>
<img src="annotate_rotated4.png" /><br/><br/>



</body>
</html> 
This is the result on the server that works:

Code: Select all

Hello World
running the convert program...


running the identify program...
annotate_rotated4.png PNG 136x132 151x298+15+166 DirectClass 6kb



this should identify the version of ImageMagick

annotate_rotated4.png PNG 136x132 151x298+15+166 DirectClass 6kb
annotate_rotated4.png
Image

This is the result on the server that does not work:

Code: Select all

Hello World
running the convert program...


running the identify program...




this should identify the version of ImageMagick

Version: ImageMagick 6.5.0-4 2009-03-22 Q16 http://www.imagemagick.org
annotate_rotated4.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: I need to make many tilted text graphics

Post by anthony »

Try and re-direct errors to a log file for your script.

See...
http://www.cit.griffith.edu.au/~anthony ... /php.hints

It looks to me like it is not finding the programs
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply