Skip to content

Commit

Permalink
watermark with image
Browse files Browse the repository at this point in the history
  • Loading branch information
maztch committed Dec 2, 2020
1 parent 2280d16 commit 593e689
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
29 changes: 29 additions & 0 deletions samples/watermark_basic_image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');

use Ilovepdf\WatermarkTask;

// you can call task class directly
// to get your key pair, please visit https://developer.ilovepdf.com/user/projects
$myTask = new WatermarkTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addFile('/path/to/file/document.pdf');

$watermakImage = $myTask->addElementFile('/path/to/image/image.png');

// set mode to image
$myTask->setMode("image");

// set the image
$myTask->setImageFile($watermakImage);

// process files
$myTask->execute();

// and finally download the unlocked file. If no path is set, it will be downloaded on current folder
$myTask->download();
21 changes: 21 additions & 0 deletions src/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Element


public $bold = false;

/**
* string
* @var
Expand Down Expand Up @@ -260,4 +261,24 @@ public function setHorizontalPositionAdjustment($horizontal_position_adjustment)
$this->horizontal_position_adjustment = $horizontal_position_adjustment;
return $this;
}

/**
* @param mixed $server_filename
* @return Element
*/
public function setServerFilename($server_filename)
{
$this->server_filename = $server_filename;
return $this;
}

/**
* @param File $file
* @return Element
*/
public function setFile($file)
{
$this->server_filename = $file->getServerFilename();
return $this;
}
}
18 changes: 18 additions & 0 deletions src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ public function uploadFile($task, $filepath)
return new File($response->body->server_filename, basename($filepath));
}

/**
* @param string $filePath
* @return File
*/
public function addElementFile($filePath)
{
return $this->uploadFile($this->task, $filePath);
}

/**
* @param string $url
* @return File
*/
public function addElementFileFromUrl($url)
{
return $this->uploadUrl($this->task, $url);
}

/**
* @return Task
*/
Expand Down
11 changes: 10 additions & 1 deletion src/WatermarkTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WatermarkTask extends Task
/**
* @var string
*/
public $text;
public $text;

/**
* @var strig
Expand Down Expand Up @@ -147,6 +147,15 @@ public function setImage($image)
return $this;
}

/**
* @param File $image
*/
public function setImageFile(File $imageFile)
{
$this->image = $imageFile->getServerFilename();
return $this;
}

/**
* @param string $pages
*/
Expand Down

0 comments on commit 593e689

Please sign in to comment.