first commit

This commit is contained in:
2023-09-01 00:37:57 -07:00
commit 9caab8ce68
602 changed files with 33485 additions and 0 deletions

View File

@ -0,0 +1,19 @@
Copyright (c) 2016 Andreas Gohr <andi@splitbrain.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,24 @@
RingIcon - A Indenticon/Glyphicon Library
=========================================
This minimal library generates identifiers based on an input seed. It can be
used to generate avatar images or visualize other identifying info (like
crypto keys). The result is a PNG or SVG image.
It has no dependencies except the GD library extension for PHP for PNG images.
![Multicolor with 3 Rings](sample.png)
![Monochrome with 5 Rings](mono.png)
Usage
-----
See the ``demo.html``/``demo.php`` files for examples.
You can tune the following parameters:
- The size of the resulting image (via constructor)
- The number of rings to generate (via constructor)
- Multicolor versus monochrome image (via ``setMono()`` method)
The monochrome version uses a single color and variates the alpha transparency of the rings.

View File

@ -0,0 +1,69 @@
<?php
namespace Avatar_Privacy\Vendor\splitbrain\RingIcon;
/**
* Class RingIcon
*
* Generates a identicon/visiglyph like image based on concentric rings
*
* @author Andreas Gohr <andi@splitbrain.org>
* @license MIT
* @package splitbrain\RingIcon
*/
abstract class AbstractRingIcon
{
protected $size;
protected $fullsize;
protected $rings;
protected $center;
protected $ringwidth;
protected $seed;
protected $ismono = \false;
protected $monocolor = null;
/**
* RingIcon constructor.
* @param int $size width and height of the resulting image
* @param int $rings number of rings
*/
public function __construct($size, $rings = 3)
{
$this->size = $size;
$this->fullsize = $this->size * 5;
$this->rings = $rings;
$this->center = \floor($this->fullsize / 2);
$this->ringwidth = \floor($this->fullsize / $rings);
$this->seed = \mt_rand() . \time();
}
/**
* When set to true a monochrome version is returned
*
* @param bool $ismono
*/
public function setMono($ismono)
{
$this->ismono = $ismono;
}
/**
* Generate number from seed
*
* Each call runs MD5 on the seed again
*
* @param int $min
* @param int $max
* @return int
*/
protected function rand($min, $max)
{
$this->seed = \md5($this->seed);
$rand = \hexdec(\substr($this->seed, 0, 8));
return $rand % ($max - $min + 1) + $min;
}
/**
* Set a fixed color, which to be later only varied within its alpha channel
*/
protected function generateMonoColor()
{
$this->monocolor = array($this->rand(20, 255), $this->rand(20, 255), $this->rand(20, 255));
}
}

View File

@ -0,0 +1,145 @@
<?php
namespace Avatar_Privacy\Vendor\splitbrain\RingIcon;
class RingIconSVG extends AbstractRingIcon
{
public function __construct($size, $rings = 3)
{
parent::__construct($size, $rings);
// we don't downscale
$this->center = \floor($this->size / 2);
$this->ringwidth = \floor($this->size / $rings);
}
/**
* Generates an ring image svg suitable for inlining in html
*
* If a seed is given, the image will be based on that seed
*
* @param string $seed
*
* @return string
*/
public function getInlineSVG($seed = '')
{
return $this->generateSVGImage($seed);
}
/**
* Generates an ring image svg
*
* If a seed is given, the image will be based on that seed
*
* @param string $seed initialize the genrator with this string
* @param string $file if given, the image is saved at that path, otherwise is printed as file to browser
*/
public function createImage($seed = '', $file = '')
{
$svg = $this->generateSVGImage($seed, \true);
if ($file) {
\file_put_contents($file, $svg);
} else {
\header("Content-type: image/svg+xml");
echo $svg;
}
}
/**
* Generates an ring image svg
*
* If a seed is given, the image will be based on that seed
*
* @param string $seed initialize the genrator with this string
* @param bool $file if true, the svg will have the markup suitable for being delivered as file
*
* @return string
*/
protected function generateSVGImage($seed = '', $file = \false)
{
if (!$seed) {
$seed = \mt_rand() . \time();
}
$this->seed = $seed;
// monochrome wanted?
if ($this->ismono) {
$this->generateMonoColor();
}
if ($file) {
$svgFileAttributes = array('xmlns' => 'http://www.w3.org/2000/svg', 'version' => '1.1', 'width' => $this->size, 'height' => $this->size);
$svgFileAttributes = \implode(' ', \array_map(function ($k, $v) {
return $k . '="' . \htmlspecialchars($v) . '"';
}, \array_keys($svgFileAttributes), $svgFileAttributes));
} else {
$svgFileAttributes = '';
}
$svg = "<svg {$svgFileAttributes} viewBox=\"0 0 {$this->size} {$this->size}\">";
$arcOuterRadious = $this->size / 2;
for ($i = $this->rings; $i > 0; $i--) {
$svg .= $this->createSVGArcPath($arcOuterRadious);
$arcOuterRadious -= $this->ringwidth / 2;
}
$svg .= '</svg>';
if ($file) {
$svgBoilerplate = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
$svg = $svgBoilerplate . $svg;
}
return $svg;
}
/**
* Draw a single arc
*
* @param float $outerRadius
*
* @return string
*/
protected function createSVGArcPath($outerRadius)
{
$color = $this->randomCssColor();
$ringThickness = $this->ringwidth / 2;
$startAngle = $this->rand(20, 360);
$stopAngle = $this->rand(20, 360);
if ($stopAngle < $startAngle) {
list($startAngle, $stopAngle) = array($stopAngle, $startAngle);
}
list($xStart, $yStart) = $this->polarToCartesian($outerRadius, $startAngle);
list($xOuterEnd, $yOuterEnd) = $this->polarToCartesian($outerRadius, $stopAngle);
$innerRadius = $outerRadius - $ringThickness;
$SweepFlag = 0;
$innerSweepFlag = 1;
$largeArcFlag = (int) ($stopAngle - $startAngle < 180);
list($xInnerStart, $yInnerStart) = $this->polarToCartesian($outerRadius - $ringThickness, $stopAngle);
list($xInnerEnd, $yInnerEnd) = $this->polarToCartesian($outerRadius - $ringThickness, $startAngle);
$fullPath = "<path fill='{$color}' d='\n M {$xStart} {$yStart}\n A {$outerRadius} {$outerRadius} 0 {$largeArcFlag} {$SweepFlag} {$xOuterEnd} {$yOuterEnd}\n L {$xInnerStart} {$yInnerStart}\n A {$innerRadius} {$innerRadius} 0 {$largeArcFlag} {$innerSweepFlag} {$xInnerEnd} {$yInnerEnd}\n Z\n '/>";
return $fullPath;
}
/**
* Create a random valid css color value
*
* @return string
*/
protected function randomCssColor()
{
if ($this->ismono) {
$alpha = 1 - $this->rand(0, 96) / 100;
return "rgba({$this->monocolor[0]}, {$this->monocolor[1]}, {$this->monocolor[2]}, {$alpha})";
}
$r = $this->rand(0, 255);
$g = $this->rand(0, 255);
$b = $this->rand(0, 255);
return "rgb({$r}, {$g}, {$b})";
}
/**
* Calculate the x,y coordinate of a given angle at a given distance from the center
*
* 0 Degree is 3 o'clock
*
* @param float $radius
* @param float $angleInDegrees
*
* @return array
*/
protected function polarToCartesian($radius, $angleInDegrees)
{
$angleInRadians = $angleInDegrees * \M_PI / 180.0;
return array($this->size / 2 + $radius * \cos($angleInRadians), $this->size / 2 + $radius * \sin($angleInRadians));
}
}