Applied fixes from StyleCI
This commit is contained in:
committed by
StyleCI Bot
parent
be5df5334f
commit
d637c2b23f
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
/**
|
||||
*/
|
||||
?>
|
||||
<form style="font-family: Verdana, Tahoma; font-size: 11px">
|
||||
<input type="hidden" name="demo" value="<?php echo $activeDemo->name; ?>" />
|
||||
<div style="background-color: #f0f0f0; padding: 5px;">
|
||||
<input type="submit" value="refresh" />
|
||||
<?php
|
||||
foreach ($activeDemo->fields as $field)
|
||||
$field->render();
|
||||
foreach ($activeDemo->fields as $field) {
|
||||
$field->render();
|
||||
}
|
||||
?>
|
||||
<br />
|
||||
<span style="font-family: Verdana, Tahoma; font-size: 11px">
|
||||
@@ -18,49 +18,51 @@
|
||||
|
||||
<div style="background-color: #d0d0d0; padding: 5px; text-align: right; float: right; width: 300px;">
|
||||
<?php
|
||||
$top_form['output']->render();
|
||||
echo "<br />\n";
|
||||
echo ' Palette options (only for <em>png8</em> and <em>gif</em> output):<br />';
|
||||
$top_form['ncolors']->render();
|
||||
echo "<br />\n";
|
||||
$top_form['dither']->render();
|
||||
$top_form['match_palette']->render();
|
||||
$top_form['output']->render();
|
||||
echo "<br />\n";
|
||||
echo ' Palette options (only for <em>png8</em> and <em>gif</em> output):<br />';
|
||||
$top_form['ncolors']->render();
|
||||
echo "<br />\n";
|
||||
$top_form['dither']->render();
|
||||
$top_form['match_palette']->render();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
$activeDemo->text();
|
||||
$activeDemo->text();
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
$images_in_row = 2;
|
||||
$in_row = 0;
|
||||
$images = array();
|
||||
$di = new DirectoryIterator(dirname(__FILE__) . '/images/');
|
||||
foreach ($di as $file)
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0)
|
||||
$images[] = $file->getFilename();
|
||||
|
||||
asort($images);
|
||||
foreach ($images as $image_file)
|
||||
{
|
||||
echo '<div class="images">';
|
||||
echo '<img src="images/' . $image_file . '" />';
|
||||
$img_url = 'image.php?image=' . $image_file . '&output=' . $top_form['output']->value .
|
||||
'&colors=' . $top_form['ncolors']->value . '&dither=' . $top_form['dither']->value .
|
||||
'&match_palette=' . $top_form['match_palette']->value . '&demo=' . $activeDemo->name;
|
||||
foreach ($activeDemo->fields as $field)
|
||||
$img_url .= '&' . $field->getURLValue();
|
||||
|
||||
echo ' ';
|
||||
echo '<a href="' . $img_url . '">';
|
||||
echo '<img src="' . $img_url . '" />';
|
||||
echo '</a>';
|
||||
echo "</div>\n";
|
||||
}
|
||||
$images_in_row = 2;
|
||||
$in_row = 0;
|
||||
$images = [];
|
||||
$di = new DirectoryIterator(dirname(__FILE__).'/images/');
|
||||
foreach ($di as $file) {
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0) {
|
||||
$images[] = $file->getFilename();
|
||||
}
|
||||
}
|
||||
|
||||
asort($images);
|
||||
foreach ($images as $image_file) {
|
||||
echo '<div class="images">';
|
||||
echo '<img src="images/'.$image_file.'" />';
|
||||
$img_url = 'image.php?image='.$image_file.'&output='.$top_form['output']->value.
|
||||
'&colors='.$top_form['ncolors']->value.'&dither='.$top_form['dither']->value.
|
||||
'&match_palette='.$top_form['match_palette']->value.'&demo='.$activeDemo->name;
|
||||
foreach ($activeDemo->fields as $field) {
|
||||
$img_url .= '&'.$field->getURLValue();
|
||||
}
|
||||
|
||||
echo ' ';
|
||||
echo '<a href="'.$img_url.'">';
|
||||
echo '<img src="'.$img_url.'" />';
|
||||
echo '</a>';
|
||||
echo "</div>\n";
|
||||
}
|
||||
?>
|
||||
<div style="clear: both"></div>
|
||||
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_addNoise extends Demo
|
||||
{
|
||||
public $order = 9350;
|
||||
/**
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new SelectField('type', ['salt&pepper', 'mono', 'color'], 'mono'));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->addNoise($this->fields['amount']->value, $this->fields['type']->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,44 @@
|
||||
<?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'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_applyConvolution extends Demo
|
||||
{
|
||||
public $order = 2025;
|
||||
|
||||
protected $base_matrix = [[2, 0, 0], [0, -1, 0], [0, 0, -1]];
|
||||
|
||||
public 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));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$mstr = $this->fval('matrix');
|
||||
$rows = explode(',', $mstr);
|
||||
|
||||
$matrix = [];
|
||||
foreach ($this->base_matrix as $idx => $base_row) {
|
||||
$build_row = [];
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_applyFilter extends Demo
|
||||
{
|
||||
public $order = 2000;
|
||||
/**
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new SelectField('filter', [
|
||||
'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));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +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';
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_applyMask extends Demo
|
||||
{
|
||||
public $order = 600;
|
||||
|
||||
public 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');
|
||||
}
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
|
||||
public function getFormat()
|
||||
{
|
||||
return 'png';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_asGrayscale extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->asGrayscale();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_asGrayscale extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
return $img->asGrayscale();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_asNegative extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->asNegative();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_asNegative extends Demo
|
||||
{
|
||||
public $order = 300;
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
return $img->asNegative();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_autoCrop extends Demo
|
||||
{
|
||||
public $order = 1050;
|
||||
|
||||
public 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'));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<?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'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_correctGamma extends Demo
|
||||
{
|
||||
public $order = 2050;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new FloatField('in_gamma', 1.1));
|
||||
$this->addField(new FloatField('out_gamma', 3.7));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->correctGamma($this->fval('in_gamma'), $this->fval('out_gamma'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_crop extends Demo
|
||||
{
|
||||
public $order = 1000;
|
||||
|
||||
public 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));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_flip extends Demo
|
||||
{
|
||||
public $order = 1200;
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->flip();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_flip extends Demo
|
||||
{
|
||||
public $order = 1200;
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->flip();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,53 @@
|
||||
<?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:
|
||||
/**
|
||||
*/
|
||||
class Demo_getCanvas extends Demo
|
||||
{
|
||||
public $order = 1300;
|
||||
|
||||
public 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', ['show' => false, 'pattern' => '/(.*)\.ttf$/', 'default' => 'VeraSe.ttf']));
|
||||
$this->addField(new IntField('size', 18));
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
public function et($name)
|
||||
{
|
||||
return htmlentities($this->fval($name));
|
||||
}
|
||||
|
||||
public 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));
|
||||
@@ -59,5 +58,5 @@
|
||||
\$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>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_getChannels extends Demo
|
||||
{
|
||||
public $order = 500;
|
||||
|
||||
protected $channels = ['red', 'green', 'blue', 'alpha'];
|
||||
|
||||
public 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));
|
||||
}
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
$on = [];
|
||||
foreach ($this->channels as $name) {
|
||||
if ($this->fields[$name]->value) {
|
||||
$on[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $img->getChannels($on);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_getMask extends Demo
|
||||
{
|
||||
public $order = 550;
|
||||
|
||||
function execute($img, $request)
|
||||
{
|
||||
return $img->getMask();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_getMask extends Demo
|
||||
{
|
||||
public $order = 550;
|
||||
|
||||
public function execute($img, $request)
|
||||
{
|
||||
return $img->getMask();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
<?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.";
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_merge extends Demo
|
||||
{
|
||||
public $order = 800;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new FileSelectField('overlay', 'images', ['default' => '6-logo.gif']));
|
||||
$this->addField(new CoordinateField('left', 'right-10'));
|
||||
$this->addField(new CoordinateField('top', 'bottom-15%'));
|
||||
$this->addField(new IntField('opacity', 50));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
echo "For alpha images, set opacity=100, otherwise alpha channel won't work.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_mirror extends Demo
|
||||
{
|
||||
public $order = 1150;
|
||||
|
||||
function execute($image, $request)
|
||||
{
|
||||
return $image->mirror();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_mirror extends Demo
|
||||
{
|
||||
public $order = 1150;
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->mirror();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_resize extends Demo
|
||||
{
|
||||
public $order = 900;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new CoordinateField('width', 120));
|
||||
$this->addField(new CoordinateField('height', null));
|
||||
$this->addField(new SelectField('fit', ['inside', 'fill', 'outside']));
|
||||
$this->addField(new SelectField('scale', ['any', 'down', 'up']));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_resizeCanvas extends Demo
|
||||
{
|
||||
public $order = 910;
|
||||
|
||||
public 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', ['any', 'down', 'up'], 'any'));
|
||||
$this->addField(new CheckboxField('merge', false, 'Merge or copy over'));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_rotate extends Demo
|
||||
{
|
||||
public $order = 1100;
|
||||
/**
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new AngleField('angle', 25));
|
||||
$this->addField(new ColorField('color', ''));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
$angle = $this->fields['angle']->value;
|
||||
$color = $this->fields['color']->value;
|
||||
|
||||
return $image->rotate($angle, $color ? hexdec($color) : null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Demo_roundCorners extends Demo
|
||||
{
|
||||
public $order = 1075;
|
||||
|
||||
public 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));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo_unsharp extends Demo
|
||||
{
|
||||
public $order = 1350;
|
||||
/**
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
public function init()
|
||||
{
|
||||
$this->addField(new IntField('amount', 300));
|
||||
$this->addField(new IntField('radius', 3));
|
||||
$this->addField(new IntField('threshold', 2));
|
||||
}
|
||||
|
||||
public function execute($image, $request)
|
||||
{
|
||||
return $image->unsharp($this->fields['amount']->value, $this->fields['radius']->value, $this->fields['threshold']->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
include('../lib/WideImage.php');
|
||||
|
||||
include '../lib/WideImage.php';
|
||||
|
||||
$img = WideImage::createTrueColorImage(400, 200);
|
||||
$canvas = $img->getCanvas();
|
||||
@@ -31,40 +32,39 @@ $text = '#j';
|
||||
// First we create our bounding box
|
||||
$bbox = imageftbbox($font_size, $angle, $font, $text);
|
||||
|
||||
|
||||
function normalize_bbox($bbox)
|
||||
{
|
||||
return array(
|
||||
'up-left' => array('x' => $bbox[6], 'y' => $bbox[7]),
|
||||
'up-right' => array('x' => $bbox[4], 'y' => $bbox[5]),
|
||||
'down-left' => array('x' => $bbox[0], 'y' => $bbox[1]),
|
||||
'down-right' => array('x' => $bbox[2], 'y' => $bbox[3]),
|
||||
);
|
||||
return [
|
||||
'up-left' => ['x' => $bbox[6], 'y' => $bbox[7]],
|
||||
'up-right' => ['x' => $bbox[4], 'y' => $bbox[5]],
|
||||
'down-left' => ['x' => $bbox[0], 'y' => $bbox[1]],
|
||||
'down-right' => ['x' => $bbox[2], 'y' => $bbox[3]],
|
||||
];
|
||||
}
|
||||
|
||||
function outer_box($box)
|
||||
{
|
||||
return array(
|
||||
'left' => min($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'top' => min($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y']),
|
||||
'right' => max($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'bottom' => max($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y'])
|
||||
);
|
||||
return [
|
||||
'left' => min($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'top' => min($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y']),
|
||||
'right' => max($box['up-left']['x'], $box['up-right']['x'], $box['down-left']['x'], $box['down-right']['x']),
|
||||
'bottom' => max($box['up-left']['y'], $box['up-right']['y'], $box['down-left']['y'], $box['down-right']['y']),
|
||||
];
|
||||
}
|
||||
|
||||
$box = normalize_bbox($bbox);
|
||||
|
||||
// This is our cordinates for X and Y
|
||||
#$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
|
||||
#$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
|
||||
#$x = 300;
|
||||
#$y = 175;
|
||||
//$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
|
||||
//$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
|
||||
//$x = 300;
|
||||
//$y = 175;
|
||||
|
||||
$obox = outer_box(normalize_bbox(imageftbbox($font_size, $angle, $font, '')));
|
||||
$obox = outer_box(normalize_bbox(imageftbbox($font_size, $angle, $font, $text)));
|
||||
|
||||
#$x = imagesx($im) - $obox['right'] - 1;
|
||||
#$y = imagesy($im) - $obox['bottom'] - 1;
|
||||
//$x = imagesx($im) - $obox['right'] - 1;
|
||||
//$y = imagesy($im) - $obox['bottom'] - 1;
|
||||
$x = 0;
|
||||
$y = 0;
|
||||
|
||||
@@ -72,9 +72,8 @@ $gc = imagecolorallocate($im, 255, 200, 200);
|
||||
imageline($im, imagesx($im) / 2, 0, imagesx($im) / 2, imagesy($im), $gc);
|
||||
imageline($im, 0, imagesy($im) / 2, imagesx($im), imagesy($im) / 2, $gc);
|
||||
|
||||
|
||||
imagefttext($im, $font_size, $angle, $x, $y, $black, $font, $text);
|
||||
#imagefttext($im, $font_size, $angle, $x, $y, $black, $font, 'aj');
|
||||
//imagefttext($im, $font_size, $angle, $x, $y, $black, $font, 'aj');
|
||||
|
||||
$c = imagecolorallocate($im, 0, 255, 0);
|
||||
imageline($im, $box['up-left']['x'] + $x, $box['up-left']['y'] + $y, $box['up-right']['x'] + $x, $box['up-right']['y'] + $y, $c);
|
||||
@@ -91,7 +90,6 @@ imageline($im, $obox['left'] + $x, $obox['bottom'] + $y, $obox['left'] + $x, $ob
|
||||
|
||||
imagefilledellipse($im, $x, $y, 3, 3, imagecolorallocate($im, 255, 0, 0));
|
||||
|
||||
|
||||
// Output to browser
|
||||
header('Content-type: image/png');
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class AngleField extends IntField
|
||||
{
|
||||
function __construct($name, $default, $hint = 'In degrees clockwise, negative values accepted')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class AngleField extends IntField
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'In degrees clockwise, negative values accepted')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CheckboxField extends Field
|
||||
{
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default ? '1' : null) === '1';
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
if ($this->value)
|
||||
$chk = 'checked="checked"';
|
||||
else
|
||||
$chk = '';
|
||||
|
||||
echo '<input type="hidden" name="' . $name . '" id="' . $id . '_val" value="' . ($this->value ? '1' : '') . '" />';
|
||||
echo '<input type="checkbox" ' . $chk . ' name="' . $name . '_cb" id="' . $id . '" value="1" onclick="document.getElementById(\'' . $id . '_val\').value = Number(this.checked);" />';
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class CheckboxField extends Field
|
||||
{
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default ? '1' : null) === '1';
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
if ($this->value) {
|
||||
$chk = 'checked="checked"';
|
||||
} else {
|
||||
$chk = '';
|
||||
}
|
||||
|
||||
echo '<input type="hidden" name="'.$name.'" id="'.$id.'_val" value="'.($this->value ? '1' : '').'" />';
|
||||
echo '<input type="checkbox" '.$chk.' name="'.$name.'_cb" id="'.$id.'" value="1" onclick="document.getElementById(\''.$id.'_val\').value = Number(this.checked);" />';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CheckboxSetField extends Field
|
||||
{
|
||||
public $options;
|
||||
public $request;
|
||||
|
||||
function __construct($name, $options)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = array();
|
||||
if (is_array($request->get($this->name)))
|
||||
foreach ($request->get($this->name) as $val)
|
||||
if (in_array($val, $this->options))
|
||||
$this->value[] = $val;
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
$request = $this->request;
|
||||
foreach ($this->options as $option)
|
||||
{
|
||||
if (is_array($request->get($this->name)) && in_array($option, $request->get($this->name)))
|
||||
$chk = 'checked="checked"';
|
||||
else
|
||||
$chk = '';
|
||||
/**
|
||||
*/
|
||||
class CheckboxSetField extends Field
|
||||
{
|
||||
public $options;
|
||||
public $request;
|
||||
|
||||
$name = $this->name . '[]';
|
||||
$id = $this->name . '_' . $option;
|
||||
echo '<input type="checkbox" ' . $chk . ' name="' . $name . '" id="' . $id . '" value="' . $option . '" />';
|
||||
echo '<label for="' . $id . '">' . $option . '</label> ';
|
||||
}
|
||||
}
|
||||
|
||||
function getURLValue()
|
||||
{
|
||||
$v = '';
|
||||
foreach ($this->value as $value)
|
||||
$v .= $this->name . '[]=' . $value . '&';
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct($name, $options)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = [];
|
||||
if (is_array($request->get($this->name))) {
|
||||
foreach ($request->get($this->name) as $val) {
|
||||
if (in_array($val, $this->options)) {
|
||||
$this->value[] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$request = $this->request;
|
||||
foreach ($this->options as $option) {
|
||||
if (is_array($request->get($this->name)) && in_array($option, $request->get($this->name))) {
|
||||
$chk = 'checked="checked"';
|
||||
} else {
|
||||
$chk = '';
|
||||
}
|
||||
|
||||
$name = $this->name.'[]';
|
||||
$id = $this->name.'_'.$option;
|
||||
echo '<input type="checkbox" '.$chk.' name="'.$name.'" id="'.$id.'" value="'.$option.'" />';
|
||||
echo '<label for="'.$id.'">'.$option.'</label> ';
|
||||
}
|
||||
}
|
||||
|
||||
public function getURLValue()
|
||||
{
|
||||
$v = '';
|
||||
foreach ($this->value as $value) {
|
||||
$v .= $this->name.'[]='.$value.'&';
|
||||
}
|
||||
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class ColorField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'RRGGBB hex, leave blank for transparent background')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$c = $request->getColor($this->name, $this->default);
|
||||
if ($c === '')
|
||||
$this->value = null;
|
||||
else
|
||||
$this->value = str_pad(dechex(hexdec($c)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class ColorField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'RRGGBB hex, leave blank for transparent background')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$c = $request->getColor($this->name, $this->default);
|
||||
if ($c === '') {
|
||||
$this->value = null;
|
||||
} else {
|
||||
$this->value = str_pad(dechex(hexdec($c)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class CoordinateField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Smart coordinate')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getCoordinate($this->name, $this->default);
|
||||
if ($this->value > 1000)
|
||||
$this->value = 1000;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class CoordinateField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'Smart coordinate')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->getCoordinate($this->name, $this->default);
|
||||
if ($this->value > 1000) {
|
||||
$this->value = 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Demo
|
||||
{
|
||||
public $name;
|
||||
public $format = null;
|
||||
public $fields = array();
|
||||
public $order = 1000;
|
||||
|
||||
function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
}
|
||||
|
||||
static function create($name)
|
||||
{
|
||||
$file = DEMO_PATH . '/demos/' . $name . '.php';
|
||||
if (!file_exists($file))
|
||||
throw new Exception("Invalid demo: {$name}");
|
||||
include $file;
|
||||
$className = 'Demo_' . $name;
|
||||
$demo = new $className($name);
|
||||
$demo->request = Request::getInstance();
|
||||
$demo->init();
|
||||
foreach ($demo->fields as $field)
|
||||
{
|
||||
$field->request = Request::getInstance();
|
||||
$field->init(Request::getInstance());
|
||||
}
|
||||
return $demo;
|
||||
}
|
||||
|
||||
function getFormat()
|
||||
{
|
||||
return 'as input';
|
||||
}
|
||||
|
||||
function addField($field)
|
||||
{
|
||||
$this->fields[$field->name] = $field;
|
||||
}
|
||||
|
||||
function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function text()
|
||||
{
|
||||
}
|
||||
|
||||
function fval($name)
|
||||
{
|
||||
return $this->fields[$name]->value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class Demo
|
||||
{
|
||||
public $name;
|
||||
public $format = null;
|
||||
public $fields = [];
|
||||
public $order = 1000;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public static function create($name)
|
||||
{
|
||||
$file = DEMO_PATH.'/demos/'.$name.'.php';
|
||||
if (!file_exists($file)) {
|
||||
throw new Exception("Invalid demo: {$name}");
|
||||
}
|
||||
include $file;
|
||||
$className = 'Demo_'.$name;
|
||||
$demo = new $className($name);
|
||||
$demo->request = Request::getInstance();
|
||||
$demo->init();
|
||||
foreach ($demo->fields as $field) {
|
||||
$field->request = Request::getInstance();
|
||||
$field->init(Request::getInstance());
|
||||
}
|
||||
|
||||
return $demo;
|
||||
}
|
||||
|
||||
public function getFormat()
|
||||
{
|
||||
return 'as input';
|
||||
}
|
||||
|
||||
public function addField($field)
|
||||
{
|
||||
$this->fields[$field->name] = $field;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
}
|
||||
|
||||
public function fval($name)
|
||||
{
|
||||
return $this->fields[$name]->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Field
|
||||
{
|
||||
public $name;
|
||||
public $default;
|
||||
public $value;
|
||||
public $request;
|
||||
public $hint;
|
||||
|
||||
function __construct($name, $default = null, $hint = '')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->default = $default;
|
||||
|
||||
if ($hint == '')
|
||||
$hint = $name;
|
||||
|
||||
$this->hint = $hint;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default);
|
||||
}
|
||||
|
||||
function render()
|
||||
{
|
||||
$id = htmlentities($this->name);
|
||||
echo '<label style="background-color: #c0c0c0; padding: 5px; margin: 2px;" for="imgparam_' . $id . '" title="' . htmlentities($this->hint) . '">';
|
||||
echo $this->name . ': ';
|
||||
$this->renderBody($id, 'imgparam_' . $id);
|
||||
echo '</label> ';
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
echo '<input id="' . $id . '" type="text" size="15" name="' . $name . '" value="' . $this->getRenderValue() . '" />';
|
||||
}
|
||||
|
||||
function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function getUrlValue()
|
||||
{
|
||||
return urlencode($this->name) . '=' . urlencode($this->value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class Field
|
||||
{
|
||||
public $name;
|
||||
public $default;
|
||||
public $value;
|
||||
public $request;
|
||||
public $hint;
|
||||
|
||||
public function __construct($name, $default = null, $hint = '')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->default = $default;
|
||||
|
||||
if ($hint == '') {
|
||||
$hint = $name;
|
||||
}
|
||||
|
||||
$this->hint = $hint;
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->get($this->name, $this->default);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$id = htmlentities($this->name);
|
||||
echo '<label style="background-color: #c0c0c0; padding: 5px; margin: 2px;" for="imgparam_'.$id.'" title="'.htmlentities($this->hint).'">';
|
||||
echo $this->name.': ';
|
||||
$this->renderBody($id, 'imgparam_'.$id);
|
||||
echo '</label> ';
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
echo '<input id="'.$id.'" type="text" size="15" name="'.$name.'" value="'.$this->getRenderValue().'" />';
|
||||
}
|
||||
|
||||
public function getRenderValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getUrlValue()
|
||||
{
|
||||
return urlencode($this->name).'='.urlencode($this->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FileSelectField extends Field
|
||||
{
|
||||
public $request;
|
||||
public $files = array();
|
||||
public $options;
|
||||
|
||||
function __construct($name, $path, $options = array())
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->path = $path;
|
||||
$this->options = $options;
|
||||
|
||||
if (!isset($options['show']))
|
||||
$this->options['show'] = true;
|
||||
|
||||
if (!isset($options['pattern']))
|
||||
$this->options['pattern'] = '/(.*)/';
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = null;
|
||||
$di = new DirectoryIterator(DEMO_PATH . $this->path);
|
||||
foreach ($di as $file)
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0 && preg_match($this->options['pattern'], $file->getFilename()))
|
||||
{
|
||||
$this->files[] = $file->getFilename();
|
||||
if ($this->value === null && isset($this->options['default']) && $this->options['default'] == $file->getFilename())
|
||||
$this->value = $this->options['default'];
|
||||
|
||||
if ($this->request->get($this->name) == $file->getFilename())
|
||||
$this->value = $file->getFilename();
|
||||
}
|
||||
|
||||
sort($this->files);
|
||||
|
||||
if (!$this->value && count($this->files) > 0)
|
||||
$this->value = $this->files[0];
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
if ($this->options['show'])
|
||||
{
|
||||
$onch = "document.getElementById('sel_{$id}').src = '{$this->path}/' + this.options[this.selectedIndex].value;";
|
||||
}
|
||||
else
|
||||
$onch = '';
|
||||
|
||||
echo '<select id="' . $id . '" name="' . $name . '" onchange="' . $onch . '">';
|
||||
$selected_file = null;
|
||||
foreach ($this->files as $file)
|
||||
{
|
||||
if ($this->value == $file)
|
||||
{
|
||||
$sel = 'selected="selected"';
|
||||
$selected_file = $file;
|
||||
}
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
echo '<option ' . $sel . ' value="' . $file . '">' . $file . '</option>' . PHP_EOL;
|
||||
}
|
||||
echo '</select>';
|
||||
|
||||
if ($this->options['show'] && $selected_file)
|
||||
{
|
||||
echo '<div style="display: inline; min-width: 50px; min-height: 50px">';
|
||||
echo '<img style="position: absolute" id="sel_' . $id . '" width="50" src="' . $this->path . '/' . $selected_file . '" /> ';
|
||||
echo " ";
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function getURLValue()
|
||||
{
|
||||
return $this->name . '=' . $this->value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class FileSelectField extends Field
|
||||
{
|
||||
public $request;
|
||||
public $files = [];
|
||||
public $options;
|
||||
|
||||
public function __construct($name, $path, $options = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->path = $path;
|
||||
$this->options = $options;
|
||||
|
||||
if (!isset($options['show'])) {
|
||||
$this->options['show'] = true;
|
||||
}
|
||||
|
||||
if (!isset($options['pattern'])) {
|
||||
$this->options['pattern'] = '/(.*)/';
|
||||
}
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = null;
|
||||
$di = new DirectoryIterator(DEMO_PATH.$this->path);
|
||||
foreach ($di as $file) {
|
||||
if (!$file->isDot() && strpos($file->getFilename(), '.') !== 0 && preg_match($this->options['pattern'], $file->getFilename())) {
|
||||
$this->files[] = $file->getFilename();
|
||||
if ($this->value === null && isset($this->options['default']) && $this->options['default'] == $file->getFilename()) {
|
||||
$this->value = $this->options['default'];
|
||||
}
|
||||
|
||||
if ($this->request->get($this->name) == $file->getFilename()) {
|
||||
$this->value = $file->getFilename();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort($this->files);
|
||||
|
||||
if (!$this->value && count($this->files) > 0) {
|
||||
$this->value = $this->files[0];
|
||||
}
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
if ($this->options['show']) {
|
||||
$onch = "document.getElementById('sel_{$id}').src = '{$this->path}/' + this.options[this.selectedIndex].value;";
|
||||
} else {
|
||||
$onch = '';
|
||||
}
|
||||
|
||||
echo '<select id="'.$id.'" name="'.$name.'" onchange="'.$onch.'">';
|
||||
$selected_file = null;
|
||||
foreach ($this->files as $file) {
|
||||
if ($this->value == $file) {
|
||||
$sel = 'selected="selected"';
|
||||
$selected_file = $file;
|
||||
} else {
|
||||
$sel = '';
|
||||
}
|
||||
|
||||
echo '<option '.$sel.' value="'.$file.'">'.$file.'</option>'.PHP_EOL;
|
||||
}
|
||||
echo '</select>';
|
||||
|
||||
if ($this->options['show'] && $selected_file) {
|
||||
echo '<div style="display: inline; min-width: 50px; min-height: 50px">';
|
||||
echo '<img style="position: absolute" id="sel_'.$id.'" width="50" src="'.$this->path.'/'.$selected_file.'" /> ';
|
||||
echo ' ';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function getURLValue()
|
||||
{
|
||||
return $this->name.'='.$this->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FloatField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Float')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getFloat($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class FloatField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'Float')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->getFloat($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class FormatSelectField extends SelectField
|
||||
{
|
||||
function __construct($name)
|
||||
{
|
||||
parent::__construct($name, array('preset for demo', 'as input', 'png8', 'png24', 'jpeg', 'gif', 'bmp'), null, 'Image format');
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class FormatSelectField extends SelectField
|
||||
{
|
||||
public function __construct($name)
|
||||
{
|
||||
parent::__construct($name, ['preset for demo', 'as input', 'png8', 'png24', 'jpeg', 'gif', 'bmp'], null, 'Image format');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class IntField extends Field
|
||||
{
|
||||
function __construct($name, $default, $hint = 'Integer')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $request->getInt($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class IntField extends Field
|
||||
{
|
||||
public function __construct($name, $default, $hint = 'Integer')
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $request->getInt($this->name, $this->default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,135 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
protected $vars = array();
|
||||
|
||||
protected static $instance;
|
||||
static function getInstance()
|
||||
{
|
||||
if (self::$instance === null)
|
||||
self::$instance = new Request;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->vars = $_GET;
|
||||
|
||||
/*
|
||||
// have to rely on parsing QUERY_STRING, thanks to PHP
|
||||
// http://bugs.php.net/bug.php?id=39078
|
||||
// http://bugs.php.net/bug.php?id=45149
|
||||
$all_vars = explode('&', $_SERVER['QUERY_STRING']);
|
||||
foreach ($all_vars as $keyval)
|
||||
{
|
||||
if (strlen($keyval) == 0)
|
||||
continue;
|
||||
|
||||
if (strpos($keyval, '=') === false)
|
||||
{
|
||||
$key = $keyval;
|
||||
$value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list($key, $value) = explode('=', $keyval);
|
||||
#$value = str_replace('%2B', '[[PLUS]]', $value);
|
||||
$value = urldecode($value);
|
||||
#$value = str_replace('[[PLUS]]', '+', $value);
|
||||
}
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->vars[$key]))
|
||||
return $this->vars[$key];
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
|
||||
function getInt($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0)
|
||||
return intval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getFloat($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0)
|
||||
return floatval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getCoordinate($key, $default = 0)
|
||||
{
|
||||
$v = self::get($key);
|
||||
if (strlen($v) > 0 && WideImage_Coordinate::parse($v) !== null)
|
||||
return self::get($key);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getOption($key, $valid = array(), $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && in_array($value, $valid))
|
||||
return strval($value);
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getColor($key, $default = '000000')
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (substr($value, 0, 1) == '#')
|
||||
$value = substr($value, 1);
|
||||
|
||||
if ($value === '' || preg_match('~^[0-9a-f]{1,6}$~i', $value))
|
||||
return $value;
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
|
||||
function getRegex($key, $regex, $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && preg_match($regex, $value))
|
||||
return $value;
|
||||
else
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
/**
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**/
|
||||
|
||||
/**
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
protected $vars = [];
|
||||
|
||||
protected static $instance;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->vars = $_GET;
|
||||
|
||||
/*
|
||||
// have to rely on parsing QUERY_STRING, thanks to PHP
|
||||
// http://bugs.php.net/bug.php?id=39078
|
||||
// http://bugs.php.net/bug.php?id=45149
|
||||
$all_vars = explode('&', $_SERVER['QUERY_STRING']);
|
||||
foreach ($all_vars as $keyval)
|
||||
{
|
||||
if (strlen($keyval) == 0)
|
||||
continue;
|
||||
|
||||
if (strpos($keyval, '=') === false)
|
||||
{
|
||||
$key = $keyval;
|
||||
$value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
list($key, $value) = explode('=', $keyval);
|
||||
#$value = str_replace('%2B', '[[PLUS]]', $value);
|
||||
$value = urldecode($value);
|
||||
#$value = str_replace('[[PLUS]]', '+', $value);
|
||||
}
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (isset($this->vars[$key])) {
|
||||
return $this->vars[$key];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->vars[$key] = $value;
|
||||
}
|
||||
|
||||
public function getInt($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0) {
|
||||
return intval($value);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFloat($key, $default = 0)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (strlen($value) > 0) {
|
||||
return floatval($value);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getCoordinate($key, $default = 0)
|
||||
{
|
||||
$v = self::get($key);
|
||||
if (strlen($v) > 0 && WideImage_Coordinate::parse($v) !== null) {
|
||||
return self::get($key);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOption($key, $valid = [], $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && in_array($value, $valid)) {
|
||||
return strval($value);
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getColor($key, $default = '000000')
|
||||
{
|
||||
$value = self::get($key);
|
||||
if (substr($value, 0, 1) == '#') {
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
|
||||
if ($value === '' || preg_match('~^[0-9a-f]{1,6}$~i', $value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRegex($key, $regex, $default = null)
|
||||
{
|
||||
$value = self::get($key);
|
||||
if ($value !== null && preg_match($regex, $value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
class SelectField extends Field
|
||||
{
|
||||
public $options;
|
||||
|
||||
function __construct($name, $options, $default = null, $hint = null)
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
if ($default === null)
|
||||
$this->default = $options[0];
|
||||
else
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
function init($request)
|
||||
{
|
||||
$this->value = $this->default;
|
||||
$v = str_replace('+', ' ', $request->get($this->name));
|
||||
if (in_array($v, $this->options))
|
||||
$this->value = $v;
|
||||
}
|
||||
|
||||
function renderBody($name, $id)
|
||||
{
|
||||
echo '<select id="' . $id . '" name="' . $name . '">';
|
||||
foreach ($this->options as $option)
|
||||
{
|
||||
if ($this->value == $option)
|
||||
$sel = 'selected="selected"';
|
||||
else
|
||||
$sel = '';
|
||||
|
||||
echo '<option ' . $sel . ' value="' . $option . '">' . $option . '</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
class SelectField extends Field
|
||||
{
|
||||
public $options;
|
||||
|
||||
public function __construct($name, $options, $default = null, $hint = null)
|
||||
{
|
||||
parent::__construct($name, $default, $hint);
|
||||
$this->name = $name;
|
||||
$this->options = $options;
|
||||
if ($default === null) {
|
||||
$this->default = $options[0];
|
||||
} else {
|
||||
$this->default = $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function init($request)
|
||||
{
|
||||
$this->value = $this->default;
|
||||
$v = str_replace('+', ' ', $request->get($this->name));
|
||||
if (in_array($v, $this->options)) {
|
||||
$this->value = $v;
|
||||
}
|
||||
}
|
||||
|
||||
public function renderBody($name, $id)
|
||||
{
|
||||
echo '<select id="'.$id.'" name="'.$name.'">';
|
||||
foreach ($this->options as $option) {
|
||||
if ($this->value == $option) {
|
||||
$sel = 'selected="selected"';
|
||||
} else {
|
||||
$sel = '';
|
||||
}
|
||||
|
||||
echo '<option '.$sel.' value="'.$option.'">'.$option.'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
define('DEMO_PATH', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR);
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
require_once DEMO_PATH . 'helpers/Request.php';
|
||||
require_once DEMO_PATH . 'helpers/Demo.php';
|
||||
require_once DEMO_PATH . 'helpers/Field.php';
|
||||
require_once DEMO_PATH . 'helpers/CheckboxField.php';
|
||||
require_once DEMO_PATH . 'helpers/FileSelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/CoordinateField.php';
|
||||
require_once DEMO_PATH . 'helpers/IntField.php';
|
||||
require_once DEMO_PATH . 'helpers/FloatField.php';
|
||||
require_once DEMO_PATH . 'helpers/AngleField.php';
|
||||
require_once DEMO_PATH . 'helpers/SelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/FormatSelectField.php';
|
||||
require_once DEMO_PATH . 'helpers/ColorField.php';
|
||||
/**
|
||||
*/
|
||||
define('DEMO_PATH', realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..').DIRECTORY_SEPARATOR);
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
require_once DEMO_PATH.'helpers/Request.php';
|
||||
require_once DEMO_PATH.'helpers/Demo.php';
|
||||
require_once DEMO_PATH.'helpers/Field.php';
|
||||
require_once DEMO_PATH.'helpers/CheckboxField.php';
|
||||
require_once DEMO_PATH.'helpers/FileSelectField.php';
|
||||
require_once DEMO_PATH.'helpers/CoordinateField.php';
|
||||
require_once DEMO_PATH.'helpers/IntField.php';
|
||||
require_once DEMO_PATH.'helpers/FloatField.php';
|
||||
require_once DEMO_PATH.'helpers/AngleField.php';
|
||||
require_once DEMO_PATH.'helpers/SelectField.php';
|
||||
require_once DEMO_PATH.'helpers/FormatSelectField.php';
|
||||
require_once DEMO_PATH.'helpers/ColorField.php';
|
||||
|
||||
@@ -1,52 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Demos
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/helpers/common.php';
|
||||
require_once dirname(__FILE__) . '/../lib/WideImage.php';
|
||||
|
||||
$request = Request::getInstance();
|
||||
$demo = Demo::create($request->get('demo'));
|
||||
$image = WideImage::load('images/' . $request->get('image'));
|
||||
|
||||
$result = $demo->execute($image, $request);
|
||||
|
||||
$output = new FormatSelectField('output');
|
||||
$output->init(Request::getInstance());
|
||||
|
||||
if ($output->value == 'preset for demo')
|
||||
$format = $demo->getFormat();
|
||||
else
|
||||
$format = $output->value;
|
||||
|
||||
if ($format === 'as input')
|
||||
$format = substr($request->get('image'), -3);
|
||||
|
||||
$output = 24;
|
||||
if ($format == 'png8')
|
||||
{
|
||||
$output = 8;
|
||||
$format = 'png';
|
||||
}
|
||||
elseif ($format == 'png24')
|
||||
$format = 'png';
|
||||
elseif ($format == 'gif')
|
||||
$output = 8;
|
||||
|
||||
if ($output == 8)
|
||||
{
|
||||
$ncolors = new IntField('colors', 255);
|
||||
$ncolors->init(Request::getInstance());
|
||||
|
||||
$dither = new CheckboxField('dither', true);
|
||||
$dither->init(Request::getInstance());
|
||||
|
||||
$match_palette = new CheckboxField('match_palette', true);
|
||||
$match_palette->init(Request::getInstance());
|
||||
|
||||
$result = $result->asPalette($ncolors->value, $dither->value, $match_palette->value);
|
||||
}
|
||||
|
||||
$result->output($format);
|
||||
|
||||
/**
|
||||
*/
|
||||
require_once dirname(__FILE__).'/helpers/common.php';
|
||||
require_once dirname(__FILE__).'/../lib/WideImage.php';
|
||||
|
||||
$request = Request::getInstance();
|
||||
$demo = Demo::create($request->get('demo'));
|
||||
$image = WideImage::load('images/'.$request->get('image'));
|
||||
|
||||
$result = $demo->execute($image, $request);
|
||||
|
||||
$output = new FormatSelectField('output');
|
||||
$output->init(Request::getInstance());
|
||||
|
||||
if ($output->value == 'preset for demo') {
|
||||
$format = $demo->getFormat();
|
||||
} else {
|
||||
$format = $output->value;
|
||||
}
|
||||
|
||||
if ($format === 'as input') {
|
||||
$format = substr($request->get('image'), -3);
|
||||
}
|
||||
|
||||
$output = 24;
|
||||
if ($format == 'png8') {
|
||||
$output = 8;
|
||||
$format = 'png';
|
||||
} elseif ($format == 'png24') {
|
||||
$format = 'png';
|
||||
} elseif ($format == 'gif') {
|
||||
$output = 8;
|
||||
}
|
||||
|
||||
if ($output == 8) {
|
||||
$ncolors = new IntField('colors', 255);
|
||||
$ncolors->init(Request::getInstance());
|
||||
|
||||
$dither = new CheckboxField('dither', true);
|
||||
$dither->init(Request::getInstance());
|
||||
|
||||
$match_palette = new CheckboxField('match_palette', true);
|
||||
$match_palette->init(Request::getInstance());
|
||||
|
||||
$result = $result->asPalette($ncolors->value, $dither->value, $match_palette->value);
|
||||
}
|
||||
|
||||
$result->output($format);
|
||||
|
||||
@@ -1,63 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
This file is part of WideImage.
|
||||
|
||||
WideImage is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
WideImage is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with WideImage; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
* @package Demos
|
||||
**/
|
||||
|
||||
include 'helpers/common.php';
|
||||
require_once '../lib/WideImage.php';
|
||||
|
||||
$demos = array();
|
||||
$di = new DirectoryIterator(dirname(__FILE__) . '/demos/');
|
||||
foreach ($di as $file)
|
||||
if (substr($file->getFilename(), -4) == '.php')
|
||||
$demos[] = Demo::create(substr($file->getFilename(), 0, -4));
|
||||
|
||||
usort($demos, 'cmp_demos');
|
||||
|
||||
function cmp_demos($d1, $d2)
|
||||
{
|
||||
if ($d1->order === $d2->order)
|
||||
return 0;
|
||||
|
||||
return ($d1->order < $d2->order ? -1 : 1);
|
||||
}
|
||||
|
||||
if (isset($_GET['demo']))
|
||||
$activeDemoName = $_GET['demo'];
|
||||
else
|
||||
$activeDemoName = null;
|
||||
|
||||
$activeDemo = null;
|
||||
foreach ($demos as $demo)
|
||||
if ($demo->name == $activeDemoName)
|
||||
{
|
||||
$activeDemo = $demo;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$activeDemo)
|
||||
$activeDemoName = null;
|
||||
|
||||
/**
|
||||
|
||||
**/
|
||||
include 'helpers/common.php';
|
||||
require_once '../lib/WideImage.php';
|
||||
|
||||
$demos = [];
|
||||
$di = new DirectoryIterator(dirname(__FILE__).'/demos/');
|
||||
foreach ($di as $file) {
|
||||
if (substr($file->getFilename(), -4) == '.php') {
|
||||
$demos[] = Demo::create(substr($file->getFilename(), 0, -4));
|
||||
}
|
||||
}
|
||||
|
||||
usort($demos, 'cmp_demos');
|
||||
|
||||
function cmp_demos($d1, $d2)
|
||||
{
|
||||
if ($d1->order === $d2->order) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $d1->order < $d2->order ? -1 : 1;
|
||||
}
|
||||
|
||||
if (isset($_GET['demo'])) {
|
||||
$activeDemoName = $_GET['demo'];
|
||||
} else {
|
||||
$activeDemoName = null;
|
||||
}
|
||||
|
||||
$activeDemo = null;
|
||||
foreach ($demos as $demo) {
|
||||
if ($demo->name == $activeDemoName) {
|
||||
$activeDemo = $demo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$activeDemo) {
|
||||
$activeDemoName = null;
|
||||
}
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>WideImage -<?php if ($activeDemo) echo " " . $activeDemo->name; ?> demo</title>
|
||||
<title>WideImage -<?php if ($activeDemo) {
|
||||
echo ' '.$activeDemo->name;
|
||||
} ?> demo</title>
|
||||
|
||||
<style>
|
||||
body
|
||||
@@ -119,28 +109,28 @@
|
||||
|
||||
<ul>
|
||||
<?php
|
||||
$top_form = array();
|
||||
|
||||
$top_form['output'] = new FormatSelectField('output');
|
||||
$top_form['output']->init(Request::getInstance());
|
||||
|
||||
$top_form['ncolors'] = new IntField('colors', 255);
|
||||
$top_form['ncolors']->init(Request::getInstance());
|
||||
|
||||
$top_form['dither'] = new CheckboxField('dither', true);
|
||||
$top_form['dither']->init(Request::getInstance());
|
||||
$top_form['match_palette'] = new CheckboxField('match_palette', true);
|
||||
$top_form['match_palette']->init(Request::getInstance());
|
||||
|
||||
foreach ($demos as $demo)
|
||||
{
|
||||
if ($activeDemo !== null && $demo->name == $activeDemo->name)
|
||||
$css = 'active_demo';
|
||||
else
|
||||
$css = '';
|
||||
|
||||
echo "<li><a class=\"$css\" href=\"?demo={$demo->name}&output={$top_form['output']->value}&colors={$top_form['ncolors']->value}&dither={$top_form['dither']->value}&match_palette={$top_form['match_palette']->value}\">{$demo->name}</a></li>\n";
|
||||
}
|
||||
$top_form = [];
|
||||
|
||||
$top_form['output'] = new FormatSelectField('output');
|
||||
$top_form['output']->init(Request::getInstance());
|
||||
|
||||
$top_form['ncolors'] = new IntField('colors', 255);
|
||||
$top_form['ncolors']->init(Request::getInstance());
|
||||
|
||||
$top_form['dither'] = new CheckboxField('dither', true);
|
||||
$top_form['dither']->init(Request::getInstance());
|
||||
$top_form['match_palette'] = new CheckboxField('match_palette', true);
|
||||
$top_form['match_palette']->init(Request::getInstance());
|
||||
|
||||
foreach ($demos as $demo) {
|
||||
if ($activeDemo !== null && $demo->name == $activeDemo->name) {
|
||||
$css = 'active_demo';
|
||||
} else {
|
||||
$css = '';
|
||||
}
|
||||
|
||||
echo "<li><a class=\"$css\" href=\"?demo={$demo->name}&output={$top_form['output']->value}&colors={$top_form['ncolors']->value}&dither={$top_form['dither']->value}&match_palette={$top_form['match_palette']->value}\">{$demo->name}</a></li>\n";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
@@ -164,10 +154,9 @@
|
||||
</div>
|
||||
<div style="margin-left: 200px">
|
||||
<?php
|
||||
if ($activeDemo)
|
||||
{
|
||||
include 'demo_screen.php';
|
||||
}
|
||||
if ($activeDemo) {
|
||||
include 'demo_screen.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user