良いphp自動アバター生成はありますか? WP_MonsterIDやWP_Identiconのようなものはかなり見てきましたが、すべてのワードプレス プラグインがあります。
2772 次
4 に答える
4
Gravatarのようなものを使用できます。メール アドレスをハッシュし、アバターを変更するには gravatar.com にアクセスして変更することをユーザーに知らせるだけです。
たとえば、64 ピクセルの画像を作成するには
<?
$email = "my@whatever.com";
$hash = md5(strtolower(trim($email)));
echo "<img src='http://gravatar.com/avatar/$hash?size=64&d=identicon' />
?>
これに関する詳細なドキュメントは、https ://en.gravatar.com/site/implement/images/ でご覧いただけます。
于 2012-09-30T08:27:08.567 に答える
2
wavatar wordpress プラグインをカスタマイズしました。カスタマイズした wavaters.php ファイルの内容:
//wavaters.php
define("AVATAR_SIZE", '100');
define("WAVATAR_BACKGROUNDS", '4');
define("WAVATAR_FACES", '11');
define("WAVATAR_BROWS", '8');
define("WAVATAR_EYES", '13');
define("WAVATAR_PUPILS", '11');
define("WAVATAR_MOUTHS", '19');
/*-----------------------------------------------------------------------------
Clamp a value between 0 and 255
-----------------------------------------------------------------------------*/
function wavatar_clamp ($v)
{
return $v < 0 ? 0 : ($v > 255 ? 255 : $v);
}
/*-----------------------------------------------------------------------------
Handy function for converting hus/sat/lum color values to RGB, which makes it
very easy to generate random-yet-still-vibrant colors.
-----------------------------------------------------------------------------*/
function wavatar_hsl ($h, $s, $l)
{
if ($h>240 || $h<0 || $s>240 || $s<0 || $l>240 || $l<0)
return array(0,0,0);
if ($h<=40) {
$R=255;
$G=(int)($h/40*256);
$B=0;
} elseif ($h>40 && $h<=80) {
$R=(1-($h-40)/40)*256;
$G=255;
$B=0;
} elseif ($h>80 && $h<=120) {
$R=0;
$G=255;
$B=($h-80)/40*256;
} elseif ($h>120 && $h<=160) {
$R=0;
$G=(1-($h-120)/40)*256;
$B=255;
} elseif ($h>160 && $h<=200) {
$R=($h-160)/40*256;
$G=0;
$B=255;
} elseif ($h>200) {
$R=255;
$G=0;
$B=(1-($h-200)/40)*256;
}
$R=$R+(240-$s)/240*(128-$R);
$G=$G+(240-$s)/240*(128-$G);
$B=$B+(240-$s)/240*(128-$B);
if ($l<120) {
$R=($R/120)*$l;
$G=($G/120)*$l;
$B=($B/120)*$l;
} else {
$R=$l*((256-$R)/120)+2*$R-256;
$G=$l*((256-$G)/120)+2*$G-256;
$B=$l*((256-$B)/120)+2*$B-256;
}
return array((int)wavatar_clamp ($R),(int)wavatar_clamp($G),(int)wavatar_clamp($B));
}
/*-----------------------------------------------------------------------------
Helper function for building a wavatar. This loads an image and adds it to
our composite using the given color values.
-----------------------------------------------------------------------------*/
function wavatar_apply_image ($base, $part)
{
$file = dirname(__FILE__).'/parts/' . $part . '.png';
$im = @imagecreatefrompng($file);
if(!$im)
return;
imagecopy($base,$im, 0, 0, 0, 0, AVATAR_SIZE, AVATAR_SIZE);
imagedestroy($im);
}
/*-----------------------------------------------------------------------------
Builds the avatar.
-----------------------------------------------------------------------------*/
function wavatar_build ($seed, $filename, $size)
{
//look at the seed (an md5 hash) and use pairs of digits to determine our
//"random" parts and colors.
$face = 1 + (hexdec (substr ($seed, 1, 2)) % (WAVATAR_FACES));
$bg_color = (hexdec (substr ($seed, 3, 2)) % 240);
$fade = 1 + (hexdec (substr ($seed, 5, 2)) % (WAVATAR_BACKGROUNDS));
$wav_color = (hexdec (substr ($seed, 7, 2)) % 240);
$brow = 1 + (hexdec (substr ($seed, 9, 2)) % (WAVATAR_BROWS));
$eyes = 1 + (hexdec (substr ($seed, 11, 2)) % (WAVATAR_EYES));
$pupil = 1 + (hexdec (substr ($seed, 13, 2)) % (WAVATAR_PUPILS));
$mouth = 1 + (hexdec (substr ($seed, 15, 2)) % (WAVATAR_MOUTHS));
// create backgound
$avatar = imagecreatetruecolor (AVATAR_SIZE, AVATAR_SIZE);
//Pick a random color for the background
$c = wavatar_hsl ($bg_color, 240, 50);
$bg = imagecolorallocate ($avatar, $c[0], $c[1], $c[2]);
imagefill($avatar, 1, 1, $bg);
$c = wavatar_hsl ($wav_color, 240, 170);
$bg = imagecolorallocate ($avatar, $c[0], $c[1], $c[2]);
//Now add the various layers onto the image
wavatar_apply_image ($avatar, "fade$fade");
wavatar_apply_image ($avatar, "mask$face");
imagefill($avatar, (int)(AVATAR_SIZE / 2),(int)(AVATAR_SIZE / 2),$bg);
wavatar_apply_image ($avatar, "shine$face");
wavatar_apply_image ($avatar, "eyes$eyes");
wavatar_apply_image ($avatar, "brow$brow");
wavatar_apply_image ($avatar, "pupils$pupil");
wavatar_apply_image ($avatar, "mouth$mouth");
//resize if needed
if ($size != AVATAR_SIZE) {
$out = imagecreatetruecolor($size,$size);
imagecopyresampled ($out,$avatar, 0, 0, 0, 0, $size, $size, AVATAR_SIZE, AVATAR_SIZE);
imagepng($out, $filename);
imagedestroy($out);
imagedestroy($avatar);
} else {
imagepng($avatar, $filename);
imagedestroy($avatar);
}
}
使用するには、オリジナルのwavatarをダウンロードしてください。partsフォルダを解凍し、wavatar.phpファイルと同じディレクトリに置きます。次に、次のように呼び出します。
//$seed: $seed to use in create unique avatar for every user preferably md5 of the users email
//$filename: where and what name the image should be stored with
//$size: size of the image
function wavatar_build ($seed, $filename, $size);
于 2012-09-30T08:51:57.870 に答える
1
WP_MonsterID は、その仕組みを詳しく説明しています。例によって学びます。
于 2012-09-30T07:51:59.433 に答える
0
imagecreatefrom*() 関数とそれに関連する他のものを使用して、自分で作成できます。例えば。imagecreatefrompng();
于 2012-09-30T07:46:21.897 に答える