ajaxray / php-watermark Goto Github PK
View Code? Open in Web Editor NEWAdd text or image Watermark on image and PDF files
License: MIT License
Add text or image Watermark on image and PDF files
License: MIT License
list($width, $height) = getimagesize($this->inputSrcWM);
$watermark->setTileSize($width * $this->tile_ratio, $height * $this->tile_ratio);
looks like do not work for image logo source.
$data = new File();
$data->name = $request->input('name');
$this->validate($request, ['file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', ] //only allow this type extension file.
);
$file = $request->file('file');
$ext = $file->getClientOriginalExtension();
$newName = rand(100000, 1001238912) . "." . $ext;
$file->move('uploads/file', $newName);
$data->file = $newName;
$data->save();
I am new to Laravel, what I'm doing here is to get a new name for the file and save it to the db as well as to the uploads/file folder. I want to be able to watermark the image i upload as well as retain the naming convention. Example name of the file could be 426240098.jpeg. I'll appreciate your help
Hi ! I have tried to generate a Pdf file with Image ,but the contents of the pdf become indistinct.Is it possible to make it clear as the original one?
Hi,
Is there any plan to update this package to have text color functionality?
Actually i tried to change rgba color in this function getDuelTextColor
but unfortunately it does't work.
Can you give me a hand in this if you don't plan to update this package soon.
I am getting the code to work exactly as I'd hoped on my live server. I am using wamp locally, and it seems that the file isn't writing even though I'm using chmod on the directory and setting it to 0777. Is there any reason I should think of why your code wouldn't write a new file on a windows server?
Thanks!
Kyle
Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in src\Ajaxray\PHPWatermark\Watermark.php on line 31
In testing, this package has been working flawlessly. However, I got the final document we're going to use live. For some reason, that document doesn't work.
The original PDF is 853KB. However when I try and watermark it with my name and email, it blows up to like 20MB in size, and the outputted file is corrupted and can't be open. Please note, nothing about this code changes except pointing to a different PDF.
$documentPath = BEDROCK_CONFIG_DIR . '/1519939315.XeevRAl27BGXn9MAVctvCYBATWxL88sKm04YU1e5.pdf';
$inputFile = '1519939315.XeevRAl27BGXn9MAVctvCYBATWxL88sKm04YU1e5.pdf';
$watermark = new Watermark(BEDROCK_CONFIG_DIR . '/1519939315.XeevRAl27BGXn9MAVctvCYBATWxL88sKm04YU1e5.pdf');
// set watermark text
$text = $row->first_name . " " . $row->last_name . " \r\n " . $row->email;
// Watermark with text
$watermark->setFont('AvantGarde-BookOblique');
$watermark->setFontSize(24);
$watermark->setRotate(345);
$watermark->setOffset(0, 0);
$watermark->setOpacity(.2);
$watermark->setPosition(Watermark::POSITION_CENTER);
// write file to hd
$outputFile = BEDROCK_CONFIG_DIR . '/output/' . $inputFile;
$watermark->withText($text, $outputFile);
I am not getting any errors in the console other than it takes a long time obviously. Is there any specific way I need to save PDFs, or format them in a specific way?
EDIT: The PDFs are just word documents I click save as PDF or print to PDF. The latest test I did this way created a PDF 2MB. When I ran the above script over it, the output was 13MB (Only putting my name & email as you can see).
In this last example, it opened OK, but why did adding my name & email to each page (81 pages), increase the size by 11MB?
Hi,
I have a transparent watermark which is basically a rectangle with white borders and the letters of my website inside written in white as well. The rest is transparency. It works very well but as you can imagine, when I apply this watermark on bright images, my watermark doesn't show up, it's almost invisible.
It would be nice if we could have an option to adjust the watermark image contrast/colors depending of the background, just like mix-blend-mode
in CSS: https://css-tricks.com/almanac/properties/m/mix-blend-mode/
To make it short: a watermark that adapts to the background.
Hi,
I'm using the script without composer. I downloaded the archive and tried to run the example_img.php.
I had to change the include 'vendor/autoload.php';
since there's no autoload.php file (I suppose this come from Composer)
I used the following include :
include '../src/Ajaxray/PHPWatermark/Watermark.php';
I get the following error:
Uncaught Error: Class 'Ajaxray\PHPWatermark\CommandBuilders\ImageCommandBuilder' not found in /src/Ajaxray/PHPWatermark/Watermark.php:112
Any ideas on what I'm doing wrong? I have not modified any other files.
Thanks!
What is the problem when i try to add watermark to my PDF file and it turn to very bad resolution?
I need do not make tile with big borders? but i want to tile with step.
I am using this package to apply watermark on pdf files bu watermark does not merged with pdf file, instead withImage() function return false.
$watermark = 'images/watermark.png';
if ($model->extension == 'pdf') {
$pdf = new Watermark($fileName); // $fileName is string that contain path to pdf file
$pdf->withImage($watermark);
}
The problem is, it does not throw any error like file not exist or etc. it just returns false.
Hi Anis Uddin Ahmad,
I'm using text like "Approuvé, Non Publié" and it has been converting text like "Approuv, Non Publi" as a watermark. This removing "é" from the original text.
Thank You in Advance.
Cant see Ajaxarray namespace
I have both install ghostscript and ImageMagick, and i used laravel framework. When i used image watermark is works very well, but when i used pdf watermark. it seems nothing has happen. Am i do wrong?
This is my code :
if($id_watermark->fileext == 'image/jpeg' || $id_watermark->fileext == 'image/png') { /* Watermarking with Text */ $watermark = new Watermark('upload/'.$id_watermark->files); $watermark->setTiled() ->setTileSize(300, 300) ->setFontSize(24) ->setRotate(330) ->setOffset(60, 0); $text = "Verified"; $watermark->withText($text, 'upload/'.$id_watermark->files); } elseif($id_watermark->fileext == 'application/pdf') { /* Watermarking with Text */ $watermark = new Watermark('upload/'.$id_watermark->files); $watermark->setFont('Arial'); $watermark->setFontSize(18); $watermark->setRotate(345); $watermark->setOffset(20, 60); $watermark->setPosition(Watermark::POSITION_BOTTOM_RIGHT); $text = "Verified"; $watermark->withText($text, 'upload/'.$id_watermark->files); }
code when the extension is pdf is not working. Is it any way to properly used ghostscript?
I have a trouble which described here
http://www.imagemagick.org/discourse-server/viewtopic.php?t=31549
When I use a png image as a watermark I get gray background as a result.
So I propose to make changes in the method getMarkerOpacity of class PDFCommandBuilder:
replace strings
$opacity = $this->getOpacity() * 100;
return "-alpha set -channel A -evaluate set {$opacity}%";
with strings
$opacity = $this->getOpacity();
return "-alpha set -channel A -evaluate multiply {$opacity}";
Hi,
I am trying your script but it is not working giving the following error. Can you please at this for me, Thanks in advance.
Fatal error: Uncaught BadFunctionCallException: ImageMagick not found in this system. in www\php-watermark\src\Ajaxray\PHPWatermark\Requirements\RequirementsChecker.php:12 Stack trace: #0 www\php-watermark\src\Ajaxray\PHPWatermark\CommandBuilders\AbstractCommandBuilder.php(16): Ajaxray\PHPWatermark\Requirements\RequirementsChecker->ensureImagemagickInstallation() #1 www\php-watermark\src\Ajaxray\PHPWatermark\CommandBuilders\CommandBuilderFactory.php(15): Ajaxray\PHPWatermark\CommandBuilders\AbstractCommandBuilder->__construct('C:\laragon6\www...') #2 www\php-watermark\src\Ajaxray\PHPWatermark\Watermark.php(54): Ajaxray\PHPWatermark\CommandBuilders\CommandBuilderFactory::getCommandBuilder('\www...') #3 www\php-watermark\examples\example_img.php(7): Ajaxray\PHPWatermark\Watermark->__construct('C:\laragon6\www...') #4 {main} thrown in \www\php-watermark\src\Ajaxray\PHPWatermark\Requirements\RequirementsChecker.php on line 12
My PHP details
Php version 8.1.x
imagick extension enabled and version is php_imagick-3.5.1-7.3-nts-vc15-x64
Example useges
Watermark::setStretch('90%');
Watermark::setStretch(200, 200);
Just ran the examples provided here and the pdfs are simply not being generated. Nothing happens at all. No erros and no exceptions being thrown.
Can someone give me a light?
UPDATE:
So, checking my apache error log, it turns out I have this error
sh: convert: command not found
Which is odd, because I can run convert from bash
Hi, I was wondering if it's possible to apply watermarks to specific pages instead of all? I have a 500+ page PDF and I'd like to apply the watermark on only the first page. Ideally, I should be able to get the total number of pages and if it exceeds a certain number (say, 20), I apply the watermark on only the first page.
Hi friend
I have used your library for pdf watermark and it would be working well but pdf quality is distorted, can you please guide me how to make it same as original with watermark.
Thanks!
Jigs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.