Pass path to TTF file?

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
vbsaltydog

Pass path to TTF file?

Post by vbsaltydog »

I am trying to set the font option within a convert command to use the server path to a windows true type font file (.ttf) and it is not working. I have done this before on servers that I control but this is a remote server and I do not have access to ssh and cannot modify the server fonts library, hence the need to upload the .ttf files and point directly to them.

In the following command, can you see why the -font option is not working?

Code: Select all

convert $server_media_path/images/logos_temp/$fd_usr--$logo_image -transparent #ffffff \ -gravity south -background white -splice 0x25 -fill rgb'($textcolor)' -pointsize $fontsize \ -font "path_to_ttf_file" -draw "text 0,0 '$logotext'" $server_media_path/images/logos_temp/$fd_usr--$logo_image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pass path to TTF file?

Post by fmw42 »

check to see if IM is recognizing your fonts

convert -list font


see http://www.imagemagick.org/Usage/scripts/ for

imagick_type_gen
show_fonts
graphics_utf
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

Thanks for the info. I have read over the scripts and they are great for adding ttf files to the IM fonts library but my issue is that I am using the full path to the ttf file in my convert command which is supposed to work and does work on other applications that I have written and on this particular application (uses the convert command listed in my previous post) , full paths to the ttf files does not work which leads me to believe that it will continue to fail even after the ttf file is added to the IM fonts library.

Also, it is not a simple thing for me to run commands like :

convert -font list

and view the output as I do not have access to ssh on the remote server and am running my IM commands from within a web app where the output can not be easily sent to the browser.

Advise?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Pass path to TTF file?

Post by Bonzo »

I use relative paths not absolute paths and that works OK.

If you have a server I pressume you can run php code ?

try running this to see the fonts installed:

Code: Select all

<?php 
// Select the version number from the configeration file
preg_match('/^LIB_VERSION_NUMBER ([0-9,]+)$/m', shell_exec("convert -list configure "), $vnums);

// Seperate the numbers at the ,
$number = explode( ",", $vnums[1] );

// Format the version from 6,3,4,1 format to 06030401
$version = "";

for($i=0;$i<4;$i++)
{
$version .= str_pad( $number[$i], 2, '0', STR_PAD_LEFT );
} 

// The 'list' method used to get the fonts changed in IM v6.3.5-7
$font_list = ( $version > "06030507" ) ? "font" : "type";

// Display the version of Imagemagick, the method to read the fonts and the list of fonts
echo "<h2>IM version: ".$version." </h2>\n
<h3>Method used: convert -list $font_list</h3>\n
<hr>\n<pre>";
system("convert -list $font_list");
echo "</pre>\n<hr>";
?> 
Loads of other information on my site with php examples and how to find setup information.

Also why do you have \ twice in your code ?
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

The \ is a leftover escape character that I forgot to edit out before printing the command in the forum. I am actually using the perl 'system' function from within my web app to issue the IM commands and the double quotes need to be escaped.

I actually just found out that I do have a limited ssh login to the server so I can see the convert -list fonts output.

The fonts that I want to use are not listed of course but they should still work from the absolute paths, no ?
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

OK. When I try to run my convert command from the shell I get an error that convert cant read the ttf file

I checked the path to the ttf file and it is correct and the file was 755 so it should have worked. I changed the ttf file to 777 and convert still cant read it.

Any ideas?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Pass path to TTF file?

Post by Bonzo »

Two things I would try:

1/ Use a font that is installed and does the code work.

2/ Use a relative path to the font and see what happens.
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

After some troubleshooting from the shell. The ttf files can be read using the relative path but not from the absolute path.

Thanks again for all of your help.
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

We were both posting at the same time. You were correct on the relative path idea.

Thanks again. You were a huge help on my project. I will post a link to the finished program when its done.
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

Its not over yet. I can see the ttf files through the relative path now but this is the error I get:

Code: Select all

ERROR: /invalidfont in --.type42execchar--
Operand stack:
   --dict:13/13(ro)(L)--   116   t   116   0.046875   0.0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   %finish_show   --nostringval--   --nostringval--   3   3   0   --nostringval--   (gs_show_enum)   %op_show_continue
Dictionary stack:
   --dict:1127/1686(ro)(G)--   --dict:0/20(G)--   --dict:104/200(L)--
Current allocation mode is local
Current file position is 320
ESP Ghostscript 815.02: Unrecoverable error, exit code 1
ERROR: /invalidfont in --.type42execchar--
Operand stack:
   --dict:13/13(ro)(L)--   116   t   116   0.046875   0.0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   %finish_show   --nostringval--   --nostringval--   3   3   0   --nostringval--   (gs_show_enum)   %op_show_continue
Dictionary stack:
   --dict:1127/1686(ro)(G)--   --dict:0/20(G)--   --dict:104/200(L)--
Current allocation mode is local
Current file position is 320
ESP Ghostscript 815.02: Unrecoverable error, exit code 1
convert: unable to read font `comic.ttf'.
convert: Postscript delegate failed `/tmp/magick-XXUcpir6': No such file or directory.
ERROR: /invalidfont in --.type42execchar--
Operand stack:
   --dict:13/13(ro)(L)--   116   t   116   0.046875   0.0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   %finish_show   --nostringval--   --nostringval--   3   3   0   --nostringval--   (gs_show_enum)   %op_show_continue
Dictionary stack:
   --dict:1127/1686(ro)(G)--   --dict:0/20(G)--   --dict:104/200(L)--
Current allocation mode is local
Current file position is 320
ESP Ghostscript 815.02: Unrecoverable error, exit code 1
ERROR: /invalidfont in --.type42execchar--
Operand stack:
   --dict:13/13(ro)(L)--   116   t   116   0.046875   0.0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   %finish_show   --nostringval--   --nostringval--   3   3   0   --nostringval--   (gs_show_enum)   %op_show_continue
Dictionary stack:
   --dict:1127/1686(ro)(G)--   --dict:0/20(G)--   --dict:104/200(L)--
Current allocation mode is local
Current file position is 320
ESP Ghostscript 815.02: Unrecoverable error, exit code 1
convert: unable to read font `comic.ttf'.
convert: Postscript delegate failed `/tmp/magick-XXsWCXsW': No such file or directory.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Pass path to TTF file?

Post by magick »

Does your version of ImageMagick include support for Freetype? Type

identify -list configure

The DELEGATES tag should mention freetype.

Can you post a URL to your Postscript image. Its possible Ghostscript is choking on an embedded font. We need to reproduce the problem to be of any help.
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

When we were troubleshooting paths before, I got it to work using a relative path and the same ttf file that is choking now.
Here is the output requested:

Code: Select all

Name          Value
-------------------------------------------------------------------------------
CC            gcc
CFLAGS        -g -O2 -Wall -W -pthread
CONFIGURE     ./configure /usr/local/share/config.site /usr/local/etc/config.site
COPYRIGHT     Copyright (C) 1999-2007 ImageMagick Studio LLC
CPPFLAGS      -I/usr/local/include
CXX           g++
CXXFLAGS      -g -O2 -Wall -W -pthread
DEFS          -DHAVE_CONFIG_H
DELEGATES     fontconfig freetype jpeg png tiff x11 xml zlib
DISTCHECK_CONFIG_FLAGS --disable-deprecate --with-quantum-depth=16 --with-djvu=no --with-fontpath=
EXEC-PREFIX   /usr/local
HOST          i686-pc-linux-gnu
LDFLAGS       -L/usr/local/lib -lfreetype
LIB_VERSION   0x636
LIB_VERSION_NUMBER 6,3,6,10
LIBS          -lMagick -ltiff -lfreetype -ljpeg -lfontconfig -lX11 -lz -lm -lpthread
NAME          ImageMagick
PCFLAGS       
PREFIX        /usr/local
QuantumDepth  16
RELEASE_DATE  11/07/07
VERSION       6.3.6
WEBSITE       http://www.imagemagick.org

vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

Any ideas about why I am getting the

ERROR: /invalidfont in --.type42execchar--

errors from my previous post?

Thanks again.
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

bump.

I really need to get this ghostscript error resolved in order to complete my project.

If I run the following command at the shell as one user, it works. If I run the same command as another user, I get the ghostscript error. I use the same TTF font file for both tests. Is it possible that it is a permissions error? I know I have permission to the TTF but is it possible that I do not have a ghostscript permission as the user that gets the error?

command: convert -background white -fill black -font Coopbl.TTF -pointsize 35 label:'text' test.gif

What else could it be?
vbsaltydog

Re: Pass path to TTF file?

Post by vbsaltydog »

Well, I figured it out and thought I would share the solution. I don't know what the permissions error was since my account on this server is so limited but I moved the ttf files to another area of my server space and set the permissions on the ttf files to 755 and it works perfectly using absolute or relative paths so for whatever reason, my user and the apache server account could not read the files from the other directory even though the ttf files were 755.
Post Reply