Watermark all tif images

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?".
cappsie

Re: Watermark all tif images

Post by cappsie »

Hi,

Ok so the first two scripts didn't show anything in the browser, but the second did work:

Code: Select all

<?php
exec("C:/ImageMagick/IMconvert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
Version: ImageMagick 6.8.9-3 Q16 x86 2014-05-30 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib

So the full path works.

While typing this, I managed to get it working AND without any errors :D

Code: Select all

$cmd = "$original_image -font C:/Windows/Fonts/ARIAL.TTF -fill black -pointsize 50 -gravity south -annotate +0+0 \"$text_submitted\" -fill white -annotate +3+3 \"$text_submitted\"  " ;
Oddly, jpg works fine but tif doesn't. I also haven't specified an output file as I thought the default should be fine - the default being the same as the input file.

How can I get the tif format working as it seems to hang when I choose tif rather than jpg.?

Thanks,
Adam.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Watermark all tif images

Post by snibgo »

I also haven't specified an output file as I thought the default should be fine - the default being the same as the input file.
If you don't specify an output file, the command will fail.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Watermark all tif images

Post by fmw42 »

Version: ImageMagick 6.8.9-3 Q16 x86 2014-05-30 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib
There is no released version 6.8.9-3. Did you download the beta?
cappsie

Re: Watermark all tif images

Post by cappsie »

fmw42 wrote:
Version: ImageMagick 6.8.9-3 Q16 x86 2014-05-30 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib
There is no released version 6.8.9-3. Did you download the beta?
I got it from here: http://www.imagemagick.org/script/binar ... hp#windows
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Watermark all tif images

Post by fmw42 »

Those all say ImageMagick-6.8.9-2. So there must be some numbering issue in the download files. Please report your convert -version and this issue on the Bugs forum regarding your Windows download.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Watermark all tif images

Post by fmw42 »

snibgo wrote:
I also haven't specified an output file as I thought the default should be fine - the default being the same as the input file.
If you don't specify an output file, the command will fail.
You will need to specify an output filename, which can be the same as the input. Or just use "null:" (without the quotes) if you do not want any output, but still want to get the error messages.
cappsie

Re: Watermark all tif images

Post by cappsie »

fmw42 wrote:
snibgo wrote:
I also haven't specified an output file as I thought the default should be fine - the default being the same as the input file.
If you don't specify an output file, the command will fail.
You will need to specify an output filename, which can be the same as the input. Or just use "null:" (without the quotes) if you do not want any output, but still want to get the error messages.
Thanks :)

I'm gradually building this command:

Code: Select all

$cmd = "$original_image -font C:/Windows/Fonts/ARIAL.TTF -fill black -pointsize 50 -gravity south -annotate +0+0 \"$text_submitted\" -fill white -annotate +3+3 \"$text_submitted\"  -fill blue -annotate +5+5 \"$text_submitted\" -write $original_image -path C:/TEST " ;
I think my -path is wrong though.
cappsie

Re: Watermark all tif images

Post by cappsie »

Can ImageMagick also offer a link to download the file or perhaps a back button?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Watermark all tif images

Post by fmw42 »

Input files can be specified as http://...../animage.suffix

I do not know what you mean by a back button. IM is command line. I suspect you want to put links in some page that contains an image, but that would be a PHP operation, not IM. Similarly, if you want to download your output image via PHP, you can do that, but it is a php operation. see http://www.rubblewebs.co.uk/index.php for examples of PHP with Imagemagick in particular see http://www.rubblewebs.co.uk/imagemagick/index.php. He has watermarking examples and display of results.
cappsie

Re: Watermark all tif images

Post by cappsie »

That's spot on thanks. I'll have a crack tomorrow :-)

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

Re: Watermark all tif images

Post by fmw42 »

In particular see http://www.rubblewebs.co.uk/imagemagick/index.php. He has watermarking examples and display of results.
cappsie

Re: Watermark all tif images

Post by cappsie »

Hi,

I have the tif watermarking working. I haven't been able to get the -path working correctly - if you have pointers, I'd appreciate it.

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

Re: Watermark all tif images

Post by fmw42 »

cappsie wrote:Hi,

I have the tif watermarking working. I haven't been able to get the -path working correctly - if you have pointers, I'd appreciate it.

Thanks,
Adam.
Please clarify. What -path? Are you using mogrify or convert? What is your exact command?

If mogrify, you must create a new directory to hold the output images before using mogrify. IM cannot create a new directory.

see http://www.imagemagick.org/Usage/basics/#mogrify

I do not believe that convert uses -path. You just specify the path for the output in the filename. The convert options page needs to modified to not that -path is for mogrify, if I am not mistaken about my comment.
cappsie

Re: Watermark all tif images

Post by cappsie »

fmw42 wrote:
cappsie wrote:Hi,

I have the tif watermarking working. I haven't been able to get the -path working correctly - if you have pointers, I'd appreciate it.

Thanks,
Adam.
Please clarify. What -path? Are you using mogrify or convert? What is your exact command?

If mogrify, you must create a new directory to hold the output images before using mogrify. IM cannot create a new directory.

see http://www.imagemagick.org/Usage/basics/#mogrify

I do not believe that convert uses -path. You just specify the path for the output in the filename. The convert options page needs to modified to not that -path is for mogrify, if I am not mistaken about my comment.

Hi,

I've pasted the code below:

Code: Select all

<?php
function clean($name, $max) {
// Remove everything except letters numbers . and @ in the variable
preg_replace("/[^A-Za-z0-9.\-_@]/","",$name);

// Do not allow excessively long entries - length set in function call
// Could use a word wrap here - add a \n after a certain amount of characters
$name = substr($name, 0, $max);
return $name;
}

// If the form has been submitted do this
if(isset($_FILES['filename']['tmp_name'])) {
 
// Temporary upload image name 
$original_image = $_FILES['filename']['tmp_name'];
$filePath = realpath($_FILES["filename"]["tmp_name"]);

// Name to save the image as - in this case the same as the original
// The same folder as the code
$new_image = $_FILES['filename']['name'];  

// Cleanup the text.
$text_submitted = clean ( $_POST['text_submitted'], 18 );

// Build the imagemagick command - using rgba so the opacity of the text can be set
// $cmd = "$original_image -font C:/Windows/Fonts/ARIAL.TTF -fill black -pointsize 50  -gravity south -annotate +0+0 \"$text_submitted\" -fill white -annotate +3+3 \"$text_submitted\"  -fill blue -annotate +5+5 \"$text_submitted\" -write $original_image " ;

$cmd = "$original_image -font C:/Windows/Fonts/ARIAL.TTF -fill rgba(0,0,0,0.4) -pointsize 50  -gravity south -annotate +0+0 \"$text_submitted\" -write $original_image " ;

// Coment out to display the command - good for debugging
//echo $cmd;

// Setup the array for the error reporting
$array = array();

// The array is to hold any errors you may get
// Comment out the if function after debugging
exec("C:/ImageMagick/IMconvert $cmd  $new_image 2>&1", $array);


echo "Graded image saved as: <a href=\"$filePath\">  $original_image s </a>";
echo "<BR />";
echo "<BR />";
echo "Graded text: <B>$text_submitted</B>";
if ( !empty($array) ){
echo "<br />There were some errors during the Imagemagick conversion:<br />
<pre><br />".print_r($array)."<br>"; 
echo "</pre>";
}
            }                      
else { ?>

<form method="post" action="<?php echo  $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<label>Upload file for grading</label> 
<input type="file" name="filename"  /><BR /><BR />
<label>Grading Text</label>
<input type="text" name="text_submitted"  /><br /><BR /><BR />
<input type="Submit" name="Submit" value="Grade File" />
</form>
 <?php } ?> 
Once the tif image has been watermarked, I wanted to offer a link to download it. Oddly I'm only seeing the Windows temporary directory. I suspect either my variables are wrong or the convert command can only display the Widows temp folder.

I've looked over the links you've offered, but I didn't really find anything that helped. However, this page did offer what I need, though I'm unable to work it into the current code: http://salman-w.blogspot.co.uk/2008/11/ ... using.html

Are you able to assist?

Sorry for being a n00b. :-/

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

Re: Watermark all tif images

Post by fmw42 »

Sorry, I do not know PHP that well. Perhaps user Bonzo can help or see his web site at http://www.rubblewebs.co.uk/imagemagick/index.php
Post Reply