Commit ad446b1e authored by Zot's avatar Zot

add the cat-avatar plugin even though the generated avatars look like crap at...

add the cat-avatar plugin even though the generated avatars look like crap at 300px. Perhaps this will motivate somebody to come up with something better.
parent 2523f50a
Cat-Avatar-Generator
====================
![cover picture](http://www.peppercarrot.com/data/images/lab/2016-11-30_cdn/2016-11-29_the-quest-to-free-peppercarrot-website_02a-avatar.jpg)
A generator of cats pictures optimised to generate or random avatars, or defined avatar from a "seed". A derivation by [David Revoy](http://www.peppercarrot.com) from the original [MonsterID by Andreas Gohr's](https://www.splitbrain.org/blog/2007-01/20_monsterid_as_gravatar_fallback).
## License:
**Artworks:**
PNG and ORA files licensed under: [CC-By 4.0](https://creativecommons.org/licenses/by/4.0/) attribution: David Revoy with the following exception: Generated cats used as Avatar (for blog,forum,social-network) don't need direct attribution and so, can be used as regular avatars without pasting David Revoy's name all over the place.
**Code**
This PHP is licensed under the short and simple permissive:
[MIT License](https://en.wikipedia.org/wiki/MIT_License)
## Usage:
Call the script this way:
```
echo '<img height="70px" width="70px" src="your/path/to/cat-avatar-generator?seed='.$var.'"/>';
```
_(Note: for the seed, I advice to use author's name to not expose email or sensitive datas, even hashed on a public code.)_
## How to edit artworks
1. Open img/00_SRC.ora with Krita ( or Gimp,Mypaint,Pinta) Do your edit/draw/paint, respect layer naming, save.
2. Open it again in Gimp 2.8, with the [export layer plugin](https://github.com/khalim19/gimp-plugin-export-layers/releases/download/2.4/export-layers-2.4.zip)
3. Scale the image down to the result you want (eg. 256px x 256px as on the demo ) LancZos filter
3. File > Export layer (Allow invisible layer to be exported, check 'image size', PNG file format )
4. Done.
All PNG files of 'parts' are extracted this way and keep their layer name.
a temp folder for cached avatar generation
<?php
/**
* ====================
* CAT-AVATAR-GENERATOR
* ====================
*
* @authors: Andreas Gohr, David Revoy
*
* This PHP is licensed under the short and simple permissive:
* [MIT License](https://en.wikipedia.org/wiki/MIT_License)
*
**/
// /!\ change the path to your system's cache or a folder(write permission)
// Note: this path end with / and is relative to the cat-avatar-generator.php file.
$cachepath = 'cache/';
function build_cat($seed=''){
// init random seed
if($seed) srand( hexdec(substr(md5($seed),0,6)) );
// throw the dice for body parts
$parts = array(
'body' => rand(1,15),
'fur' => rand(1,10),
'eyes' => rand(1,15),
'mouth' => rand(1,10),
'accessorie' => rand(1,20)
);
// create backgound
$cat = @imagecreatetruecolor(70, 70)
or die("GD image create failed");
$white = imagecolorallocate($cat, 255, 255, 255);
imagefill($cat,0,0,$white);
// add parts
foreach($parts as $part => $num){
$file = dirname(__FILE__).'/avatars/'.$part.'_'.$num.'.png';
$im = @imagecreatefrompng($file);
if(!$im) die('Failed to load '.$file);
imageSaveAlpha($im, true);
imagecopy($cat,$im,0,0,0,0,70,70);
imagedestroy($im);
}
// restore random seed
if($seed) srand();
header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/jpg');
imagejpeg($cat, NULL, 90);
imagedestroy($cat);
}
/*
we will call build_cat() directly and avoid caching
$imageurl = $_GET["seed"];
$imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $imageurl);
$imageurl = substr($imageurl,0,35).'';
$cachefile = ''.$cachepath.''.$imageurl.'.jpg';
$cachetime = 604800; # 1 week (1 day = 86400)
// Serve from the cache if it is younger than $cachetime
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
header('Content-Type: image/jpg');
readfile($cachefile);
exit;
}
// ...Or start generation
ob_start();
// render the picture:
build_cat($_REQUEST['seed']);
// Save/cache the output to a file
$savedfile = fopen($cachefile, 'w+'); # w+ to be at start of the file, write mode, and attempt to create if not existing.
fwrite($savedfile, ob_get_contents());
fclose($savedfile);
chmod($savedfile, 0755);
ob_end_flush();
*/
<?php
/**
* Name: cavatar
* Description: create cat-avatar for default profile photo
*
*/
function cavatar_load() {
\Zotlabs\Extend\Hook::register('create_channel_photo', 'addon/cavatar/cavatar.php', 'cavatar_channel_photo');
}
function cavatar_unload() {
\Zotlabs\Extend\Hook::unregister('create_channel_photo', 'addon/cavatar/cavatar.php', 'cavatar_channel_photo');
}
function cavatar_channel_photo(&$x) {
$x['photo_url'] = z_root() . '/cavatar?f=&seed=' . notags($x['channel']['channel_address']) ;
}
function cavatar_module() {}
function cavatar_init(&$a) {
require_once('addon/cavatar/cat-avatar-generator.php');
build_cat($_REQUEST['seed']);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment