PHP code example of intellex / stamper

1. Go to this page and download the library: Download intellex/stamper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

intellex / stamper example snippets




// Load stamp or watermark from from any PNG file
$stamp = new Stamp('/path/to/your/stamp.png');

// Feel free to play around with transformations
$stamp->getSource()->resize(200, 100); // Resize to 200 x 100
$stamp->getSource()->rotate(180);      // Rotate by 180 degrees
$stamp->getSource()->setOpacity(0.5);  // Make it 50% translucent

// You can achieve the same effect using Transformation class
$transformation = new Transformation(
	200, 100,   // Width and height
	180,        // Rotation
	0.5         // Opacity
);
$stamp->getSource()->apply($transformation);

// All of the transformation can be done on the Image class in the same way!



// Load the target image from either JPEG or PNG images
$image = Image::fromFile('/path/to/your/target-image.jpeg');

// Execute
$image->stamp($stamp, 100, 100); // Single stamp starting on position 100 x 100
$image->watermark($stamp);       // Tiled watermark across the whole image


  * Class StampImage ads a stamp to the image.
 */
class StampImage extends \Intellex\ImageStamp\Proxy {

	/** @inheritdoc */
	protected function defineCache() {
		return new \Intellex\Filesystem\File('/path/to/where/this/response/will/be/cached.jpeg');
	}

	/** @inheritdoc */
	protected function defineCacheTimeToLive() {
		return 3600; // Cache for 1 hour
	}

	/** @inheritdoc */
	protected function handle() {
		// TODO the magic here
		return 'THE DATA'; // Automatically cached in the file defined in defineCache()
	}

}

new StampImage();

 s StampImage extends Proxy {

	/** @inheritdoc */
	protected function defineCache() {
		return new File('/path/to/where/this/response/will/be/cached.jpeg');
	}

	/** @inheritdoc */
	protected function defineCacheTimeToLive() {
		return 3600; // Cache for 1 hour
	}

	/** @inheritdoc */
	protected function handle() {

		// Skip favicon.ico request
		if($this->getRequestPath() === '/favicon.ico') {
			return null;
		}

		// Load image, load stamp and write to output file
		$image = Image::fromFile('/path/to/your/target-image.jpeg');
		$stamp = new Stamp('/path/to/your/target-image.jpeg', new Transformation(400, 400));
		$image->stamp($stamp, 280, 120);

		// Send the result
		header('Content-Type: ' . $image->getMimeType());
		return $image->getBinary();
	}

}

new StampImage();
nginx
server {
	
	...

	# This should be the first location section in your config 
	location ~* /images/.*\.(jpe?g|png)(?|$) {
		fastcgi_pass	unix:/run/php/php7.1-fpm.sock;
		try_files	/Proxy/watermark.php =409;