Bird Avatar Generator
|
@ -0,0 +1,14 @@
|
||||||
|
# Bird Avatar Generator
|
||||||
|
|
||||||
|
Generate a default avatar based on David Revoy's bird-avatar-generator https://www.peppercarrot.com/extras/html/2019_bird-generator/index.php
|
||||||
|
|
||||||
|
## 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 pictures used as Avatar
|
||||||
|
(for blog,forum,social-network) don't need direct attribution and so, can be used
|
||||||
|
|
||||||
|
**Original code**
|
||||||
|
Original PHP code is licensed under the short and simple permissive:
|
||||||
|
[MIT License](https://en.wikipedia.org/wiki/MIT_License)
|
After Width: | Height: | Size: 734 B |
After Width: | Height: | Size: 6.5 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 734 B |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 734 B |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 392 B |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 5.4 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 9.2 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 9.7 KiB |
|
@ -0,0 +1,266 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Name: Bird Avatar Generator
|
||||||
|
* Description: Generate a default avatar based on David Revoy's bird-avatar-generator https://www.peppercarrot.com/extras/html/2019_bird-generator/index.php
|
||||||
|
* Version: 1.0
|
||||||
|
* Author: Fabio <https://kirgroup.com/profile/fabrixxm>
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\Core\Logger;
|
||||||
|
use Friendica\Core\Renderer;
|
||||||
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\DI;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\Photo;
|
||||||
|
use Friendica\Model\Profile;
|
||||||
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
|
||||||
|
define("BIRDAVATAR_SIZE", 256);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the addon hook
|
||||||
|
*/
|
||||||
|
function birdavatar_install()
|
||||||
|
{
|
||||||
|
Hook::register('avatar_lookup', 'addon/birdavatar/birdavatar.php', 'birdavatar_lookup');
|
||||||
|
Hook::register('addon_settings', 'addon/birdavatar/birdavatar.php', 'birdavatar_addon_settings');
|
||||||
|
Hook::register('addon_settings_post', 'addon/birdavatar/birdavatar.php', 'birdavatar_addon_settings_post');
|
||||||
|
|
||||||
|
Logger::log('registered birdavatar');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bird avatar user settings page
|
||||||
|
*/
|
||||||
|
function birdavatar_addon_settings(App $a, &$s)
|
||||||
|
{
|
||||||
|
if (!local_user()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/birdavatar/');
|
||||||
|
$s .= Renderer::replaceMacros($t, [
|
||||||
|
'$postpost' => !empty($_POST['birdavatar-morebird']) || !empty($_POST['birdavatar-emailbird']),
|
||||||
|
'$uncache' => time(),
|
||||||
|
'$uid' => local_user(),
|
||||||
|
'$usebird' => DI::l10n()->t('Use Bird as Avatar'),
|
||||||
|
'$morebird' => DI::l10n()->t('More Random Bird!'),
|
||||||
|
'$emailbird' => DI::l10n()->t('Reset to email Bird'),
|
||||||
|
'$seed' => DI::pConfig()->get(local_user(), 'birdavatar', 'seed', false),
|
||||||
|
'$header' => DI::l10n()->t('Bird Avatar Settings'),
|
||||||
|
'$setrandomize' => DI::l10n()->t('Set default profile avatar or randomize the bird.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bird avatar user settings POST handle
|
||||||
|
*/
|
||||||
|
function birdavatar_addon_settings_post(App $a, &$s)
|
||||||
|
{
|
||||||
|
if (!local_user()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['birdavatar-usebird'])) {
|
||||||
|
$url = DI::baseUrl()->get() . '/birdavatar/' . local_user() . '?ts=' . time();
|
||||||
|
|
||||||
|
$self = DBA::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]);
|
||||||
|
if (!DBA::isResult($self)) {
|
||||||
|
notice(DI::l10n()->t("The bird has not found itself."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Photo::importProfilePhoto($url, local_user(), $self['id']);
|
||||||
|
|
||||||
|
$condition = ['uid' => local_user(), 'contact-id' => $self['id']];
|
||||||
|
$photo = DBA::selectFirst('photo', ['resource-id'], $condition);
|
||||||
|
if (!DBA::isResult($photo)) {
|
||||||
|
notice(DI::l10n()->t('There was an error, the bird flew away.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DBA::update('photo', ['profile' => false], ['profile' => true, 'uid' => local_user()]);
|
||||||
|
|
||||||
|
$fields = ['profile' => true, 'album' => DI::l10n()->t('Profile Photos'), 'contact-id' => 0];
|
||||||
|
DBA::update('photo', $fields, ['uid' => local_user(), 'resource-id' => $photo['resource-id']]);
|
||||||
|
|
||||||
|
Photo::importProfilePhoto($url, local_user(), $self['id']);
|
||||||
|
|
||||||
|
Contact::updateSelfFromUserID(local_user(), true);
|
||||||
|
|
||||||
|
// Update global directory in background
|
||||||
|
Profile::publishUpdate(local_user());
|
||||||
|
|
||||||
|
info(DI::l10n()->t('Meow!'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['birdavatar-morebird'])) {
|
||||||
|
DI::pConfig()->set(local_user(), 'birdavatar', 'seed', time());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['birdavatar-emailbird'])) {
|
||||||
|
DI::pConfig()->delete(local_user(), 'birdavatar', 'seed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the URL to the bird avatar
|
||||||
|
*
|
||||||
|
* @param $a array
|
||||||
|
* @param &$b array
|
||||||
|
*/
|
||||||
|
function birdavatar_lookup(App $a, &$b)
|
||||||
|
{
|
||||||
|
$user = DBA::selectFirst('user', ['uid'], ['email' => $b['email']]);
|
||||||
|
if (DBA::isResult($user)) {
|
||||||
|
$url = DI::baseUrl()->get() . '/birdavatar/' . $user['uid'];
|
||||||
|
} else {
|
||||||
|
$url = DI::baseUrl()->get() . '/birdavatar/' . md5(trim(strtolower($b['email'])));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($b['size']) {
|
||||||
|
case 300: $url .= "/4"; break;
|
||||||
|
case 80: $url .= "/5"; break;
|
||||||
|
case 48: $url .= "/6"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$b['url'] = $url;
|
||||||
|
$b['success'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function birdavatar_module()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns image for user id
|
||||||
|
*
|
||||||
|
* @throws NotFoundException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function birdavatar_content(App $a)
|
||||||
|
{
|
||||||
|
if (DI::args()->getArgc() < 2 || DI::args()->getArgc() > 3) {
|
||||||
|
throw new NotFoundException(); // this should be catched on index and show default "not found" page.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric(DI::args()->getArgv()[1])) {
|
||||||
|
$uid = intval(DI::args()->getArgv()[1]);
|
||||||
|
$condition = ['uid' => $uid,
|
||||||
|
'account_expired' => false, 'account_removed' => false];
|
||||||
|
$user = DBA::selectFirst('user', ['email'], $condition);
|
||||||
|
|
||||||
|
if ($user === false) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$seed = DI::pConfig()->get($uid, "birdavatar", "seed", md5(trim(strtolower($user['email']))));
|
||||||
|
} elseif (!empty(DI::args()->getArgv()[1])) {
|
||||||
|
$seed = DI::args()->getArgv()[1];
|
||||||
|
} else {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = 0;
|
||||||
|
if (DI::args()->getArgc() == 3) {
|
||||||
|
$size = intval(DI::args()->getArgv()[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// start generation
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// render the picture:
|
||||||
|
build_bird($seed, $size);
|
||||||
|
|
||||||
|
ob_end_flush();
|
||||||
|
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ====================
|
||||||
|
* 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)
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
function build_bird($seed = '', $size = 0)
|
||||||
|
{
|
||||||
|
// init random seed
|
||||||
|
if ($seed) {
|
||||||
|
srand(hexdec(substr(md5($seed), 0, 6)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// throw the dice for body parts
|
||||||
|
$parts = [
|
||||||
|
'tail' => rand(1,9),
|
||||||
|
'hoop' => rand(1,10),
|
||||||
|
'body' => rand(1,9),
|
||||||
|
'wing' => rand(1,9),
|
||||||
|
'eyes' => rand(1,9),
|
||||||
|
'bec' => rand(1,9),
|
||||||
|
'accessorie' => rand(1,20)
|
||||||
|
];
|
||||||
|
|
||||||
|
// create backgound
|
||||||
|
$bird = @imagecreatetruecolor(BIRDAVATAR_SIZE, BIRDAVATAR_SIZE)
|
||||||
|
or die("GD image create failed");
|
||||||
|
$white = imagecolorallocate($bird, 255, 255, 255);
|
||||||
|
imagefill($bird, 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($bird, $im, 0, 0, 0, 0, BIRDAVATAR_SIZE, BIRDAVATAR_SIZE);
|
||||||
|
imagedestroy($im);
|
||||||
|
}
|
||||||
|
|
||||||
|
// scale image
|
||||||
|
if ($size > 3 && $size < 7) {
|
||||||
|
switch ($size) {
|
||||||
|
case 4:
|
||||||
|
$size = 300;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$size = 80;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
$size = 48;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dest = imagecreatetruecolor($size, $size) or die("GD image create failed");
|
||||||
|
imagealphablending($dest, false);
|
||||||
|
imagesavealpha($dest, true);
|
||||||
|
imagecopyresampled($dest, $bird, 0, 0, 0, 0, $size, $size, BIRDAVATAR_SIZE, BIRDAVATAR_SIZE);
|
||||||
|
imagedestroy($bird);
|
||||||
|
$bird = $dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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($bird, null, 90);
|
||||||
|
imagedestroy($bird);
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
# ADDON birdavatar
|
||||||
|
# Copyright (C)
|
||||||
|
# This file is distributed under the same license as the Friendica birdavatar addon package.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#, fuzzy
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: \n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2021-11-24 12:04+0100\n"
|
||||||
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"Language: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
#: birdavatar.php:49
|
||||||
|
msgid "Use Bird as Avatar"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:50
|
||||||
|
msgid "More Random Bird!"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:51
|
||||||
|
msgid "Reset to email Bird"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:53
|
||||||
|
msgid "Bird Avatar Settings"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:54
|
||||||
|
msgid "Set default profile avatar or randomize the bird."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:72
|
||||||
|
msgid "The bird has not found itself."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:81
|
||||||
|
msgid "There was an error, the bird flew away."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:87
|
||||||
|
msgid "Profile Photos"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: birdavatar.php:97
|
||||||
|
msgid "Meow!"
|
||||||
|
msgstr ""
|
|
@ -0,0 +1,24 @@
|
||||||
|
<span id="settings_birdavatar_inflated" class="settings-block fakelink"
|
||||||
|
style="{{if $postpost}}display: none;{{else}}display: block;{{/if}}"
|
||||||
|
onclick="openClose('settings_birdavatar_expanded'); openClose('settings_birdavatar_inflated');">
|
||||||
|
<h3>{{$header}}</h3>
|
||||||
|
</span>
|
||||||
|
<div id="settings_birdavatar_expanded" class="settings-block"
|
||||||
|
style="{{if $postpost}}display: block;{{else}}display: none;{{/if}}">
|
||||||
|
<span class="fakelink" onclick="openClose('settings_birdavatar_expanded'); openClose('settings_birdavatar_inflated');">
|
||||||
|
<h3>{{$header}}</h3>
|
||||||
|
</span>
|
||||||
|
<img src="{{$basepath}}/birdavatar/{{$uid}}?{{$uncache}}">
|
||||||
|
<p>{{$setrandomize}}</p>
|
||||||
|
<div class="settings-submit-wrapper" >
|
||||||
|
<button type="submit" name="birdavatar-usebird"
|
||||||
|
class="btn btn-primary settings-submit" value="{{$usebird}}">{{$usebird}}</button>
|
||||||
|
|
||||||
|
<div class="btn-group" role="group" aria-label="...">
|
||||||
|
<button type="submit" name="birdavatar-morebird"
|
||||||
|
class="btn btn-default settings-submit" value="{{$morebird}}">{{$morebird}}</button>
|
||||||
|
<button type="submit" name="birdavatar-emailbird" {{if !$seed}}disabled{{/if}}
|
||||||
|
class="btn btn-default settings-submit" value="{{$emailbird}}">{{$emailbird}}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|