Skip to content

Commit

Permalink
[add] initial svn release (Instant Picture Creator 0.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
haschek committed Nov 22, 2007
1 parent 05f1686 commit 01d8ab9
Show file tree
Hide file tree
Showing 7 changed files with 946 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
please have a look at:
http://eye48.com/dokuwiki/doku.php?id=en:projects:instant-picture-creator
78 changes: 78 additions & 0 deletions filters/Palette.filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

class Palette
{

var $oldWidth = 0;
var $oldHeight = 0;
var $source;

function Palette($source,$parameter)
{
$this->oldWidth = imagesx ($source);
$this->oldHeight = imagesy ($source);
$this->source = $source;

if ($parameter[1] == 'gray')
{
if ($parameter[2] > 1 && $parameter[2] < 257)
{
$this->PaletteGray($parameter[2]);
}
else
{
$this->PaletteGray(64);
}
}
elseif ($parameter[1] == '')
{
$this->error[] = 'empty attribute';
}
else
{
$this->error[] = 'do not know attribute "'.$parameter[1].'"';
}

if ($this->error)
{
$this->dest = false;
}
}

function PaletteGray($colors)
{
$colors = round(256 / ($colors-1));

$this->dest = imagecreate($this->oldWidth,$this->oldHeight);

for ($y = 0; $y <$this->oldHeight; $y++)
for ($x = 0; $x <$this->oldWidth; $x++) {
$rgb = imagecolorat($this->source, $x, $y);
$red = ($rgb >> 16) & 0xFF;
$green = ($rgb >> 8) & 0xFF;
$blue = $rgb & 0xFF;

$gray = round((.299*$red + .587*$green + .114*$blue) / $colors) * $colors;
if ($gray > 255) $gray = 255;

// shift gray level to the left
$grayR = $gray << 16; // R: red
$grayG = $gray << 8; // G: green
$grayB = $gray; // B: blue

// OR operation to compute gray value
$grayColor = $grayR | $grayG | $grayB;

// set the pixel color
imagesetpixel ($this->source, $x, $y, $grayColor);
imagecolorallocate ($this->source, $grayR, $grayG, $grayB);
}


if (!imagecopyresampled($this->dest, $this->source, 0, 0, 0, 0, $this->oldWidth, $this->oldHeight, $this->oldWidth, $this->oldHeight))
$this->dest = false;
}

}

?>
154 changes: 154 additions & 0 deletions filters/Resize.filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

class Resize extends InstantFilter
{

// Security values are in pixel
// value -1 means to skip the check
var $security = array(
"max-width"=>-1,
"min-width"=>-1,
"max-height"=>-1,
"min-height"=>-1,
"max-dim"=>-1, // maximum of dimension (x*y)
"min-dim"=>-1 // minimum of dimension (x*y)
);

function Resize($source, $parameter = null)
{

$oldWidth = imagesx ($source);
$oldHeight = imagesy ($source);
$startX = 0;
$startY = 0;

if ($parameter[1] == 'square')
{
if ($oldWidth != $oldHeight)
{
if ($oldWidth > $oldHeight)
{
$temp = $oldWidth - $oldHeight;
$startX = $startX + intval($temp/2);
$oldWidth = $oldWidth - $temp;
}
else
{
$temp = $oldHeight - $oldWidth;
$startY = $startY + intval($temp/2);
$oldHeight = $oldHeight - $temp;
}
}

$newWidth = $parameter[2];
$newHeight = $parameter[2];

// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == 'exact')
{
$newWidth = $parameter[2];
$newHeight = $parameter[3];

// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == 'min')
{
if ($oldWidth < $oldHeight)
{
$newWidth = $parameter[2];
$newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
}
else
{
$newHeight = $parameter[2];
$newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
}
// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == 'max')
{
if ($oldWidth > $oldHeight)
{
$newWidth = $parameter[2];
$newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
}
else
{
$newHeight = $parameter[2];
$newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
}
// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == 'width')
{
$newWidth = $parameter[2];
$newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == 'height')
{
$newHeight = $parameter[2];
$newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == 'dim')
{
$f = sqrt(($oldHeight*$oldWidth)/$parameter[2]);
$newHeight = intval($oldHeight/$f);
$newWidth = intval($oldWidth/$f);;
// security check of dimensions
$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
}
elseif ($parameter[1] == '')
{
$this->pushError('no attributes');
}
else
{
$this->pushError('wrong attribute '.$parameter[1]);
}

if (count($this->error) == 0)
{
$this->dest = imagecreatetruecolor($newWidth, $newHeight);
if (!imagecopyresampled($this->dest, $source, 0, 0, $startX, $startY, $newWidth, $newHeight, $oldWidth, $oldHeight))
{
$this->dest = false;
$this->pushError('cannot apply filter');
}
}
else
{
$this->dest = false;
}
}

function checkSecurity($value, $min, $max)
{
if ($min > 0 && $value < $min) $this->pushError('security issue, dimension fault ('.$value.' < '.$min.')');
if ($max > 0 && $value > $max) $this->pushError('security issue, dimension fault ('.$value.' > '.$max.')');
}
}

?>
38 changes: 38 additions & 0 deletions instantpicture.conf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

# Security Configuration --- Begin

$nofiltername = 'nofilter'; // filter dummy name for unfiltered image
$nofilter = true; // is the filter dummy for unfiltered image allowed as filter in url

// array for all allowed filters, it's recommended to use that for security issues
// empty array: all requested filters will be used
// non-empty array: only that filters are allowed to be used
// $filtersallowed[] = 'filter-attr1-attr2';

# Security Configuration --- End

# System Configuration --- Begin

$pathToCache = "./cache/"; // path to cache files, relative to location of instantpicture.php
$pathToFilters = "./filters/"; // path to filters, relative to location of instantpicture.php

# System Configuration --- End

# User Preferences --- Begin

$quality = 80; // quality for Jpeg images: 1 (worst) to 99 (best)
$debug = 1; // debug level: 0 (off) | 1 (on, showed in picture) | 2 (debuginfo)
$debugtype = 'png'; // image type for debug info
$cache = 'off'; // off | hash | long | mixed
$cachefilterorder = false; // order of requested filters belongs to cache name
$defaultfilter = 'nofilter'; // default filter used for images requested without filter

// shortcuts for filters and combined filters
# $shortcuts['shortcut'] = 'anothershortcut01/anothershortcut02';
# $shortcuts['anothershortcut01'] = 'filter1-attr1-attr2';
# $shortcuts['anothershortcut02'] = 'filter2-attr1/filter3-attr1-attr2-attr3';

# User Preferences --- End

?>
Loading

0 comments on commit 01d8ab9

Please sign in to comment.