Imagemagick - Watermark - PHP

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
gonzalo_360
Posts: 1
Joined: 2012-04-16T05:14:01-07:00
Authentication code: 8675308

Imagemagick - Watermark - PHP

Post by gonzalo_360 »

Hi,
I have some problems with watermark, when i put this over pdf image, the weight of the result image is very huge. Here is the code:
Thank you for your help!!

Code: Select all

<?php

include('includes/config.php');
include('includes/conn.php');
include('includes/myfunc.php');

error_reporting(E_ALL); // Muestra los errores
ini_set("display_errors", 1); // Coloca en ON display_errors
ini_set("max_execution_time", 480); //seteo el tiempo de ejecucion solo para este proceso en 480 segundos
session_start();

$path	= addslashes( $_REQUEST['p'] );
$w	 = intval( $_REQUEST['w'] );
$h	 = intval( $_REQUEST['h'] );
$marca	= addslashes( $_REQUEST['m'] );
$tabla	= addslashes( $_REQUEST['t'] );

$sql = "select * from $tabla where path ='$path'";

$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$row['IDlote'];
$idlote = $row['IDlote'];

$consulta = "select archivo from tb_archivos where IDlote ='$idlote' order by orden";
$resultado = mysql_query($consulta);

$im = new Imagick();
$im->setResourceLimit( Imagick::RESOURCETYPE_MEMORY, 500 );

while($arr = mysql_fetch_array($resultado, MYSQL_ASSOC)){ 
foreach( $arr as $f ) 
{ 

$auxIMG = new Imagick();
$auxIMG->readImage($path.'/'.$f);



// watermark
if($marca != ''){
$draw = new ImagickDraw();
$draw->setFont('fonts/arial.ttf');
$draw->setFontSize( 100 );	
$draw->setFontWeight( 700 );
$draw->setFillAlpha( 0.5 );	
$draw->setGravity( Imagick::GRAVITY_CENTER );
$auxIMG->annotateImage( $draw, 0, 0, -45, $marca );
}


$im->addImage($auxIMG);


} 
}

$docname = substr( strrchr($path, '/'), 1);

$pdf = 'temp/'.$docname.'.pdf';

$im->writeImages($pdf, true);

header( "Content-Type: application/pdf" ); 
header('Content-Disposition: attachment; filename='.$pdf);
header('Content-Length: '.filesize($pdf));
readfile($pdf);

unlink($pdf);

session_commit();
?>
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Imagemagick - Watermark - PHP

Post by anthony »

Can you simplify, with some small test images, and exactly what you were expecting?

See How To Ask Questions The Smart Way
from Read this first before posting a new topic
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply