PDA

View Full Version : water mark



zahra6377
دوشنبه 09 مرداد 1391, 13:23 عصر
سلام
من میخوام که هر فایل pdf که توی سایتم آپلود میکنم بعد از دانلود water mark مورد نظرم روش خورده بشه .میشه این کار رو با نوشتن کد خاصی انجام داد یا نه؟

zahra6377
دوشنبه 09 مرداد 1391, 18:36 عصر
اینکه جواب ندادید یعنی هیچ راهی نداره؟؟؟؟؟؟

dousti_design
دوشنبه 09 مرداد 1391, 18:47 عصر
function PlaceWatermark($file, $text, $xxx, $yyy, $op, $outdir) {
require_once('fpdf.php');
require_once('fpdi.php');
$name = uniqid();
$font_size = 5;
$ts=explode("\n",$text);
$width=0;
foreach ($ts as $k=>$string) {
$width=max($width,strlen($string));
}
$width = imagefontwidth($font_size)*$width;
$height = imagefontheight($font_size)*count($ts);
$el=imagefontheight($font_size);
$em=imagefontwidth($font_size);
$img = imagecreatetruecolor($width,$height);
// Background color
$bg = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 0, 0,$width ,$height , $bg);
// Font color
$color = imagecolorallocate($img, 0, 0, 0);
foreach ($ts as $k=>$string) {
$len = strlen($string);
$ypos = 0;
for($i=0;$i<$len;$i++){
$xpos = $i * $em;
$ypos = $k * $el;
imagechar($img, $font_size, $xpos, $ypos, $string, $color);
$string = substr($string, 1);
}
}
imagecolortransparent($img, $bg);
$blank = imagecreatetruecolor($width, $height);
$tbg = imagecolorallocate($blank, 255, 255, 255);
imagefilledrectangle($blank, 0, 0,$width ,$height , $tbg);
imagecolortransparent($blank, $tbg);
if ( ($op < 0) OR ($op >100) ){
$op = 100;
}
imagecopymerge($blank, $img, 0, 0, 0, 0, $width, $height, $op);
imagepng($blank,$name.".png");
// Created Watermark Image
$pdf = new FPDI();
if (file_exists("./".$file)){
$pagecount = $pdf->setSourceFile($file);
} else {
return FALSE;
}
$tpl = $pdf->importPage(1);
$pdf->addPage();
$pdf->useTemplate($tpl, 1, 1, 0, 0, TRUE);
//Put the watermark
$pdf->Image($name.'.png', $xxx, $yyy, 0, 0, 'png');
if ($outdir === TRUE){
return $pdf->Output();
} else {
return $pdf;
}
}

PlaceWatermark("filename.pdf", "This is a lazy, but still simple test\n This should stand on a new line!", 30, 120, 100,TRUE);


http://stackoverflow.com/questions/2913934/how-i-can-add-watermark-to-existing-pdf-file-using-php
http://www.fpdf.org/
http://www.setasign.de/products/pdf-php-solutions/fpdi/
لایبرری های دیگه ای هم هست. این یکیشه

zahra6377
دوشنبه 09 مرداد 1391, 22:36 عصر
ممنون
پارامترهای سوم به بعدش چیه؟
فایل های fpdf.php و fpdi.php چی هستن؟
تابع uniqid() چکار میکنه؟

dousti_design
دوشنبه 09 مرداد 1391, 22:57 عصر
توی لینکی که گذاشتم کامل توضیح داده. این پارامترها


$filename – The path of the PDF in which you want to put the Watermark
$text – The Watermark text you want to add
$x – x coordinate where you want to put the Watermark
$y – y coordinate where you want to put the Watermark
$opacity – Opacity of the text
$directoutput – If TRUE function will output a PDF File, else it will return the $pdf

اون فایل ها رو باید از لینکهای دوم و سوم کلاس هاشون رو بردارید.
یونیک آی دی (http://php.net/manual/en/function.uniqid.php) یک رشته یونیک درست میکنه برای نام ازش استفاده کرده.
لینکی که گذاشتم رو بخونید دقیق مشخصه همه چیز

imanitc
سه شنبه 10 مرداد 1391, 09:16 صبح
سلام اگر کاملتر و پيشرفته ترشم بخاهي اين لينک هست
http://www.phpclasses.org/package/7581-PHP-Apply-different-types-of-effects-to-images.html