Just some code beautification
This commit is contained in:
parent
72b8bc815c
commit
ac5db74a8b
1 changed files with 19 additions and 11 deletions
|
@ -252,10 +252,12 @@ function catavatar_content(App $a)
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
function build_cat($seed='', $size=0){
|
function build_cat($seed = '', $size = 0)
|
||||||
|
{
|
||||||
// init random seed
|
// init random seed
|
||||||
if($seed) srand( hexdec(substr(md5($seed),0,6)) );
|
if ($seed) {
|
||||||
|
srand(hexdec(substr(md5($seed),0,6)));
|
||||||
|
}
|
||||||
|
|
||||||
// throw the dice for body parts
|
// throw the dice for body parts
|
||||||
$parts = array(
|
$parts = array(
|
||||||
|
@ -273,11 +275,13 @@ function build_cat($seed='', $size=0){
|
||||||
imagefill($cat,0,0,$white);
|
imagefill($cat,0,0,$white);
|
||||||
|
|
||||||
// add parts
|
// add parts
|
||||||
foreach($parts as $part => $num){
|
foreach ($parts as $part => $num){
|
||||||
$file = dirname(__FILE__).'/avatars/'.$part.'_'.$num.'.png';
|
$file = dirname(__FILE__).'/avatars/'.$part.'_'.$num.'.png';
|
||||||
|
|
||||||
$im = @imagecreatefrompng($file);
|
$im = @imagecreatefrompng($file);
|
||||||
if(!$im) die('Failed to load '.$file);
|
if (!$im) {
|
||||||
|
die('Failed to load '.$file);
|
||||||
|
}
|
||||||
imageSaveAlpha($im, true);
|
imageSaveAlpha($im, true);
|
||||||
imagecopy($cat,$im,0,0,0,0,CATAVATAR_SIZE,CATAVATAR_SIZE);
|
imagecopy($cat,$im,0,0,0,0,CATAVATAR_SIZE,CATAVATAR_SIZE);
|
||||||
imagedestroy($im);
|
imagedestroy($im);
|
||||||
|
@ -285,10 +289,16 @@ function build_cat($seed='', $size=0){
|
||||||
|
|
||||||
// scale image
|
// scale image
|
||||||
if ($size > 3 && $size < 7) {
|
if ($size > 3 && $size < 7) {
|
||||||
switch($size) {
|
switch ($size) {
|
||||||
case 4: $size = 175; break;
|
case 4:
|
||||||
case 5: $size = 80; break;
|
$size = 175;
|
||||||
case 6: $size = 48; break;
|
break;
|
||||||
|
case 5:
|
||||||
|
$size = 80;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
$size = 48;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dest = imagecreatetruecolor($size, $size);
|
$dest = imagecreatetruecolor($size, $size);
|
||||||
|
@ -311,5 +321,3 @@ function build_cat($seed='', $size=0){
|
||||||
imagejpeg($cat, NULL, 90);
|
imagejpeg($cat, NULL, 90);
|
||||||
imagedestroy($cat);
|
imagedestroy($cat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue