Update v1.0.6
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_addNoise extends Demo
|
||||
{
|
||||
public $order = 9350;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new SelectField('type', array('salt&pepper','mono','color'), 'mono'));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->addNoise($this->fields['amount']->value, $this->fields['type']->value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyConvolution extends Demo
|
||||
{
|
||||
public $order = 2025;
|
||||
|
||||
protected $base_matrix = array(array(2, 0, 0), array(0, -1, 0), array(0, 0, -1));
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new Field('matrix', '2 0 0, 0 -1 0, 0 0 -1', '3x3 float matrix; separate rows with a comma, and columns with a space'));
|
||||
$this->addField(new FloatField('div', 1));
|
||||
$this->addField(new FloatField('offset', 220));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$mstr = $this->fval('matrix');
|
||||
$rows = explode(',', $mstr);
|
||||
|
||||
$matrix = array();
|
||||
foreach ($this->base_matrix as $idx => $base_row)
|
||||
{
|
||||
$build_row = array();
|
||||
if (isset($rows[$idx]))
|
||||
{
|
||||
$row = trim($rows[$idx]);
|
||||
$cols = explode(' ', $row);
|
||||
for ($c = 0; $c < 3; $c++)
|
||||
if (isset($cols[$c]))
|
||||
$build_row[] = floatval(trim($cols[$c]));
|
||||
else
|
||||
$build_row[] = $base_row[$c];
|
||||
}
|
||||
else
|
||||
$build_row = $base_row;
|
||||
|
||||
$matrix[] = $build_row;
|
||||
}
|
||||
|
||||
return $image->applyConvolution($matrix, $this->fval('div'), $this->fval('offset'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyFilter extends Demo
|
||||
{
|
||||
public $order = 2000;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new SelectField('filter', array(
|
||||
'IMG_FILTER_NEGATE',
|
||||
'IMG_FILTER_GRAYSCALE',
|
||||
'IMG_FILTER_BRIGHTNESS',
|
||||
'IMG_FILTER_CONTRAST',
|
||||
'IMG_FILTER_COLORIZE',
|
||||
'IMG_FILTER_EDGEDETECT',
|
||||
'IMG_FILTER_EMBOSS',
|
||||
'IMG_FILTER_GAUSSIAN_BLUR',
|
||||
'IMG_FILTER_SELECTIVE_BLUR',
|
||||
'IMG_FILTER_MEAN_REMOVAL',
|
||||
'IMG_FILTER_SMOOTH'
|
||||
))
|
||||
);
|
||||
$this->addField(new IntField('arg1', null));
|
||||
$this->addField(new IntField('arg2', null));
|
||||
$this->addField(new IntField('arg3', null));
|
||||
}
|
||||
|
||||
function execute($image)
|
||||
{
|
||||
$filter = constant($this->fields['filter']->value);
|
||||
$arg1 = $this->fields['arg1']->value;
|
||||
$arg2 = $this->fields['arg2']->value;
|
||||
$arg3 = $this->fields['arg3']->value;
|
||||
|
||||
return $image->applyFilter($filter, $arg1, $arg2, $arg3);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyMask extends Demo
|
||||
{
|
||||
public $order = 600;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('mask', 'masks'));
|
||||
$this->addField(new CoordinateField('left', 10));
|
||||
$this->addField(new CoordinateField('top', '30%'));
|
||||
|
||||
if (!$this->request->get('mask'))
|
||||
$this->request->set('mask', 'mask-circle.gif');
|
||||
}
|
||||
|
||||
function execute($image)
|
||||
{
|
||||
$mask = WideImage::load(DEMO_PATH . 'masks/' . $this->fields['mask']->value);
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
|
||||
return $image->applyMask($mask, $left, $top);
|
||||
}
|
||||
|
||||
function getFormat()
|
||||
{
|
||||
return 'png';
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_asGrayscale extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->asGrayscale();
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_asNegative extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->asNegative();
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_autoCrop extends Demo
|
||||
{
|
||||
public $order = 1050;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('margin', 0));
|
||||
$this->addField(new IntField('rgb_threshold', 0));
|
||||
$this->addField(new IntField('pixel_cutoff', 1));
|
||||
$this->addField(new IntField('base_color', null, 'Index of the color'));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$margin = $this->fields['margin']->value;
|
||||
$rgb_threshold = $this->fields['rgb_threshold']->value;
|
||||
$pixel_cutoff = $this->fields['pixel_cutoff']->value;
|
||||
$base_color = $this->fields['base_color']->value;
|
||||
|
||||
return $image->autoCrop($margin, $rgb_threshold, $pixel_cutoff, $base_color);
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_correctGamma extends Demo
|
||||
{
|
||||
public $order = 2050;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new FloatField('in_gamma', 1.1));
|
||||
$this->addField(new FloatField('out_gamma', 3.7));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->correctGamma($this->fval('in_gamma'), $this->fval('out_gamma'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_crop extends Demo
|
||||
{
|
||||
public $order = 1000;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('left', 10));
|
||||
$this->addField(new CoordinateField('top', 20));
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', 60));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
|
||||
return $image->crop($left, $top, $width, $height);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_flip extends Demo
|
||||
{
|
||||
public $order = 1200;
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->flip();
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getCanvas extends Demo
|
||||
{
|
||||
public $order = 1300;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new Field('text', 'Hello world!'));
|
||||
$this->addField(new CoordinateField('x', 'middle'));
|
||||
$this->addField(new CoordinateField('y', 'bottom-5'));
|
||||
$this->addField(new IntField('angle', 5));
|
||||
$this->addField(new FileSelectField('font', 'fonts', array('show' => false, 'pattern' => '/(.*)\.ttf$/', 'default' => 'VeraSe.ttf')));
|
||||
$this->addField(new IntField('size', 18));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$text = $this->fields['text']->value;
|
||||
$x = $this->fields['x']->value;
|
||||
$y = $this->fields['y']->value;
|
||||
$angle = $this->fields['angle']->value;
|
||||
$font = $this->fields['font']->value;
|
||||
$font_size = $this->fields['size']->value;
|
||||
|
||||
$canvas = $image->getCanvas();
|
||||
|
||||
$canvas->filledRectangle(10, 10, 80, 40, $image->allocateColor(255, 127, 255));
|
||||
$canvas->line(60, 80, 30, 100, $image->allocateColor(255, 0, 0));
|
||||
|
||||
$font_file = DEMO_PATH . 'fonts/' . $font;
|
||||
|
||||
$canvas->useFont($font_file, $font_size, $image->allocateColor(0, 0, 0));
|
||||
$canvas->writeText("$x+1", "$y+1", $text, $angle);
|
||||
|
||||
$canvas->useFont($font_file, $font_size, $image->allocateColor(200, 220, 255));
|
||||
$canvas->writeText($x, $y, $text, $angle);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
function et($name)
|
||||
{
|
||||
return htmlentities($this->fval($name));
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
echo "This demo executes:
|
||||
<pre>
|
||||
\$canvas->filledRectangle(10, 10, 80, 40, \$img->allocateColor(255, 127, 255));
|
||||
\$canvas->line(60, 80, 30, 100, \$img->allocateColor(255, 0, 0));
|
||||
|
||||
\$canvas->useFont('{$this->et('font')}', '{$this->et('size')}', \$image->allocateColor(0, 0, 0));
|
||||
\$canvas->writeText('{$this->et('x')}+1', '{$this->et('y')}+1', '{$this->et('text')}', {$this->et('angle')});
|
||||
|
||||
\$canvas->useFont('{$this->et('font')}', '{$this->et('size')}', \$image->allocateColor(200, 220, 255));
|
||||
\$canvas->writeText('{$this->et('x')}', '{$this->et('y')}', '{$this->et('text')}', {$this->et('angle')});
|
||||
</pre>";
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getChannels extends Demo
|
||||
{
|
||||
public $order = 500;
|
||||
|
||||
protected $channels = array('red', 'green', 'blue', 'alpha');
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CheckboxField('red', true));
|
||||
$this->addField(new CheckboxField('green', false));
|
||||
$this->addField(new CheckboxField('blue', true));
|
||||
$this->addField(new CheckboxField('alpha', false));
|
||||
}
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
$on = array();
|
||||
foreach ($this->channels as $name)
|
||||
if ($this->fields[$name]->value)
|
||||
$on[] = $name;
|
||||
|
||||
return $img->getChannels($on);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getMask extends Demo
|
||||
{
|
||||
public $order = 550;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->getMask();
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_merge extends Demo
|
||||
{
|
||||
public $order = 800;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('overlay', 'images', array('default' => '6-logo.gif')));
|
||||
$this->addField(new CoordinateField('left', 'right-10'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-15%'));
|
||||
$this->addField(new IntField('opacity', 50));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$overlay = WideImage::load(DEMO_PATH . 'images/' . $this->fields['overlay']->value);
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$opacity = $this->fields['opacity']->value;
|
||||
|
||||
return $image->merge($overlay, $left, $top, $opacity);
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
echo "For alpha images, set opacity=100, otherwise alpha channel won't work.";
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_mirror extends Demo
|
||||
{
|
||||
public $order = 1150;
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->mirror();
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_resize extends Demo
|
||||
{
|
||||
public $order = 900;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', null));
|
||||
$this->addField(new SelectField('fit', array('inside', 'fill', 'outside')));
|
||||
$this->addField(new SelectField('scale', array('any', 'down', 'up')));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
$fit = $this->fields['fit']->value;
|
||||
$scale = $this->fields['scale']->value;
|
||||
|
||||
return $image->resize($width, $height, $fit, $scale);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_resizeCanvas extends Demo
|
||||
{
|
||||
public $order = 910;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', '100%+30'));
|
||||
$this->addField(new CoordinateField('height', 200));
|
||||
$this->addField(new CoordinateField('left', '2'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-10'));
|
||||
$this->addField(new ColorField('color', 'ffffff'));
|
||||
$this->addField(new SelectField('scale', array('any', 'down', 'up'), 'any'));
|
||||
$this->addField(new CheckboxField('merge', false, "Merge or copy over"));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$width = $this->fields['width']->value;
|
||||
$height = $this->fields['height']->value;
|
||||
$left = $this->fields['left']->value;
|
||||
$top = $this->fields['top']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
$scale = $this->fields['scale']->value;
|
||||
$merge = $this->fields['merge']->value;
|
||||
|
||||
return $image->resizeCanvas($width, $height, $left, $top, $color ? hexdec($color) : null, $scale, $merge);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_rotate extends Demo
|
||||
{
|
||||
public $order = 1100;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new AngleField('angle', 25));
|
||||
$this->addField(new ColorField('color', ''));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$angle = $this->fields['angle']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
|
||||
return $image->rotate($angle, $color ? hexdec($color) : null);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_roundCorners extends Demo
|
||||
{
|
||||
public $order = 1075;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('radius', 30));
|
||||
$this->addField(new ColorField('color', 'ffffff'));
|
||||
$this->addField(new IntField('smoothness', 2));
|
||||
|
||||
$this->addField(new CheckboxField('top-left', true));
|
||||
$this->addField(new CheckboxField('top-right', true));
|
||||
$this->addField(new CheckboxField('bottom-right', true));
|
||||
$this->addField(new CheckboxField('bottom-left', true));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
$color = $this->fields['color']->value;
|
||||
$radius = $this->fields['radius']->value;
|
||||
$smoothness = $this->fields['smoothness']->value;
|
||||
|
||||
$corners = 0;
|
||||
if ($this->fval('top-left'))
|
||||
$corners += WideImage::SIDE_TOP_LEFT;
|
||||
|
||||
if ($this->fval('top-right'))
|
||||
$corners += WideImage::SIDE_TOP_RIGHT;
|
||||
|
||||
if ($this->fval('bottom-right'))
|
||||
$corners += WideImage::SIDE_BOTTOM_RIGHT;
|
||||
|
||||
if ($this->fval('bottom-left'))
|
||||
$corners += WideImage::SIDE_BOTTOM_LEFT;
|
||||
|
||||
return $image->roundCorners($radius, $color ? hexdec($color) : null, $smoothness, $corners);
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_unsharp extends Demo
|
||||
{
|
||||
public $order = 1350;
|
||||
|
||||
function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new IntField('radius', 3));
|
||||
$this->addField(new IntField('threshold', 2));
|
||||
}
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->unsharp($this->fields['amount']->value, $this->fields['radius']->value, $this->fields['threshold']->value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user