php-watermark
php-watermark copied to clipboard
function withImage() return false
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.
Hello @libedux ,
Thanks for asking. Can you please specify which one is your case?
- The file
images/watermark.png
exists at the correct path, but watermarking is not happening andwithImage()
returns false - The image
images/watermark.png
does not exist at the correct path. So you are expecting an Exception/Error instead of returningfalse
silently.
Hello @ajaxray
I am getting same issue, I am using this sample code
use Ajaxray\PHPWatermark\Watermark; include 'watermark/autoload.php'; $watermark = new Watermark(__DIR__ . '/pdf/order.pdf'); print_r($watermark); $watermark->setPosition(Watermark::POSITION_TOP_RIGHT); $watermark->setOffset(50, 50); $watermark->setOpacity(.2); $watermark->setTiled(); var_dump($watermark->withImage(__DIR__ . '/img/logo.png', __DIR__ . '/pdf/result_img.pdf'));
Hello @rajansinghrawat and @libedux
I have added a section for debugging steps in README. Can you please try and let me know the outcome?
I got the same issue with some extra text:
if (File::exists($file_path)) {
$watermark = new Watermark($file_path);
$watermark->withImage(public_path('image.jpg'))
->setPosition(Watermark::POSITION_BOTTOM_RIGHT)
->write($file_path);
}
It gives me:
Invalid Parameter - -alpha
Invalid Parameter - 100
PHP Error: Call to a member function setPosition() on bool
Both $file_path
and public_path('image.jpg')
are absolute pathes, which can be check with File::exists($path)
method.
@convers39 Can you please tell me your version of ImageMagick
installation?
@convers39 I guess that you are using the v0.1.2,and running example in github.The style in v0.1.2 is like $watermark->setPosition(watermark::POSITION_BOTTOM_RIGHT); $watermark->withImage($image.jpg, $file_path);