Changes on printing text over an 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
marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Changes on printing text over an image

Post by marciano »

Hello,

This is a part of a code I'm using for serveral years.
It prints text over a semitransparent rectangle in the upper right corner of a photo.
After switching from Centos 6/php5 to Centos 7/php7 only the semitransparent rectangle is printed but the text.

Code: Select all

$n = "A number";
$tama = getimagesize($foto); 
$width = $tama[0] ; 
$height = $tama[1] ;
$a = $width - 13; 
$b = $width - 2;  
$L = 140; 
$A1 = "convert -size {$width}x{$height} xc:transparent \
		-draw \"fill black fill-opacity 0.3 rectangle {$a},0 {$width},{$L} \
			font Helvetica  font-size 13   \
			fill white  \
			translate {$b},{$L} rotate -90 text 0,0 'Some Text Here/{$n}' \" \
		draw_mvg.png";
exec("$A1") ;
$A2 = "composite -gravity Center draw_mvg.png {$foto} {$foto}";
exec("$A2");
The text is not printed, only the rectangle
Image

User avatar
fmw42
Posts: 26108
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Changes on printing text over an image

Post by fmw42 »

Check the ImageMagick versions to see that you have the same delegates and also what versions are being used with what dates.

convert -version

should list them.

marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Changes on printing text over an image

Post by marciano »

The new one
Version: ImageMagick 6.7.8-9 2019-08-08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

I don't have the old version.
If you need it I have a complete backup of the old server but I don't know how to get it from there
Here's a screenshot of files I kept from the old server Image

User avatar
fmw42
Posts: 26108
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Changes on printing text over an image

Post by fmw42 »

On your new system, you do not list the Delegates line? Please provide.

marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Changes on printing text over an image

Post by marciano »

Sorry, here it is:
DELEGATES bzlib fontconfig freetype gs jpeg jng jp2 lcms2 lzma openexr pango png rsvg tiff x11 xml wmf zlib

snibgo
Posts: 12706
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Changes on printing text over an image

Post by snibgo »

Which part of the script doesn't do what you want? I suppose draw_mvg.png isn't what you want. I don't see why it should work. It is drawn at 0,0, so it won't show. And you rotate it by -90 degrees about the (0,0) axis, so it is certainly outside the image. Try "rotate 90", ie 90 degrees clockwise, instead.
snibgo's IM pages: im.snibgo.com

marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Changes on printing text over an image

Post by marciano »

Which part of the script doesn't do what you want?
The text is missing

Code: Select all

font Helvetica  font-size 13   \
			fill white  \
			translate {$b},{$L} rotate -90 text 0,0 'Some Text Here/{$n}' \" \
		draw_mvg.png";
Before Image After Image
I suppose draw_mvg.png isn't what you want.
That's right.
I don't see why it should work.
It worked for several years. I tried rotate 90 instead -90 but it didn't work.
The php script hasn't been changed (I checked with a 2018 backup)

User avatar
fmw42
Posts: 26108
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Changes on printing text over an image

Post by fmw42 »

I suggest you run it directly in a shell window and put in exact numbers so you have a simple command line that we can also test. And post your full input image.

marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Changes on printing text over an image

Post by marciano »

Okay. I am writing a script to replace those without text. To test I'm going to set a fixed text instead of variables and then post the part of ImageMagick for better understanding. Thank you.

marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Changes on printing text over an image

Post by marciano »

Just to get the picture, the variables:

Code: Select all

$n = 98765;
$foto = "ZTA_1864b.jpg";
$foto2 = "ZTA_1864b-2.jpg";
$wi = 293; //width
$he = 440; //height 
$a = $wi - 13; //abscissa from where the vertical strip begins = width - thickness of the vertical strip
$b = $wi - 2;  // a couple of pixels from the right margin for the text
$L = 140; // Height of the text
Here replaced vars by numbers/text (test). The issue is to get draw_mvg.png with the text included

Code: Select all

$A1 = "convert -size 293x440 xc:transparent \
	-draw \"fill black fill-opacity 0.3 rectangle 280,0 293,140 \
		   font Helvetica  font-size 13   \
		   fill white  \
		   translate 291,140 rotate -90 text 0,0 'some.text.here/98765' \" \
	draw_mvg.png";
exec("$A1") ;
Complementary, Overlay draw_mvg.png to the image, not a problem

Code: Select all

$A2 = "composite -gravity Center draw_mvg.png ZTA_1864b.jpg ZTA_1864b-2.jpg";
exec("$A2");
The result is the same as posted before as "after"

marciano
Posts: 17
Joined: 2011-06-18T15:09:09-07:00
Authentication code: 8675308

Re: Changes on printing text over an image

Post by marciano »

Directly from command line I realized what happened

Code: Select all

convert -size 293x440 xc:transparent -draw "fill black fill-opacity 0.3 rectangle 280,0 293,140 font Helvetica  font-size 13  fill white translate 291,140 rotate -90 text 0,0 'some.text.here/98765' " draw_mvg.png
convert: unable to read font `/usr/share/fonts/default/Type1/n019003l.pfb' @ error/annotate.c/RenderFreetype/1124.
convert: Postscript delegate failed `/tmp/magick-0MJd33Xv': No such file or directory @ error/ps.c/ReadPSImage/832.
convert: unable to read font `/usr/share/fonts/default/Type1/n019003l.pfb' @ error/annotate.c/RenderFreetype/1124.
convert: Postscript delegate failed `/tmp/magick-TPW7Lth3': No such file or directory @ error/ps.c/ReadPSImage/832.

The move didn't take into account about the font type
https://bugs.centos.org/view.php?id=16443
https://bugzilla.redhat.com/show_bug.cgi?id=1743658

Tried DejaVu-Sans-Condensed instead of Helvetica and all goes fine again

Post Reply