forked from elboletaire/Watimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new method "crop" for using cropping tools like jcrop
* Bugfixes * Updated readme file
- Loading branch information
1 parent
b9d3b21
commit 3339869
Showing
3 changed files
with
290 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,119 @@ | ||
<?php | ||
error_reporting(E_ALL); | ||
ini_set('display_errors', '1'); | ||
require 'watermark.php'; | ||
|
||
// Applying watermarks | ||
date_default_timezone_set('UTC'); | ||
|
||
require 'watimage.php'; | ||
|
||
|
||
/************************ | ||
*** APPLY WATERMARKS *** | ||
************************/ | ||
$wm = new Watimage(); | ||
$wm->setImage(array('file' => 'test.png', 'quality' => 50)); | ||
$wm->setWatermark(array('file' => 'watermark.png', 'position' => 'top right')); | ||
$wm->applyWatermark(); | ||
$wm->setImage(array('file' => 'test.png', 'quality' => 70)); // file to use and export quality | ||
$wm->setWatermark(array('file' => 'watermark.png', 'position' => 'top right')); // watermark to use and it's position | ||
$wm->applyWatermark(); // apply watermark to the canvas | ||
if ( !$wm->generate('test1.png') ) { | ||
// handle error... | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
|
||
// Resize | ||
/********************* | ||
*** RESIZE IMAGES *** | ||
*********************/ | ||
$wm = new Watimage('test.png'); | ||
// allowed types: resize, resizecrop, resizemin, crop | ||
$wm->resize(array('type' => 'resizecrop', 'size' => array(400, 200))); | ||
if ( !$wm->generate('test2.png') ) { | ||
// handle error... | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
|
||
|
||
// Rotate | ||
/********************* | ||
*** ROTATE IMAGES *** | ||
*********************/ | ||
$wm = new Watimage('test.png'); | ||
$wm->rotate(90); | ||
if ( !$wm->generate('test3.png') ) { | ||
// handle error... | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
|
||
// Exporting to other format | ||
/********************************** | ||
*** EXPORTING TO OTHER FORMATS *** | ||
**********************************/ | ||
$wm = new Watimage('test.png'); | ||
if ( !$wm->generate('test4.jpg') ) { | ||
// handle error... | ||
if ( !$wm->generate('test4.jpg', 'image/jpeg') ) { | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
|
||
// Flip | ||
/******************* | ||
*** FLIP IMAGES *** | ||
*******************/ | ||
$wm = new Watimage('test.png'); | ||
$wm->flip('vertical'); | ||
$wm->flip('vertical'); // or "horizontal" | ||
if ( !$wm->generate('test5.png') ) { | ||
// handle error... | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
|
||
// All together | ||
$wm = new Watimage('test.png', 'watermark.png'); | ||
$wm->resize(array('type' => 'resizecrop', 'size' => 400)); | ||
|
||
/*********************** | ||
*** CROPPING IMAGES *** | ||
***********************/ | ||
// Usefull for cropping plugins like https://github.com/tapmodo/Jcrop | ||
$wm = new Watimage('test.png'); | ||
$wm->crop(array( // values from the cropper | ||
'width' => 500, // the cropped width | ||
'height' => 500, // " " height | ||
'x' => 50, | ||
'y' => 80 | ||
)); | ||
if ( !$wm->generate('test6.png') ) { | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
|
||
|
||
/*************************** | ||
*** EVERYTHING TOGETHER *** | ||
***************************/ | ||
|
||
$wm = new Watimage(); | ||
|
||
// Set the image | ||
$wm->setImage('test.png'); // you can also set the quality with setImage, you only need to change it with an array: array('file' => 'test.png', 'quality' => 70) | ||
|
||
// Set the export quality | ||
$wm->setQuality(80); | ||
|
||
// Set a watermark | ||
$wm->setWatermark(array( | ||
'file' => 'watermark.png', // the watermark file | ||
'position' => 'center center', // the watermark position works like CSS backgrounds positioning | ||
'margin' => array('x' => -20, 'y' => 10), // you can set some 'margins' to the watermark for better positioning | ||
'size' => 'full' // you can set the size of the watermark using a percentage or the word "full" for getting a full width/height watermark | ||
)); | ||
|
||
// Resize the image | ||
$wm->resize(array('type' => 'resize', 'size' => 400)); | ||
|
||
// Flip it | ||
$wm->flip('horizontal'); | ||
$wm->rotate(90); | ||
|
||
// Now rotate it 30deg | ||
$wm->rotate(30); | ||
|
||
// It's time to apply the watermark | ||
$wm->applyWatermark(); | ||
if ( !$wm->generate('test6.png') ) { | ||
// handle error... | ||
|
||
// Export the file | ||
if ( !$wm->generate('test7.png') ) { | ||
// handle errors... | ||
print_r($wm->errors); | ||
} | ||
} | ||
|
||
// END OF FILE |
Oops, something went wrong.