Skip to content

Commit

Permalink
* Added new method "crop" for using cropping tools like jcrop
Browse files Browse the repository at this point in the history
* Bugfixes
* Updated readme file
  • Loading branch information
elboletaire committed Apr 18, 2012
1 parent b9d3b21 commit 3339869
Show file tree
Hide file tree
Showing 3 changed files with 290 additions and 171 deletions.
11 changes: 8 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ class FooController extends AppController
// Set image and watermark
$this->Watimage->setImage('test.png');
$this->Watimage->setWatermark('watermark.png');
// Resize image to 400x400px
$this->Watimage->resize(array('type' => 'resizecrop', 'size' => 400));
// Flip it horitzontally
$this->Watimage->flip('horizontal');
// Rotate 90 degrees
$this->Watimage->rotate(90);
// Rotate 45 degrees
$this->Watimage->rotate(45);
// Apply the watermark
$this->Watimage->applyWatermark();
Expand All @@ -86,6 +87,9 @@ You have an example.php file with more examples.

## Changelog

* **0.6** [2012/04/18]
* Added new method 'crop' for using it with cropping tools like jcrop
* Minor bugfixes
* **0.5** [2012/01/14]
* Resolved all transparency issues
* **0.2.3** [2012/01/12]
Expand All @@ -102,7 +106,8 @@ You have an example.php file with more examples.
* Added flip function.
* Minor bugfixes
* **0.1** [2010/06/10]
* First version
* First version


## More info

Expand Down
108 changes: 85 additions & 23 deletions example.php
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
Loading

0 comments on commit 3339869

Please sign in to comment.