Initial import: Carteasy Shop (Dev-Stand)
This commit is contained in:
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
require 'phImaginator/phImaginator.class.php';
|
||||
|
||||
$rsis = new phImaginator();
|
||||
|
||||
|
||||
/*
|
||||
* Quelldateien hinzufügen
|
||||
*
|
||||
* Dateien können einzeln oder gesammelt hinzugefügt werden
|
||||
*
|
||||
* 1. Eine einzelne Datei, z. B. "quellordner/bildchen/bild1.jpg"
|
||||
* 2. Ein ganzes Verzeichnis, z. B. "quellordner/bildchen"
|
||||
* 3. Ein Array von Dateien, z. B. "array('datei1.jpg', 'datei2.jpg')"
|
||||
* 4. Ein Array von Verzeichnissen, z. B. "array('order1', 'ordner2')"
|
||||
* 5. Ein Array von Dateien und Verzeichnissen
|
||||
*/
|
||||
$rsis->add('demosource/amy-adams.jpg');
|
||||
|
||||
|
||||
/*
|
||||
* Verkleinern auf eine maximale Breite
|
||||
*
|
||||
* Die Höhe wird proportional angepasst
|
||||
*/
|
||||
//$rsis->Resize_fitWidth(300);
|
||||
|
||||
|
||||
/*
|
||||
* Verkleinern auf eine maximale Höhe
|
||||
*
|
||||
* Die Breite wird proportional angepasst
|
||||
*/
|
||||
//$rsis->Resize_fitHeight(300);
|
||||
|
||||
|
||||
/*
|
||||
* Verkleinern auf eine maximale Höhe und Breite
|
||||
*
|
||||
* Breite und Höhe werden proportional so angepasst, dass weder Breite noch Höhe die angegebenen
|
||||
* Maximal-Werte überschreiten
|
||||
*/
|
||||
//$rsis->Resize_fitBoth(200, 200);
|
||||
|
||||
|
||||
/*
|
||||
* Skalieren auf eine feste Breite und Höhe
|
||||
*
|
||||
* Breite und Höhe werden aproportional so angepasst, dass beide den angegebenen Werten entsprechen
|
||||
*/
|
||||
//$rsis->Resize_scale(5000, 5000);
|
||||
|
||||
|
||||
/*
|
||||
* Einboxen
|
||||
*
|
||||
* Breite oder Höhe werden poroportional so angepasst, dass die kürzere Seite in die Box passt.
|
||||
* Der auf beiden Seiten überstehende Rest auf der Achse der längeren Seite des Bildes wird abgeschnitten.
|
||||
*/
|
||||
//$rsis->Box_fit(250, 250);
|
||||
|
||||
|
||||
/*
|
||||
* Ausschnitt
|
||||
*
|
||||
* Ein Ausschnitt der Größe P1 x P2 wird ab der Position P3/P4 ausgeschnitten
|
||||
*/
|
||||
//$rsis->Box_crop(500, 500, 50, 50);
|
||||
|
||||
|
||||
/*
|
||||
* Spiegeln
|
||||
*
|
||||
* Spiegelt das Bild um die horizontale bzw. vertikale Achse oder um beide Achsen
|
||||
*/
|
||||
//$rsis->Flip_horizontal();
|
||||
//$rsis->Flip_vertical();
|
||||
//$rsis->Flip_both();
|
||||
|
||||
|
||||
/*
|
||||
* Rotieren
|
||||
*
|
||||
* Rotiert das Bild um P1°.
|
||||
* Die Farbe des Hintergrundes wird über P2 definiert
|
||||
* P3 bestimmt die Opazität (wirkt sich nur bei der Generierung von PNG aus)
|
||||
*/
|
||||
//$rsis->Rotate_degree(45, '#000000', 50);
|
||||
|
||||
|
||||
/*
|
||||
* Rotieren ins Querformat
|
||||
*
|
||||
* Rotiert das Bild so, dass die Breite größer ist als die Höhe
|
||||
*/
|
||||
//$rsis->Rotate_landscape();
|
||||
|
||||
|
||||
/*
|
||||
* Rotieren ins Hochformat
|
||||
*
|
||||
* Rotiert das Bild so, dass die Höhe größer ist als die Breite
|
||||
*/
|
||||
//$rsis->Rotate_portrait();
|
||||
|
||||
|
||||
/*
|
||||
* Rahmung außen
|
||||
*
|
||||
* Setzt einen Rahmen der Breite P1 und Farbe P2 um das Bild
|
||||
* Die Abmessungen des Bildes werden vergrößert (Rahmen außen am Bild)
|
||||
*/
|
||||
//$rsis->Border_outer(20, '#00ff00');
|
||||
|
||||
|
||||
/*
|
||||
* Rahmung innen
|
||||
*
|
||||
* Setzt einen Rahmen der Breite P1 und Farbe P2 in das Bild
|
||||
* Die Abmessungen des Bildes bleiben unverändert
|
||||
* Der Rahmen überdeckt den äußeren Bereich des Bildes
|
||||
*/
|
||||
//$rsis->Border_inner(500, '#00ff00');
|
||||
|
||||
|
||||
/*
|
||||
* Rahmung innen Variante
|
||||
*
|
||||
* Setzt einen Rahmen der Breite P1 und Farbe P2 in das Bild
|
||||
* Die Abmessungen des Bildes bleiben unverändert
|
||||
* Der Rahmen überdeckt den äußeren Bereich des Bildes nicht, das Bild wird hingegen aproportional
|
||||
* so skaliert, dass es innerhalb des Rahmens passt
|
||||
*/
|
||||
//$rsis->Border_stretched(50, '#00ff00');
|
||||
|
||||
|
||||
/*
|
||||
* Farbtonänderung
|
||||
*
|
||||
* Farben werden angepasst. Schwarz und weiß bleiben erhalten
|
||||
* RGB (P1, P2, P3)
|
||||
* Sättigung (P4)
|
||||
*/
|
||||
//$rsis->Filter_hue(50, 10, 200, 100);
|
||||
|
||||
|
||||
/*
|
||||
* Sepia
|
||||
*
|
||||
*/
|
||||
//$rsis->Filter_sepia();
|
||||
|
||||
|
||||
/*
|
||||
* PHP Standard-Filter (Rauschen, Weichzeichnen usw.)
|
||||
* http://php.net/manual/de/function.imagefilter.php
|
||||
*
|
||||
*/
|
||||
//$rsis->Filter_common(IMG_FILTER_MEAN_REMOVAL);
|
||||
|
||||
|
||||
/*
|
||||
* Farbreduktion
|
||||
*
|
||||
* Reduziert die Farben des Bildes um P1%
|
||||
*/
|
||||
//$rsis->Filter_reduceColors(50);
|
||||
|
||||
|
||||
/*
|
||||
* Beschriftung - Schriftart und Format
|
||||
*
|
||||
* Definiert die Schrift für Beschriftungen
|
||||
*
|
||||
* P1: Font file
|
||||
* P2: Font size
|
||||
* P3: Font colour
|
||||
* P4: Transparenz
|
||||
*/
|
||||
//$rsis->setFont('BAUHS93.ttf', 30, '#000000', 50);
|
||||
|
||||
|
||||
/*
|
||||
* Beschriftung Freitext
|
||||
*
|
||||
* Beschriftet das Bild
|
||||
*
|
||||
* P1: Text
|
||||
* P2: Horizontale Position
|
||||
* P3: Vertikale Position
|
||||
* P4: Rotation
|
||||
*/
|
||||
//$rsis->Write_text('Hallo Du', phImaginator::POSITION_CENTER, phImaginator::POSITION_MIDDLE, 45);
|
||||
|
||||
|
||||
/*
|
||||
* Beschriftung Dateiinfo
|
||||
*
|
||||
* Beschriftet das Bild mit Dateiinformationen
|
||||
*
|
||||
* P1: Horizontale Position
|
||||
* P2: Vertikale Position
|
||||
*/
|
||||
//$rsis->Write_fileInfo(phImaginator::POSITION_CENTER, phImaginator::POSITION_MIDDLE);
|
||||
|
||||
|
||||
/*
|
||||
* Rechteck zeichnen
|
||||
*
|
||||
* Zeichnet ein Rechteck in das Bild
|
||||
*
|
||||
* P1: Horizontale Position
|
||||
* P2: Vertikale Position
|
||||
* P3: Breite absolut in Pixeln (integer) oder prozentual (string)
|
||||
* P4: Höhe absolut in Pixeln (integer) oder prozentual (string)
|
||||
* P5: Farbe
|
||||
* P6: Opazität
|
||||
*/
|
||||
//$rsis->Draw_rectangle(phImaginator::POSITION_LEFT, phImaginator::POSITION_MIDDLE, '50%', 30, '#141615', 50);
|
||||
|
||||
|
||||
/*
|
||||
* Stempeln
|
||||
*
|
||||
* Stempelt ein Bild mit einem Stempel
|
||||
*
|
||||
* P1: Stempel-Quelldatei
|
||||
* P2: Horizontale Position
|
||||
* P3: Vertikale Position
|
||||
* P4: Opazität
|
||||
* P5: Größenanpassung des Stempels (FITTING_WIDTH, FITTING_HEIGHT, FITTING_BOTH oder false)
|
||||
*/
|
||||
//$rsis->Mask_stamp(
|
||||
// 'bug.png',
|
||||
// phImaginator::POSITION_CENTER,
|
||||
// phImaginator::POSITION_MIDDLE,
|
||||
// 50
|
||||
//);
|
||||
|
||||
|
||||
/*
|
||||
* Runde Ecken (standard, relativ hart)
|
||||
*
|
||||
* Rundet die Ecken mit P1 Pixeln ab. Bei PNG-Ausgabe sind die Ecken transparent
|
||||
*/
|
||||
//$rsis->Mask_corners(25);
|
||||
|
||||
|
||||
/*
|
||||
* Runde Ecken (besser, smoother)
|
||||
*
|
||||
* Rundet die Ecken mit P1 Pixeln ab. Bei PNG-Ausgabe sind die Ecken transparent.
|
||||
* P2 gibt an, welche Ecken gerundet werden sollen (POSITION_ALL & Co.)
|
||||
*/
|
||||
//$rsis->Mask_betterCorners(25, phImaginator::POSITION_ALL);
|
||||
|
||||
|
||||
/*
|
||||
* Reflexionen
|
||||
*
|
||||
* Reflektiert (Wasserspiegel) das Bild. Bei Ausgabe als PNG ist die Reflexion teiltransparent.
|
||||
*
|
||||
* P1: Höhe der Reflexion in Prozent (string) oder Pixeln (integer)
|
||||
* P2: Abstand zwischen Bild und Reflexion in Pixeln
|
||||
* P3: Proportion der Reflexion (float)
|
||||
* P4: Anfangsopazität der Reflexion
|
||||
* P4: Verlaufsmodus (TRANSITION_LOGARITHMIC, TRANSITION_EXPONENTIAL oder TRANSITION_LINEAR)
|
||||
*/
|
||||
//$rsis->Reflect_common('85%', 2, 1.2, 65, phImaginator::TRANSITION_LOGARITHMIC);
|
||||
|
||||
|
||||
/*
|
||||
* Histogramm
|
||||
*
|
||||
* Erstellung eines Histogramms
|
||||
*/
|
||||
//$rsis->Measure_histogram();
|
||||
|
||||
|
||||
/*
|
||||
* Dateinamen Präfix / Suffix
|
||||
*
|
||||
* Fügt dem Dateinamen beim Speichern einen Zusatz zu
|
||||
*
|
||||
* P1: Präfix
|
||||
* P2: Suffix
|
||||
*/
|
||||
//$rsis->nameAdd('vorne', 'hinten');
|
||||
|
||||
|
||||
/*
|
||||
* Speichern
|
||||
*
|
||||
* Fügt dem Dateinamen beim Speichern einen Zusatz zu
|
||||
*
|
||||
* P1: Typ (IMAGETYPE_JPEG, IMAGETYPE_PNG oder IMAGETYPE_GIF)
|
||||
* P2: Qualität (JPEG und tw PNG)
|
||||
* P3: Ziel (Pfad)
|
||||
*/
|
||||
$rsis->save(IMAGETYPE_JPEG, 85, './');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Nicht fertige Module
|
||||
////////$rsis->Collage_ordered(600, 400, '#FF0000', 50);
|
||||
////////$rsis->Collage_fitted(600, 400, '#FF0000', 50);
|
||||
////////$rsis->Merge_fitted(300, 200, 50);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Border extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function outer($borderWidth, $color = '#000000') {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
if (!is_array($color)) {
|
||||
$color = sscanf($color, '#%2x%2x%2x');
|
||||
}
|
||||
|
||||
$newWidth = $image_data['width'] + 2 * $borderWidth;
|
||||
$newHeight = $image_data['height'] + 2 * $borderWidth;
|
||||
|
||||
$borderedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
imagealphablending($borderedImage, false);
|
||||
imagesavealpha($borderedImage, true);
|
||||
|
||||
$colorResource = imagecolorallocate($borderedImage, $color[0], $color[1], $color[2]);
|
||||
imagefill($borderedImage, 0, 0, $colorResource);
|
||||
|
||||
imagecopy($borderedImage, $image_data['resource'], $borderWidth, $borderWidth, 0, 0, $image_data['width'], $image_data['height']);
|
||||
|
||||
$image_data['resource'] = $borderedImage;
|
||||
|
||||
$image_data['width'] = imagesx($image_data['resource']);
|
||||
$image_data['height'] = imagesy($image_data['resource']);
|
||||
}
|
||||
|
||||
|
||||
public static function inner($borderWidth, $color = '#000000') {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
if (!is_array($color)) {
|
||||
$color = sscanf($color, '#%2x%2x%2x');
|
||||
}
|
||||
|
||||
$newWidth = $image_data['width'];
|
||||
$newHeight = $image_data['height'];
|
||||
|
||||
$borderedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
imagealphablending($borderedImage, false);
|
||||
imagesavealpha($borderedImage, true);
|
||||
|
||||
$colorResource = imagecolorallocate($borderedImage, $color[0], $color[1], $color[2]);
|
||||
imagefill($borderedImage, 0, 0, $colorResource);
|
||||
|
||||
imagecopy($borderedImage, $image_data['resource'], $borderWidth, $borderWidth, $borderWidth, $borderWidth, $image_data['width'] - 2 * $borderWidth, $image_data['height'] - 2 * $borderWidth);
|
||||
|
||||
$image_data['resource'] = $borderedImage;
|
||||
}
|
||||
|
||||
|
||||
public static function stretched($borderWidth, $color = '#000000') {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
if (!is_array($color)) {
|
||||
$color = sscanf($color, '#%2x%2x%2x');
|
||||
}
|
||||
|
||||
$newWidth = $image_data['width'];
|
||||
$newHeight = $image_data['height'];
|
||||
|
||||
$borderedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
imagealphablending($borderedImage, false);
|
||||
imagesavealpha($borderedImage, true);
|
||||
|
||||
$colorResource = imagecolorallocate($borderedImage, $color[0], $color[1], $color[2]);
|
||||
imagefill($borderedImage, 0, 0, $colorResource);
|
||||
|
||||
imagecopyresampled($borderedImage, $image_data['resource'], $borderWidth, $borderWidth, 0, 0, $image_data['width'] - 2 * $borderWidth, $image_data['height'] - 2 * $borderWidth, $image_data['width'], $image_data['height']);
|
||||
|
||||
$image_data['resource'] = $borderedImage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Box extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function fit($width, $height) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$imageBox = imagecreatetruecolor($width, $height);
|
||||
imagealphablending($imageBox, false);
|
||||
imagesavealpha($imageBox, true);
|
||||
|
||||
$proportions['w'] = $width / $image_data['width'];
|
||||
$proportions['h'] = $height / $image_data['height'];
|
||||
|
||||
$use_proportion = max($proportions);
|
||||
|
||||
$crop_width = $image_data['width'] * $use_proportion;
|
||||
$crop_height = $image_data['height'] * $use_proportion;
|
||||
|
||||
imagecopyresampled(
|
||||
$imageBox,
|
||||
$image_data['resource'],
|
||||
0,
|
||||
0,
|
||||
($crop_width - $width) / $use_proportion / 2,
|
||||
($crop_height - $height) / $use_proportion / 2,
|
||||
$crop_width,
|
||||
$crop_height,
|
||||
$image_data['width'],
|
||||
$image_data['height']
|
||||
);
|
||||
|
||||
$image_data['resource'] = $imageBox;
|
||||
$image_data['width'] = $width;
|
||||
$image_data['height'] = $height;
|
||||
}
|
||||
|
||||
|
||||
public static function crop($width, $height, $start_x, $start_y) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$imageBox = imagecreatetruecolor($width, $height);
|
||||
imagealphablending($imageBox, false);
|
||||
imagesavealpha($imageBox, true);
|
||||
|
||||
imagecopy(
|
||||
$imageBox,
|
||||
$image_data['resource'],
|
||||
0,
|
||||
0,
|
||||
$start_x,
|
||||
$start_y,
|
||||
$width,
|
||||
$height
|
||||
);
|
||||
|
||||
$image_data['resource'] = $imageBox;
|
||||
$image_data['width'] = $width;
|
||||
$image_data['height'] = $height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Collage extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
|
||||
protected static $runCollected = true;
|
||||
|
||||
|
||||
public static function ordered($params) {
|
||||
require_once 'phImaginator.Resize.class.php';
|
||||
|
||||
self::universalCollage('ordered', $params);
|
||||
}
|
||||
|
||||
|
||||
public static function fitted($params) {
|
||||
require_once 'phImaginator.Box.class.php';
|
||||
|
||||
self::universalCollage('fitted', $params);
|
||||
}
|
||||
|
||||
|
||||
private static function universalCollage($type, $params) {
|
||||
$width = $params[0];
|
||||
$height = $params[1];
|
||||
|
||||
if (is_array(parent::$imageSourceCollection)) {
|
||||
|
||||
$images_count = count(parent::$imageSourceCollection);
|
||||
|
||||
$proportion = $width / $height;
|
||||
|
||||
$imr = sqrt($images_count);
|
||||
$imr_x = round($imr * $proportion);
|
||||
$imr_y = round($images_count / $imr_x);
|
||||
|
||||
$imageBox_w = $width / $imr_x;
|
||||
$imageBox_h = $height / $imr_y;
|
||||
|
||||
$collageImage = imagecreatetruecolor($width, $height);
|
||||
|
||||
$bgcolor = parent::transparency($collageImage, $params[2], $params[3]);
|
||||
|
||||
imagefill($collageImage, 0, 0, $bgcolor);
|
||||
|
||||
for ($y = 0; $y < $imr_y; ++$y) {
|
||||
for ($x = 0; $x < $imr_x; ++$x) {
|
||||
$image_data = array_shift(parent::$imageSourceCollection);
|
||||
if (!$image_data) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($type == 'fitted') {
|
||||
phImaginator_Box::fit($image_data, array($imageBox_w, $imageBox_h));
|
||||
} else if ($type == 'ordered') {
|
||||
phImaginator_Resize::fitBoth($image_data, array($imageBox_w, $imageBox_h));
|
||||
}
|
||||
|
||||
imagecopyresampled($collageImage, $image_data['resource'], $x * $imageBox_w, $y * $imageBox_h, 0, 0, $image_data['width'], $image_data['height'], $image_data['width'], $image_data['height']);
|
||||
}
|
||||
}
|
||||
|
||||
parent::replaceSourceCollection($collageImage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Draw extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function rectangle($position_horizontal, $position_vertical, $width, $height, $color, $opacity) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$bgColor = parent::transparency($image_data['resource'], $color, $opacity);
|
||||
|
||||
$elemPos = parent::getElementPositions($position_horizontal, $position_vertical, $image_data, $width, $height);
|
||||
$elemSizes = parent::computeElementSizes($image_data, $width, $height);
|
||||
|
||||
imagefilledrectangle($image_data['resource'], $elemPos['x'], $elemPos['y'], $elemPos['x'] + $elemSizes['w'], $elemPos['y'] + $elemSizes['h'], $bgColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Filter extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
// (c) mail at kavisiegel dot com
|
||||
public static function hue($r, $g, $b, $saturation = 100) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$transparency = parent::calculateTransparency($saturation);
|
||||
|
||||
$rgb = $r + $g + $b;
|
||||
|
||||
$rgb = ($rgb > 0) ? $rgb : 1;
|
||||
|
||||
$col = array($r / $rgb, $b / $rgb, $g / $rgb);
|
||||
|
||||
$width = $image_data['width'];
|
||||
$height = $image_data['height'];
|
||||
|
||||
for ($x = 0; $x < $width; ++$x) {
|
||||
for ($y = 0; $y < $height; ++$y) {
|
||||
$rgb = imagecolorat($image_data['resource'], $x, $y);
|
||||
|
||||
$r = ($rgb >> 16) & 0xFF;
|
||||
$g = ($rgb >> 8) & 0xFF;
|
||||
$b = $rgb & 0xFF;
|
||||
|
||||
$newR = $r * $col[0] + $g * $col[1] + $b * $col[2];
|
||||
$newG = $r * $col[2] + $g * $col[0] + $b * $col[1];
|
||||
$newB = $r * $col[1] + $g * $col[2] + $b * $col[0];
|
||||
|
||||
imagesetpixel($image_data['resource'], $x, $y, imagecolorallocatealpha($image_data['resource'], $newR, $newG, $newB, $transparency));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function sepia() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
imagetruecolortopalette($image_data['resource'], true, 256);
|
||||
|
||||
$colors = imagecolorstotal($image_data['resource']);
|
||||
|
||||
for ($i = 0; $i < $colors; ++$i) {
|
||||
$pindex = imagecolorsforindex($image_data['resource'], $i);
|
||||
|
||||
$r = ($pindex['red'] * 0.393 + $pindex['green'] * 0.769 + $pindex['blue'] * 0.189 ) / 1.351;
|
||||
$g = ($pindex['red'] * 0.349 + $pindex['green'] * 0.686 + $pindex['blue'] * 0.168) / 1.203;
|
||||
$b = ($pindex['red'] * 0.372 + $pindex['green'] * 0.534 + $pindex['blue'] * 0.131) / 2.140;
|
||||
|
||||
imagecolorset($image_data['resource'], $i, $r, $g, $b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function common($filterType, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$putArguments = array($image_data['resource'], $filterType);
|
||||
|
||||
for ($arg = 1; $arg <= 4; ++$arg) {
|
||||
if (isset(${'arg' . $arg})) {
|
||||
$putArguments[] = ${'arg' . $arg};
|
||||
}
|
||||
}
|
||||
|
||||
call_user_func_array('imagefilter', $putArguments);
|
||||
}
|
||||
|
||||
|
||||
public static function reduceColors($percentage = 100) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$transparency = parent::calculateTransparency($percentage);
|
||||
|
||||
for ($x = 0; $x < $image_data['width']; ++$x) {
|
||||
for ($y = 0; $y < $image_data['height']; ++$y) {
|
||||
$rgb = imagecolorat($image_data['resource'], $x, $y);
|
||||
|
||||
$r = ($rgb >> 16) & 0xFF;
|
||||
$g = ($rgb >> 8) & 0xFF;
|
||||
$b = $rgb & 0xFF;
|
||||
|
||||
$c = ($r + $g + $b) / 3;
|
||||
|
||||
imagesetpixel($image_data['resource'], $x, $y, imagecolorallocatealpha($image_data['resource'], $c, $c, $c, $transparency));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Flip extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function horizontal() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$image = imagecreatetruecolor($image_data['width'], $image_data['height']);
|
||||
imagealphablending($image, false);
|
||||
imagesavealpha($image, true);
|
||||
|
||||
imagecopyresampled($image, $image_data['resource'], 0, 0, 0, $image_data['height'] - 1, $image_data['width'], $image_data['height'], $image_data['width'], -$image_data['height']);
|
||||
|
||||
$image_data['resource'] = $image;
|
||||
}
|
||||
|
||||
|
||||
public static function vertical() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$image = imagecreatetruecolor($image_data['width'], $image_data['height']);
|
||||
imagealphablending($image, false);
|
||||
imagesavealpha($image, true);
|
||||
|
||||
imagecopyresampled($image, $image_data['resource'], 0, 0, $image_data['width'] - 1, 0, $image_data['width'], $image_data['height'], -$image_data['width'], $image_data['height']);
|
||||
|
||||
$image_data['resource'] = $image;
|
||||
}
|
||||
|
||||
|
||||
public static function both() {
|
||||
self::horizontal();
|
||||
self::vertical();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* R&S Imagination Suite
|
||||
* Mask Class
|
||||
*
|
||||
* blah fasel description
|
||||
*
|
||||
* @author Darius A. Zylka <rs@regen-sonne.de>
|
||||
* @copyright (c) 2009 Darius A. Zylka
|
||||
* @version 1.0
|
||||
* @package phImaginator
|
||||
* @subpackage phImaginator_Mask
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Mask class
|
||||
*
|
||||
* @package phImaginator
|
||||
* @subpackage phImaginator_Mask
|
||||
*
|
||||
*/
|
||||
abstract class phImaginator_Mask extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
|
||||
/**
|
||||
* Defines if the desired method of this class should be used for each source element or for all elements at once
|
||||
*
|
||||
* @access protected
|
||||
* @var bool
|
||||
*/
|
||||
protected static $runCollected = false;
|
||||
|
||||
/**
|
||||
* Stamps an image with another image with a defined opacity
|
||||
*
|
||||
* @param array $image_data Image data array from the image resource collection
|
||||
* @param array $params Submitted parameters
|
||||
* @uses phImaginator::$imageSourceCollection
|
||||
*/
|
||||
public static function stamp($stamp_file, $position_horizontal, $position_vertical, $opacity, $fitting = false) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$cache_name = serialize(array(__METHOD__, $stamp_file, $position_horizontal, $position_vertical, $opacity, $fitting));
|
||||
|
||||
$cached_data = parent::getCachedData($cache_name);
|
||||
|
||||
if ($cached_data) {
|
||||
$stamp_w = $cached_data[1];
|
||||
$stamp_h = $cached_data[2];
|
||||
|
||||
$stamp_mod = $cached_data[0];
|
||||
} else {
|
||||
$stamp = imagecreatefrompng($stamp_file);
|
||||
|
||||
$stamp_w = imagesx($stamp);
|
||||
$stamp_h = imagesy($stamp);
|
||||
|
||||
$stamp_mod = imagecreatetruecolor($stamp_w, $stamp_h);
|
||||
|
||||
$colortrans = parent::transparency($stamp_mod, array(127, 127, 127), $opacity);
|
||||
imagefill($stamp_mod, 0, 0, $colortrans);
|
||||
|
||||
imagelayereffect($stamp_mod, IMG_EFFECT_OVERLAY);
|
||||
|
||||
imagecopyresampled($stamp_mod, $stamp, 0, 0, 0, 0, $stamp_w, $stamp_h, $stamp_w, $stamp_h);
|
||||
|
||||
parent::cacheData($cache_name, array($stamp_mod, $stamp_w, $stamp_h));
|
||||
}
|
||||
|
||||
$stampSizes['w'] = $stamp_w;
|
||||
$stampSizes['h'] = $stamp_h;
|
||||
|
||||
if ($fitting) {
|
||||
$stampSizes = parent::computeElementSizes($image_data, $fitting, null, $stamp_w, $stamp_h);
|
||||
}
|
||||
$stampPos = parent::getElementPositions($position_horizontal, $position_vertical, $image_data, $stampSizes['w'], $stampSizes['h']);
|
||||
|
||||
imagecopyresampled($image_data['resource'], $stamp_mod, $stampPos['x'], $stampPos['y'], 0, 0, $stampSizes['w'], $stampSizes['h'], $stamp_w, $stamp_h);
|
||||
}
|
||||
|
||||
|
||||
public static function corners($corner_radius) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$w = $image_data['width'];
|
||||
$h = $image_data['height'];
|
||||
|
||||
|
||||
$mask = imagecreatetruecolor($w, $h);
|
||||
imageantialias($mask, true);
|
||||
imageantialias($image_data['resource'], true);
|
||||
|
||||
$transColor = imagecolorallocatealpha($mask, 255, 0, 255, 127);
|
||||
imagefill($mask, 0, 0, $transColor);
|
||||
imagecolortransparent($mask, $transColor);
|
||||
|
||||
$overlayColor = imagecolorallocate($mask, 127, 127, 127);
|
||||
|
||||
imagefilledellipse($mask, $corner_radius, $corner_radius, $corner_radius * 2, $corner_radius * 2, $overlayColor);
|
||||
imagefilledellipse($mask, $corner_radius, $h - $corner_radius, $corner_radius * 2, $corner_radius * 2, $overlayColor);
|
||||
imagefilledellipse($mask, $w - $corner_radius, $corner_radius, $corner_radius * 2, $corner_radius * 2, $overlayColor);
|
||||
imagefilledellipse($mask, $w - $corner_radius, $h - $corner_radius, $corner_radius * 2, $corner_radius * 2, $overlayColor);
|
||||
imagefilledrectangle($mask, $corner_radius, 0, $w - $corner_radius, $h, $overlayColor);
|
||||
imagefilledrectangle($mask, 0, $corner_radius, $w, $h - $corner_radius, $overlayColor);
|
||||
|
||||
imagelayereffect($mask, IMG_EFFECT_OVERLAY);
|
||||
|
||||
imagecopyresampled($mask, $image_data['resource'], 0, 0, 0, 0, $w, $h, $w, $h);
|
||||
|
||||
$image_data['resource'] = $mask;
|
||||
}
|
||||
|
||||
|
||||
public static function betterCorners($corner_radius, $positions = POSITION_ALL) {
|
||||
$image_data = parent::getCurrentResource();
|
||||
|
||||
$cache_name = serialize(array(__METHOD__, $corner_radius));
|
||||
|
||||
$cached_data = parent::getCachedData($cache_name);
|
||||
|
||||
if ($cached_data) {
|
||||
$corner2 = $cached_data[0];
|
||||
} else {
|
||||
$rounded_corner = parent::getImageResource('rounded_corner');
|
||||
|
||||
$corner = imagecreatefromstring(base64_decode($rounded_corner));
|
||||
|
||||
|
||||
$corner2 = imagecreatetruecolor($corner_radius * 2, $corner_radius * 2);
|
||||
imagealphablending($corner2, false);
|
||||
imagesavealpha($corner2, true);
|
||||
|
||||
imagecopyresampled($corner2, $corner, 0, 0, 0, 0, $corner_radius * 2, $corner_radius * 2, imagesx($corner), imagesy($corner));
|
||||
|
||||
parent::cacheData($cache_name, array($corner2));
|
||||
}
|
||||
|
||||
$w = $image_data['width'];
|
||||
$h = $image_data['height'];
|
||||
|
||||
imagelayereffect($image_data['resource'], IMG_EFFECT_OVERLAY);
|
||||
|
||||
if (phImaginator::POSITION_LEFT_TOP & $positions || phImaginator::POSITION_ALL & $positions || phImaginator::POSITION_TOP & $positions || phImaginator::POSITION_LEFT & $positions) {
|
||||
imagecopyresampled($image_data['resource'], $corner2, 0, 0, 0, 0, $corner_radius, $corner_radius, $corner_radius, $corner_radius);
|
||||
}
|
||||
if (phImaginator::POSITION_LEFT_BOTTOM & $positions || phImaginator::POSITION_ALL & $positions || phImaginator::POSITION_BOTTOM & $positions || phImaginator::POSITION_LEFT & $positions) {
|
||||
imagecopyresampled($image_data['resource'], $corner2, 0, $h - $corner_radius, 0, $corner_radius, $corner_radius, $corner_radius, $corner_radius, $corner_radius);
|
||||
}
|
||||
if (phImaginator::POSITION_RIGHT_TOP & $positions || phImaginator::POSITION_ALL & $positions || phImaginator::POSITION_TOP & $positions || phImaginator::POSITION_RIGHT & $positions) {
|
||||
imagecopyresampled($image_data['resource'], $corner2, $w - $corner_radius, 0, $corner_radius, 0, $corner_radius, $corner_radius, $corner_radius, $corner_radius);
|
||||
}
|
||||
if (phImaginator::POSITION_RIGHT_BOTTOM & $positions || phImaginator::POSITION_ALL & $positions || phImaginator::POSITION_BOTTOM & $positions || phImaginator::POSITION_RIGHT & $positions) {
|
||||
imagecopyresampled($image_data['resource'], $corner2, $w - $corner_radius, $h - $corner_radius, $corner_radius, $corner_radius, $corner_radius, $corner_radius, $corner_radius, $corner_radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Measure extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function histogram() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$w = $image_data['width'];
|
||||
$h = $image_data['height'];
|
||||
|
||||
$resource =& $image_data['resource'];
|
||||
|
||||
$colorcount = array('rgb' => array(), 'r' => array(), 'g' => array(), 'b' => array());
|
||||
$colorSums = array('rgb' => 0, 'r' => 0, 'g' => 0, 'b' => 0);
|
||||
|
||||
for ($x = 0; $x < $w; ++$x) {
|
||||
for ($y = 0; $y < $h; ++$y) {
|
||||
$rgb = imagecolorat($resource, $x, $y);
|
||||
|
||||
$t = ($rgb >> 24) & 0xFF;
|
||||
$r = ($rgb >> 16) & 0xFF;
|
||||
$g = ($rgb >> 8) & 0xFF;
|
||||
$b = $rgb & 0xFF;
|
||||
|
||||
++$colorcount['rgb'][($r + $g + $b) / 3];
|
||||
++$colorcount['r'][$r];
|
||||
++$colorcount['g'][$g];
|
||||
++$colorcount['b'][$b];
|
||||
}
|
||||
}
|
||||
|
||||
$maxColors = max(array(max($colorcount['rgb']), max($colorcount['r']), max($colorcount['g']), max($colorcount['b'])));
|
||||
|
||||
$infoHeight = 12;
|
||||
|
||||
$pixelsPerColorStep = (($h - 1) - $infoHeight * 2) / $maxColors;
|
||||
$pixelsPerColor = ($w - 1) / 256;
|
||||
|
||||
$overlay = imagecreatetruecolor($w, $h);
|
||||
imagefill($overlay, 0, 0, imagecolorallocate($overlay, 0, 0, 0));
|
||||
|
||||
imagecopymerge($resource, $overlay, 0, 0, 0, 0, $w, $h, 80);
|
||||
|
||||
$rColor = imagecolorallocatealpha($resource, 255, 0, 0, 80);
|
||||
$gColor = imagecolorallocatealpha($resource, 0, 255, 0, 80);
|
||||
$bColor = imagecolorallocatealpha($resource, 0, 0, 255, 80);
|
||||
$grayColor = imagecolorallocatealpha($resource, 255, 255, 255, 63);
|
||||
|
||||
$points = array(0, $h - 1 - $infoHeight);
|
||||
for ($c = 0; $c <= 255; ++$c) {
|
||||
$points[] = $c * $pixelsPerColor + 1;
|
||||
$points[] = ($h - 1 - $infoHeight) - $colorcount['rgb'][$c] * $pixelsPerColorStep - 1;
|
||||
|
||||
imagefilledrectangle($resource, $c * $pixelsPerColor, $h - 1 - $infoHeight, $c * ($pixelsPerColor * 2), $h - 1, imagecolorallocate($resource, $c, $c, $c));
|
||||
}
|
||||
$points[] = $w;
|
||||
$points[] = $h - 1 - $infoHeight;
|
||||
|
||||
imagefilledpolygon($resource, $points, count($points) / 2, $grayColor);
|
||||
|
||||
for ($c = 0; $c <= 255; ++$c) {
|
||||
imageline(
|
||||
$resource,
|
||||
$c * $pixelsPerColor + 1,
|
||||
($h - 1 - $infoHeight) - $colorcount['r'][$c] * $pixelsPerColorStep - 1,
|
||||
($c - 1) * $pixelsPerColor + 1,
|
||||
($h - 1 - $infoHeight) - $colorcount['r'][$c - 1] * $pixelsPerColorStep - 1,
|
||||
$rColor
|
||||
);
|
||||
imagefilledrectangle($resource, $c * $pixelsPerColor, 0, $c * ($pixelsPerColor * 2), $infoHeight / 3 - 1, imagecolorallocate($resource, $c, 0, 0));
|
||||
|
||||
imageline(
|
||||
$resource,
|
||||
$c * $pixelsPerColor + 1,
|
||||
($h - 1 - $infoHeight) - $colorcount['g'][$c] * $pixelsPerColorStep - 1,
|
||||
($c - 1) * $pixelsPerColor + 1,
|
||||
($h - 1 - $infoHeight) - $colorcount['g'][$c - 1] * $pixelsPerColorStep - 1,
|
||||
$gColor
|
||||
);
|
||||
imagefilledrectangle($resource, $c * $pixelsPerColor, $infoHeight / 3, $c * ($pixelsPerColor * 2), ($infoHeight / 3) * 2 - 1, imagecolorallocate($resource, 0, $c, 0));
|
||||
|
||||
imageline(
|
||||
$resource,
|
||||
$c * $pixelsPerColor + 1,
|
||||
($h - 1 - $infoHeight) - $colorcount['b'][$c] * $pixelsPerColorStep - 1,
|
||||
($c - 1) * $pixelsPerColor + 1,
|
||||
($h - 1 - $infoHeight) - $colorcount['b'][$c - 1] * $pixelsPerColorStep - 1,
|
||||
$bColor
|
||||
);
|
||||
imagefilledrectangle($resource, $c * $pixelsPerColor, ($infoHeight / 3) * 2, $c * ($pixelsPerColor * 2), $infoHeight - 1, imagecolorallocate($resource, 0, 0, $c));
|
||||
|
||||
$colorSums['rgb'] += $c * $colorcount['rgb'][$c];
|
||||
$colorSums['r'] += $c * $colorcount['r'][$c];
|
||||
$colorSums['g'] += $c * $colorcount['g'][$c];
|
||||
$colorSums['b'] += $c * $colorcount['b'][$c];
|
||||
}
|
||||
|
||||
$rgbAverage = ($colorSums['rgb'] / array_sum($colorcount['rgb'])) * $pixelsPerColor + 1;
|
||||
imageline($resource, $rgbAverage, $infoHeight, $rgbAverage, ($h - $infoHeight * 2) / 4, $grayColor);
|
||||
|
||||
$rAverage = ($colorSums['r'] / array_sum($colorcount['r'])) * $pixelsPerColor + 1;
|
||||
imageline($resource, $rAverage, ($h - $infoHeight * 2) / 4, $rAverage, (($h - $infoHeight * 2) / 4) * 2, $rColor);
|
||||
|
||||
$gAverage = ($colorSums['g'] / array_sum($colorcount['g'])) * $pixelsPerColor + 1;
|
||||
imageline($resource, $gAverage, (($h - $infoHeight * 2) / 4) * 2, $gAverage, (($h - $infoHeight * 2) / 4) * 3, $gColor);
|
||||
|
||||
$bAverage = ($colorSums['b'] / array_sum($colorcount['b'])) * $pixelsPerColor + 1;
|
||||
imageline($resource, $bAverage, (($h - $infoHeight * 2) / 4) * 3, $bAverage, $h - $infoHeight - 1, $bColor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Merge extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
|
||||
protected static $runCollected = true;
|
||||
|
||||
|
||||
public static function fitted($params) {
|
||||
require_once 'phImaginator.Box.class.php';
|
||||
|
||||
self::universalMerger('fitted', $params);
|
||||
}
|
||||
|
||||
|
||||
private static function universalMerger($type, $params) {
|
||||
$width = $params[0];
|
||||
$height = $params[1];
|
||||
|
||||
$lucency = ($params[2]) ? $params[2] : 50;
|
||||
|
||||
if (is_array(parent::$imageSourceCollection)) {
|
||||
|
||||
$mergedImage = imagecreatetruecolor($width, $height);
|
||||
|
||||
$iteratorCnt = 0;
|
||||
|
||||
foreach (parent::$imageSourceCollection as $image_data) {
|
||||
if ($type == 'fitted') {
|
||||
phImaginator_Box::fit($image_data, array($width, $height));
|
||||
}
|
||||
|
||||
$useLucency = (++$iteratorCnt > 1) ? $lucency : 100;
|
||||
|
||||
imagecopymerge($mergedImage, $image_data['resource'], 0, 0, 0, 0, $image_data['width'], $image_data['height'], $useLucency);
|
||||
}
|
||||
|
||||
parent::replaceSourceCollection($mergedImage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
interface phImaginator_Module {
|
||||
|
||||
public static function ifRunCollected();
|
||||
|
||||
public static function assignImageSourceCollection(&$imageSourceCollection);
|
||||
|
||||
public static function transparency(&$image_resource, $color, $lucency);
|
||||
|
||||
public static function replaceSourceCollection($image_resource);
|
||||
|
||||
public static function addToSourceCollection($image_resource);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* R&S Imagination Suite
|
||||
* Mask Class
|
||||
*
|
||||
* blah fasel description
|
||||
*
|
||||
* @author Darius A. Zylka <rs@regen-sonne.de>
|
||||
* @copyright (c) 2009 Darius A. Zylka
|
||||
* @version 1.0
|
||||
* @package phImaginator
|
||||
* @subpackage phImaginator_Mask
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Mask class
|
||||
*
|
||||
* @package phImaginator
|
||||
* @subpackage phImaginator_Mask
|
||||
*
|
||||
*/
|
||||
abstract class phImaginator_Reflect extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
|
||||
/**
|
||||
* Defines if the desired method of this class should be used for each source element or for all elements at once
|
||||
*
|
||||
* @access protected
|
||||
* @var bool
|
||||
*/
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function common($height = '33%', $margin = 2, $proportion = 1.2, $startOpacity = 90, $transition = TRANSITION_LINEAR) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$computedSizes = parent::computeElementSizes($image_data, false, $height);
|
||||
|
||||
$reflection_height = $computedSizes['h'] / $proportion;
|
||||
$destination_height = $image_data['height'] + $reflection_height + $margin;
|
||||
|
||||
$destination = imagecreatetruecolor($image_data['width'], $destination_height);
|
||||
|
||||
imagealphablending($destination, false);
|
||||
$bgcol = imagecolorallocatealpha($destination, 255, 0, 255, 127);
|
||||
imagefilledrectangle($destination, 0, 0, $image_data['width'], $destination_height, $bgcol);
|
||||
|
||||
imagecopy($destination, $image_data['resource'], 0, 0, 0, 0, $image_data['width'], $image_data['height']);
|
||||
|
||||
$reflection = imagecreatetruecolor($image_data['width'], $reflection_height);
|
||||
|
||||
imagecopyresampled(
|
||||
$reflection,
|
||||
$image_data['resource'],
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$image_data['height'] - 1,
|
||||
$image_data['width'],
|
||||
$reflection_height,
|
||||
$image_data['width'],
|
||||
-($reflection_height * $proportion)
|
||||
);
|
||||
|
||||
|
||||
$startTransparency = 127 - ((127 / 100) * $startOpacity);
|
||||
$transLog = (127 - $startTransparency) / log($reflection_height);
|
||||
$transEx2 = (127 - $startTransparency) / $reflection_height;
|
||||
|
||||
for ($y = 0; $y <= $reflection_height - 1 + $margin; ++$y) {
|
||||
if ($transition == phImaginator::TRANSITION_LINEAR) {
|
||||
|
||||
$transparency = 127 - ((127 / 100) * (($startOpacity / $reflection_height) * ($reflection_height - ($y + 1))));
|
||||
|
||||
} else if ($transition == phImaginator::TRANSITION_LOGARITHMIC) {
|
||||
|
||||
$transparency = log($y + 1) * $transLog + $startTransparency;
|
||||
|
||||
} else if ($transition == phImaginator::TRANSITION_EXPONENTIAL) {
|
||||
|
||||
$transparency = floor(((($y + 1) / (1 / ($y + 1))) / $reflection_height) * $transEx2 + $startTransparency);
|
||||
|
||||
}
|
||||
|
||||
for ($x = 0; $x <= $image_data['width'] - 1; ++$x) {
|
||||
$colIndex = imagecolorat($reflection, $x, $y);
|
||||
$colours = imagecolorsforindex($reflection, $colIndex);
|
||||
$newcol[$x . $y] = imagecolorallocatealpha($destination, $colours['red'], $colours['green'], $colours['blue'], $transparency);
|
||||
imagesetpixel($destination, $x, $y + $image_data['height'] + $margin, $newcol[$x . $y]);
|
||||
}
|
||||
}
|
||||
|
||||
$image_data['resource'] = $destination;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Resize extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
private static $destination_width;
|
||||
private static $destination_height;
|
||||
|
||||
|
||||
public static function fitBoth($width, $height) {
|
||||
|
||||
self::$destination_width = $width;
|
||||
self::$destination_height = $height;
|
||||
|
||||
self::fitImage();
|
||||
}
|
||||
|
||||
|
||||
public static function fitWidth($width) {
|
||||
|
||||
self::$destination_width = $width;
|
||||
|
||||
self::fitImage();
|
||||
}
|
||||
|
||||
|
||||
public static function fitHeight($height) {
|
||||
|
||||
self::$destination_height = $height;
|
||||
|
||||
self::fitImage();
|
||||
}
|
||||
|
||||
|
||||
private static function fitImage() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$proportions = array();
|
||||
|
||||
if (self::$destination_width) {
|
||||
$proportions[] = self::$destination_width / $image_data['width'];
|
||||
}
|
||||
if (self::$destination_height) {
|
||||
$proportions[] = self::$destination_height / $image_data['height'];
|
||||
}
|
||||
|
||||
$use_proportion = min($proportions);
|
||||
|
||||
$width = $image_data['width'] * $use_proportion;
|
||||
$height = $image_data['height'] * $use_proportion;
|
||||
|
||||
$image = imagecreatetruecolor($width, $height);
|
||||
imagealphablending($image, false);
|
||||
imagesavealpha($image, true);
|
||||
|
||||
imagecopyresampled($image, $image_data['resource'], 0, 0, 0, 0, $width, $height, $image_data['width'], $image_data['height']);
|
||||
|
||||
$image_data['resource'] = $image;
|
||||
$image_data['width'] = $width;
|
||||
$image_data['height'] = $height;
|
||||
}
|
||||
|
||||
|
||||
public static function scale($width, $height) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
self::$destination_width = $width;
|
||||
self::$destination_height = $height;
|
||||
|
||||
$image = imagecreatetruecolor(self::$destination_width, self::$destination_height);
|
||||
imagealphablending($image, false);
|
||||
imagesavealpha($image, true);
|
||||
|
||||
imagecopyresampled($image, $image_data['resource'], 0, 0, 0, 0, self::$destination_width, self::$destination_height, $image_data['width'], $image_data['height']);
|
||||
|
||||
$image_data['resource'] = $image;
|
||||
$image_data['width'] = self::$destination_width;
|
||||
$image_data['height'] = self::$destination_height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Rotate extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function degree($angle, $color = '#000000', $opacity = 100) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$bgcolor = parent::transparency($image_data['resource'], $color, $opacity);
|
||||
|
||||
$image_data['resource'] = imagerotate($image_data['resource'], $angle, $bgcolor, true);
|
||||
|
||||
$image_data['width'] = imagesx($image_data['resource']);
|
||||
$image_data['height'] = imagesy($image_data['resource']);
|
||||
}
|
||||
|
||||
|
||||
public static function landscape() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
if ($image_data['width'] < $image_data['height']) {
|
||||
self::degree(270);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function portrait() {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
if ($image_data['width'] > $image_data['height']) {
|
||||
self::degree(90);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
|
||||
abstract class phImaginator_Write extends phImaginator_Universal implements phImaginator_Module {
|
||||
|
||||
protected static $runCollected = false;
|
||||
|
||||
|
||||
public static function text($text, $position_horizontal, $position_vertical, $rotation = 0) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
self::writeText($image_data, $text, $position_horizontal, $position_vertical, $rotation);
|
||||
}
|
||||
|
||||
|
||||
public static function fileInfo($position_horizontal, $position_vertical) {
|
||||
$image_data =& parent::getCurrentResource();
|
||||
|
||||
$text = $image_data['fileinfo']['basename'] . ' (' . $image_data['width'] . ' x ' . $image_data['height'] . ')';
|
||||
|
||||
self::writeText($image_data, $text, $position_horizontal, $position_vertical);
|
||||
}
|
||||
|
||||
|
||||
private static function writeText(&$image_data, $text, $x, $y, $rotation = 0) {
|
||||
$fontColor = parent::transparency($image_data['resource'], parent::getFontColor(), parent::getFontOpacity());
|
||||
|
||||
$fontSize = parent::getFontSize();
|
||||
$fontFile = parent::getFontFile();
|
||||
|
||||
$tboxSize = imagettfbbox($fontSize, $rotation, $fontFile, $text);
|
||||
|
||||
$textPos = parent::getElementPositions($x, $y, $image_data, abs($tboxSize[4]), abs($tboxSize[5]));
|
||||
|
||||
imagettftext($image_data['resource'], $fontSize, $rotation, $textPos['x'], $textPos['y'] + abs($tboxSize[5]), $fontColor, $fontFile, $text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* R&S Imagination Suite
|
||||
*
|
||||
* blah fasel description
|
||||
*
|
||||
* @author Darius A. Zylka <rs@regen-sonne.de>
|
||||
* @copyright (c) 2009 Darius A. Zylka
|
||||
* @version 1.0
|
||||
* @package phImaginator
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Main class
|
||||
*
|
||||
* @package phImaginator
|
||||
*
|
||||
*/
|
||||
class phImaginator {
|
||||
|
||||
const POSITION_LEFT = 1;
|
||||
const POSITION_CENTER = 2;
|
||||
const POSITION_RIGHT = 4;
|
||||
const POSITION_TOP = 8;
|
||||
const POSITION_MIDDLE = 16;
|
||||
const POSITION_BOTTOM = 32;
|
||||
|
||||
const POSITION_LEFT_TOP = 64;
|
||||
const POSITION_RIGHT_TOP = 128;
|
||||
const POSITION_LEFT_BOTTOM = 256;
|
||||
const POSITION_RIGHT_BOTTOM = 512;
|
||||
|
||||
const POSITION_ALL = 1024;
|
||||
|
||||
const FITTING_WIDTH = 2048;
|
||||
const FITTING_HEIGHT = 4096;
|
||||
const FITTING_BOTH = 8192;
|
||||
|
||||
const TRANSITION_LINEAR = 1;
|
||||
const TRANSITION_LOGARITHMIC = 2;
|
||||
const TRANSITION_EXPONENTIAL = 3;
|
||||
|
||||
/**
|
||||
* An array with all image data like resources, width, height, filename
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $imageSourceCollection = array();
|
||||
|
||||
/**
|
||||
* Incremental counter of all added images
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $resource_counter = 0;
|
||||
|
||||
/**
|
||||
* Holds the additional file name for the generated images
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $nameAppend = false;
|
||||
private $namePrepend = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Includes the module interface and the module parent class
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
require_once 'phImaginator.Module.interface.php';
|
||||
require_once 'phImaginator.Universal.class.php';
|
||||
|
||||
//phImaginator_Universal::setGlobalConstants();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new images resources
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $source An array containing files or directories or a string with a file or directory name
|
||||
*/
|
||||
public function add($source) {
|
||||
if (is_array($source)) {
|
||||
foreach ($source as $source_file) {
|
||||
$this->addSource($source_file);
|
||||
}
|
||||
} else {
|
||||
$this->addSource($source);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given resource is a file or a directory
|
||||
*
|
||||
* @access private
|
||||
* @param string $source A file or directory name
|
||||
*/
|
||||
private function addSource($source) {
|
||||
if (is_file($source)) {
|
||||
$this->addImage($source);
|
||||
} else if (is_dir($source) && $dh = opendir($source)) {
|
||||
$source .= (substr($source, -1, 1) != '/') ? '/' : '';
|
||||
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$sourcefile = $source . $file;
|
||||
|
||||
if (is_file($sourcefile)) {
|
||||
$this->addImage($sourcefile);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an image resource and adds it to the collection
|
||||
*
|
||||
* @access private
|
||||
* @param string $source_file
|
||||
* @uses $imageSourceCollection
|
||||
*/
|
||||
private function addImage($source_file) {
|
||||
list($width, $height, $type) = getimagesize($source_file);
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$resource = imagecreatefromjpeg($source_file);
|
||||
|
||||
break;
|
||||
|
||||
case IMAGETYPE_PNG:
|
||||
$resource = imagecreatefrompng($source_file);
|
||||
imagesavealpha($resource, true);
|
||||
|
||||
break;
|
||||
|
||||
case IMAGETYPE_GIF:
|
||||
$resource = imagecreatefromgif($source_file);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($resource) && is_resource($resource)) {
|
||||
++$this->resource_counter;
|
||||
|
||||
$fileinfo = pathinfo($source_file);
|
||||
|
||||
$this->imageSourceCollection[$this->resource_counter] = array(
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'resource' => $resource,
|
||||
'id' => $this->resource_counter,
|
||||
'type' => $type,
|
||||
'fileinfo' => $fileinfo
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the module class file and calls its desired method
|
||||
*
|
||||
* @access public
|
||||
* @param string $action Name of the class and its desired method
|
||||
* @param array $params Given parameters
|
||||
*/
|
||||
public function __call($action, $params) {
|
||||
$classCall = explode('_', $action);
|
||||
$class = $classCall[0];
|
||||
$method = $classCall[1];
|
||||
|
||||
if (!is_object($this->$class)) {
|
||||
require_once 'phImaginator.' . $class . '.class.php';
|
||||
$className = 'phImaginator_' . $class;
|
||||
}
|
||||
|
||||
if ($className::ifRunCollected()) {
|
||||
$className::assignImageSourceCollection($this->imageSourceCollection);
|
||||
$className::$method($params);
|
||||
} else {
|
||||
if (is_array($this->imageSourceCollection)) {
|
||||
foreach ($this->imageSourceCollection as $id => &$source_data) {
|
||||
// $className::$method($source_data, $params);
|
||||
// $tmp_params = $params;
|
||||
phImaginator_Universal::setCurrentResource($source_data);
|
||||
// array_unshift($params, &$source_data);
|
||||
call_user_func_array(array($className, $method), $params);
|
||||
|
||||
// $params = $tmp_params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an additional name for the generated image files
|
||||
*
|
||||
* @access public
|
||||
* @param string $nameAdd Prefix for the new file name
|
||||
* @uses $nameAdd
|
||||
*/
|
||||
public function nameAdd($namePrepend = false, $nameAppend = false) {
|
||||
$this->nameAppend = $nameAppend;
|
||||
$this->namePrepend = $namePrepend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks through the collection and calls the saving method for each element
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $imagetype One of the Exif Imagetype Constants
|
||||
* @param integer $quality A value between 0 (high compression level, pure quality) and 100 (no compression, best possible quality)
|
||||
* @uses $imageSourceCollection
|
||||
*/
|
||||
public function save($imagetype = false, $quality = 85, $destination = false) {
|
||||
if (is_array($this->imageSourceCollection)) {
|
||||
foreach ($this->imageSourceCollection as $source_data) {
|
||||
$this->saveImage($source_data, $imagetype, $quality, $destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the image to file system
|
||||
*
|
||||
* @access private
|
||||
* @param array $source_data
|
||||
* @param mixed $imagetype One of the Exif Imagetype Constants
|
||||
* @param quality $quality
|
||||
*/
|
||||
private function saveImage($source_data, $imagetype = false, $quality = 85, $destination = false) {
|
||||
$source_data['type'] = (!$imagetype) ? $source_data['type'] : $imagetype;
|
||||
|
||||
$destination = ($destination) ? $destination : $source_data['fileinfo']['dirname'];
|
||||
|
||||
switch ($source_data['type']) {
|
||||
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($source_data['resource'], $destination . DIRECTORY_SEPARATOR . $this->namePrepend . $source_data['fileinfo']['filename'] . $this->nameAppend . '.jpg', $quality);
|
||||
|
||||
break;
|
||||
|
||||
case IMAGETYPE_PNG:
|
||||
imagealphablending($source_data['resource'], false);
|
||||
imagesavealpha($source_data['resource'], true);
|
||||
|
||||
$q = (-$quality + 100) * 0.1;
|
||||
$quality = floor(($q > 9) ? 9 : $q);
|
||||
|
||||
imagepng($source_data['resource'], $destination . DIRECTORY_SEPARATOR . $this->namePrepend . $source_data['fileinfo']['filename'] . $this->nameAppend . '.png', $quality);
|
||||
|
||||
break;
|
||||
|
||||
case IMAGETYPE_GIF:
|
||||
imagegif($source_data['resource'], $destination . DIRECTORY_SEPARATOR . $this->namePrepend . $source_data['fileinfo']['filename'] . $this->nameAppend . '.gif');
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font informations for usage in modules
|
||||
*
|
||||
* @param string $fontFile Path and name to the TTF file
|
||||
* @param integer $size Font size
|
||||
* @param mixed $color An array or hex value for the color (array(R, G, B) or #RRGGBB)
|
||||
* @param integer $lucency An value between 0 and 100 for the lucency of the written text
|
||||
*/
|
||||
public function setFont($fontFile, $size = false, $color = false, $lucency = false) {
|
||||
phImaginator_Universal::setFont($fontFile, $size, $color, $lucency);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user