php-watermark icon indicating copy to clipboard operation
php-watermark copied to clipboard

function withImage() return false

Open libedux opened this issue 5 years ago • 6 comments

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.

libedux avatar Jan 24 '19 14:01 libedux

Hello @libedux ,

Thanks for asking. Can you please specify which one is your case?

  1. The file images/watermark.png exists at the correct path, but watermarking is not happening and withImage() returns false
  2. The image images/watermark.png does not exist at the correct path. So you are expecting an Exception/Error instead of returning false silently.

ajaxray avatar Dec 13 '19 02:12 ajaxray

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'));

rajansinghrawat avatar Feb 12 '20 09:02 rajansinghrawat

Hello @rajansinghrawat and @libedux

I have added a section for debugging steps in README. Can you please try and let me know the outcome?

ajaxray avatar May 08 '20 18:05 ajaxray

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 avatar Nov 04 '21 09:11 convers39

@convers39 Can you please tell me your version of ImageMagick installation?

ajaxray avatar Nov 04 '21 17:11 ajaxray

@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);

xihuantudi avatar Nov 25 '21 01:11 xihuantudi