105 lines
2.9 KiB
PHP
105 lines
2.9 KiB
PHP
<?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;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|