|
|
@@ -13,8 +13,6 @@
|
|
|
|
|
|
namespace PrivateBin;
|
|
|
|
|
|
-use PrivateBin\Persistence\ServerSalt;
|
|
|
-
|
|
|
/**
|
|
|
* Vizhash16x16
|
|
|
*
|
|
|
@@ -60,14 +58,6 @@ class Vizhash16x16
|
|
|
*/
|
|
|
private $height;
|
|
|
|
|
|
- /**
|
|
|
- * salt used when generating the image
|
|
|
- *
|
|
|
- * @access private
|
|
|
- * @var string
|
|
|
- */
|
|
|
- private $salt;
|
|
|
-
|
|
|
/**
|
|
|
* constructor
|
|
|
*
|
|
|
@@ -78,12 +68,13 @@ class Vizhash16x16
|
|
|
{
|
|
|
$this->width = 16;
|
|
|
$this->height = 16;
|
|
|
- $this->salt = ServerSalt::get();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Generate a 16x16 png corresponding to $text.
|
|
|
*
|
|
|
+ * The given text should to be 128 to 150 characters long
|
|
|
+ *
|
|
|
* @access public
|
|
|
* @param string $text
|
|
|
* @return string PNG data. Or empty string if GD is not available.
|
|
|
@@ -94,44 +85,35 @@ class Vizhash16x16
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
- // We hash the input string.
|
|
|
- $hash=hash('sha1', $text.$this->salt).hash('md5', $text.$this->salt);
|
|
|
- $hash=$hash.strrev($hash); # more data to make graphics
|
|
|
- $hashlen=strlen($hash);
|
|
|
+ $textlen=strlen($text);
|
|
|
|
|
|
// We convert the hash into an array of integers.
|
|
|
- $this->VALUES=array();
|
|
|
- for ($i=0; $i<$hashlen; $i=$i+2) {
|
|
|
- array_push($this->VALUES, hexdec(substr($hash, $i, 2)));
|
|
|
+ $this->VALUES = array();
|
|
|
+ for ($i = 0; $i < $textlen; $i = $i + 2) {
|
|
|
+ array_push($this->VALUES, hexdec(substr($text, $i, 2)));
|
|
|
}
|
|
|
- $this->VALUES_INDEX=0; // to walk the array.
|
|
|
+ $this->VALUES_INDEX = 0; // to walk the array.
|
|
|
|
|
|
// Then use these integers to drive the creation of an image.
|
|
|
$image = imagecreatetruecolor($this->width, $this->height);
|
|
|
|
|
|
- $r0 = $this->getInt();
|
|
|
- $r=$r0;
|
|
|
- $g0 = $this->getInt();
|
|
|
- $g=$g0;
|
|
|
- $b0 = $this->getInt();
|
|
|
- $b=$b0;
|
|
|
+ $r = $r0 = $this->getInt();
|
|
|
+ $g = $g0 = $this->getInt();
|
|
|
+ $b = $b0 = $this->getInt();
|
|
|
|
|
|
// First, create an image with a specific gradient background.
|
|
|
- $op='v';
|
|
|
- if (($this->getInt()%2)==0) {
|
|
|
- $op='h';
|
|
|
+ $op = 'v';
|
|
|
+ if (($this->getInt() % 2) == 0) {
|
|
|
+ $op = 'h';
|
|
|
};
|
|
|
$image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0));
|
|
|
|
|
|
- for ($i=0; $i<7; $i=$i+1) {
|
|
|
- $action=$this->getInt();
|
|
|
+ for ($i = 0; $i < 7; ++$i) {
|
|
|
+ $action = $this->getInt();
|
|
|
$color = imagecolorallocate($image, $r, $g, $b);
|
|
|
- $r = ($r0 + $this->getInt()/25)%256;
|
|
|
- $g = ($g0 + $this->getInt()/25)%256;
|
|
|
- $b = ($b0 + $this->getInt()/25)%256;
|
|
|
- $r0=$r;
|
|
|
- $g0=$g;
|
|
|
- $b0=$b;
|
|
|
+ $r = $r0 = ($r0 + $this->getInt() / 25) % 256;
|
|
|
+ $g = $g0 = ($g0 + $this->getInt() / 25) % 256;
|
|
|
+ $b = $b0 = ($b0 + $this->getInt() / 25) % 256;
|
|
|
$this->drawshape($image, $action, $color);
|
|
|
}
|
|
|
|
|
|
@@ -154,8 +136,8 @@ class Vizhash16x16
|
|
|
*/
|
|
|
private function getInt()
|
|
|
{
|
|
|
- $v= $this->VALUES[$this->VALUES_INDEX];
|
|
|
- $this->VALUES_INDEX++;
|
|
|
+ $v = $this->VALUES[$this->VALUES_INDEX];
|
|
|
+ ++$this->VALUES_INDEX;
|
|
|
$this->VALUES_INDEX %= count($this->VALUES); // Warp around the array
|
|
|
return $v;
|
|
|
}
|
|
|
@@ -168,7 +150,7 @@ class Vizhash16x16
|
|
|
*/
|
|
|
private function getX()
|
|
|
{
|
|
|
- return $this->width*$this->getInt()/256;
|
|
|
+ return $this->width * $this->getInt() / 256;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -179,7 +161,7 @@ class Vizhash16x16
|
|
|
*/
|
|
|
private function getY()
|
|
|
{
|
|
|
- return $this->height*$this->getInt()/256;
|
|
|
+ return $this->height * $this->getInt() / 256;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -197,7 +179,7 @@ class Vizhash16x16
|
|
|
*/
|
|
|
private function degrade($img, $direction, $color1, $color2)
|
|
|
{
|
|
|
- if ($direction=='h') {
|
|
|
+ if ($direction == 'h') {
|
|
|
$size = imagesx($img);
|
|
|
$sizeinv = imagesy($img);
|
|
|
} else {
|
|
|
@@ -205,15 +187,15 @@ class Vizhash16x16
|
|
|
$sizeinv = imagesx($img);
|
|
|
}
|
|
|
$diffs = array(
|
|
|
- (($color2[0]-$color1[0])/$size),
|
|
|
- (($color2[1]-$color1[1])/$size),
|
|
|
- (($color2[2]-$color1[2])/$size)
|
|
|
- );
|
|
|
- for ($i=0;$i<$size;$i++) {
|
|
|
- $r = $color1[0]+($diffs[0]*$i);
|
|
|
- $g = $color1[1]+($diffs[1]*$i);
|
|
|
- $b = $color1[2]+($diffs[2]*$i);
|
|
|
- if ($direction=='h') {
|
|
|
+ (($color2[0] - $color1[0]) / $size),
|
|
|
+ (($color2[1] - $color1[1]) / $size),
|
|
|
+ (($color2[2] - $color1[2]) / $size)
|
|
|
+ );
|
|
|
+ for ($i = 0; $i < $size; ++$i) {
|
|
|
+ $r = $color1[0] + ($diffs[0] * $i);
|
|
|
+ $g = $color1[1] + ($diffs[1] * $i);
|
|
|
+ $b = $color1[2] + ($diffs[2] * $i);
|
|
|
+ if ($direction == 'h') {
|
|
|
imageline($img, $i, 0, $i, $sizeinv, imagecolorallocate($img, $r, $g, $b));
|
|
|
} else {
|
|
|
imageline($img, 0, $i, $sizeinv, $i, imagecolorallocate($img, $r, $g, $b));
|
|
|
@@ -233,7 +215,7 @@ class Vizhash16x16
|
|
|
*/
|
|
|
private function drawshape($image, $action, $color)
|
|
|
{
|
|
|
- switch ($action%7) {
|
|
|
+ switch ($action % 7) {
|
|
|
case 0:
|
|
|
ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
|
|
|
break;
|
|
|
@@ -246,7 +228,8 @@ class Vizhash16x16
|
|
|
ImageFilledPolygon($image, $points, 4, $color);
|
|
|
break;
|
|
|
default:
|
|
|
- $start=$this->getInt()*360/256; $end=$start+$this->getInt()*180/256;
|
|
|
+ $start = $this->getInt() * 360 /256;
|
|
|
+ $end = $start + $this->getInt() * 180 / 256;
|
|
|
ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
|
|
|
}
|
|
|
}
|