Browse Source

add NS favicons

pull/7/head
ghost 3 years ago
parent
commit
c04689a33d
  1. 19
      library/icon.php
  2. 13
      public/image.php
  3. 1
      public/index.phtml

19
library/icon.php

@ -10,7 +10,7 @@ final class Icon {
private $_spriteZ = 800; private $_spriteZ = 800;
public function generateImageResource($hash, $width, $height, $filter = false) { public function generateImageResource($hash, $width, $height, $filter = false, $radius = 0) {
$this->_width = $width; $this->_width = $width;
$this->_height = $height; $this->_height = $height;
@ -74,12 +74,25 @@ final class Icon {
imagecopyresampled($resized, $identicon, 0, 0, (imagesx($identicon) - $this->_spriteZ * 3) / 2, (imagesx($identicon) - $this->_spriteZ * 3) / 2, $this->_width, $this->_height, $this->_spriteZ * 3, $this->_spriteZ * 3); imagecopyresampled($resized, $identicon, 0, 0, (imagesx($identicon) - $this->_spriteZ * 3) / 2, (imagesx($identicon) - $this->_spriteZ * 3) / 2, $this->_width, $this->_height, $this->_spriteZ * 3, $this->_spriteZ * 3);
imagecolortransparent($resized, $bg);
if ($filter) { if ($filter) {
imagefilter($resized, $filter); imagefilter($resized, $filter);
} }
if ($radius) {
imagearc($resized, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $bg);
imagefilltoborder($resized, 0, 0, $bg, $bg);
imagearc($resized, $width-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $bg);
imagefilltoborder($resized, $width-1, 0, $bg, $bg);
imagearc($resized, $radius-1, $height-$radius, $radius*2, $radius*2, 90, 180, $bg);
imagefilltoborder($resized, 0, $height-1, $bg, $bg);
imagearc($resized, $width-$radius, $height-$radius, $radius*2, $radius*2, 0, 90, $bg);
imagefilltoborder($resized, $width-1, $height-1, $bg, $bg);
imagecolortransparent($resized, $bg);
}
ob_start(); ob_start();
imagepng($resized); imagepng($resized);
imagedestroy($resized); imagedestroy($resized);

13
public/image.php

@ -5,17 +5,24 @@ require_once('../library/icon.php');
if (isset($_GET['hash'])) { if (isset($_GET['hash'])) {
$hash = md5($_GET['hash']);
$width = isset($_GET['width']) ? (int) $_GET['width'] : 60;
$height = isset($_GET['height']) ? (int) $_GET['height'] : 60;
$radius = isset($_GET['radius']) ? (int) $_GET['radius'] : 0;
header("Content-Type: image/png"); header("Content-Type: image/png");
if (CACHE_ENABLED) { if (CACHE_ENABLED) {
$filename = dirname(__FILE__) . '/../cache/' . $_GET['hash'] . '.png'; $filename = dirname(__FILE__) . '/../cache/' . $hash . '.png';
if (!file_exists($filename)) { if (!file_exists($filename)) {
$icon = new Icon(); $icon = new Icon();
file_put_contents($filename, $icon->generateImageResource(md5($_GET['hash']), 60, 60, false)); file_put_contents($filename, $icon->generateImageResource($hash, $width, $height, false, $radius));
} }
echo file_get_contents($filename); echo file_get_contents($filename);
@ -24,6 +31,6 @@ if (isset($_GET['hash'])) {
$icon = new Icon(); $icon = new Icon();
echo $icon->generateImageResource(md5($_GET['hash']), 60, 60, false); echo $icon->generateImageResource($hash, $width, $height, false, $radius);
} }
} }

1
public/index.phtml

@ -6,6 +6,7 @@
<meta name="description" content="Open Source Content Exploring Platform for Kevacoin Blockchain" /> <meta name="description" content="Open Source Content Exploring Platform for Kevacoin Blockchain" />
<base href="<?php echo BASE_URL; ?>" /> <base href="<?php echo BASE_URL; ?>" />
<?php if ($ns) { ?> <?php if ($ns) { ?>
<link rel="icon" type="image/png" href="image.php?hash=<?php echo $ns; ?>&width=32&height=32&radius=16" />
<?php if ($page) { ?> <?php if ($page) { ?>
<title><?php echo $namespaceValue ? $namespaceValue : $ns; ?> | PART <?php echo $page; ?> | KVAZAR</title> <title><?php echo $namespaceValue ? $namespaceValue : $ns; ?> | PART <?php echo $page; ?> | KVAZAR</title>
<meta name="robots" content="noindex,follow" /> <meta name="robots" content="noindex,follow" />

Loading…
Cancel
Save