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?".
I use Imagemagick from within a php script to resize and watermark images. I
just moved to a new VPS server (Linux) and I find that while the below line of code still does the resizing OK, it no longer applies the watermark. I don't know
how to tell what version of Imagemagick is installed but it might be version
6. I suppose that the problem must be due to incompatibility of the code with a newer version of IM. Does anyone see anything wrong with the line below that could be causing the watermarking to fail?
P.S. the ariblk font is in the same directory as the php script as it was on the old hosting. Everything in the document root directory is identical to the installation on the old server where it worked properly
The image to modify is read in first; you could just try something simple first with your texts to prove they work. I would put your font in the same directory as the code unless it is in the list created by:
<?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>";
?>
Bonzo, you removed the quotes from the '#' colors. not a good idea, especially if the PHP system using a older bourne shell, rather than bash, such as a SUN solaris server. Remember I an a UNIX expert in scripting for different UNIX-like systems.
Also forget using -draw for text drawing, the double quoting is a pain especially with the PHP quoting around that again! Use -annotate instead.
If the string being annotated is user input, feeed that string to the command using a pipeline rather than as a argument. This does two things. One protects yourself from someone trying to hack the shell using shell meta characters and quotes (on purpose or accidentally), and second prevents IM expanding percent escapes. That is why 'read from file' method of annotation (IE -annotate @- or -annotate @filename.txt ) does not do percent escapes.
Of course any and all user input should be throughly tested by your program, but using strings from the user on a command line argument directly is just asking to be hacked.
I checked the IM version, it is Version: ImageMagick 6.0.7 05/03/07 Q16. If it makes any difference, the script was running successfully on the old server under PHP 5. It is running on PHP 5.2.3 on the new server. The font is in the same directory as the script on the new server as it was on the old server.
Bonzo, I tried your modified code and it worked the same as mine did. The resize worked, but drawing the watermark didn't.
As far as hacking is concerned, the image input to that line of code is thoroughly validated earlier in the script so I don't believe there is any danger.
Anyone have any other ideas? Maybe something is missing from the Imagemagick installation?
Anthony, I tried you code and it still does the same thing, it resizes but does not draw. Might it be possible to do the watermarking in sequential steps instead of all as one command? I hope that I do not need to install a newer version of IM. The thought of installing IM (or anything for that matter) from RPM's makes me shudder.
You could replace the -annotate with the a -draw version. But my feeling it you may have a font drawing problem. Can you create a simple label using defaults?
I don't know how to set up your label example, and am a little unclear on what it should do. I did create a very simple script for IM testing. I tried this:
and it saves the image with a new filename "newbackview.jpg" but does not draw anything on it. I have not been able to get anything to draw using either -draw or -annotate.
I have a feeling we have been here before in fact I rember I had the problem when I first started.
My hosts reinstalled ImageMagick and installed GhostScript and it worked.
Out of interest I am on a shared server and have no access to the libreries etc. Is there anyway I can check the version of Ghostscript and what else is installed ?
I think that ghostscript wasn't installed so I just installed it and restarted the VPS. It did not help. Does the path to ghostscript need to be configured in IM somewhere?
I tried to generate a list of installed packages, but the problem is that the list is so long that only the bottom part of the list starting with "ip.." fits in the Putty SSH client window and I have not been able to discover how to scroll upward in the list.
A TTF font should not require ghostscript. However it does require a freetype library. Also are you sure you are running in the same directory as the TTF font you are attempting to use? Have you tried to see the error output from the convert command? Look at Bonzo's Rubbleweb site where he has examples of seeing the error reports from IM commands.
You can also use other commands in your PHP system calls to locate and list directories and other things on your hosting system to make sure the PHP is running in the directory and environment expected.
OK, making progress although I'm darned if I know why. I wrapped my code in Bonzo's error reporting code, and it still did not draw and did not report any errors. Then above my code, I added a piece of Bonzo's error reporting code verbatim from his web page, and strangely enough, now it drew on my image like it was supposed to (Honest! if I wake up in the morning and discover that I was dreaming this, I will let you know).
I experimented further eliminating the error reporting code and using my full watermarking code. It did not work until I replaced the original ariblk.ttf font with verdana.ttf It is curious that the ariblk.ttf font doesn't work when it worked before, but I can live with that problem.
Thanks to you both, Bonzo and Anthony for your kind assistance!