Imagemagick - Watermark - PHP
Posted: 2012-04-16T05:25:12-07:00
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!!
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();
?>