21, //color1 'body_back' => 33, 'body_front' => 27, //color2 'body_front_color' => 33, //color3 'accessory_middle_back' => 14, //color1 'head' => 1, 'accessory_middle_front' => 6, //color1 'face_back' => 15, 'hair_front' => 14, //color1 'face_front' => 15, 'eye' => 72, //color4 'accessory_front' => 10 ); $files = array_keys($imgs); $colors = array('default','brown','black','green'); //hair_back $num = fileNum(0,$imgs['hair_back']); $hair = colorSelect($colors); createImg($hair,'hair_back',$background,$num); //body_back[front][front_color] $num = fileNum(0,$imgs['body_back']); createImg('body_back','body_back',$background,$num); if($num < 8){ $cname = colorSelect($colors); createImg($cname,'body_front',$background,$num); createImg($cname,'body_front_color',$background,$num); } elseif($num >13){ $cname = colorSelect($colors); createImg($cname,'body_front',$background,$num - 6); createImg($cname,'body_front_color',$background,$num); } else{ $cname = colorSelect($colors); createImg($cname,'body_front_color',$background,$num); } //accessory_middle_back[front] $num = fileNum(0,$imgs['accessory_middle_back']); createImg($hair,'accessory_middle_back',$background,$num); if($num < 2){ $head = fileNum(0,$imgs['head']); createImg('head','head',$background,$head); } elseif($num > 8){ $head = fileNum(0,$imgs['head']); createImg('head','head',$background,$head); } else{ $head = fileNum(0,$imgs['head']); createImg('head','head',$background,$head); createImg($hair,'accessory_middle_front',$background,$num - 2); } //face_back $num = fileNum(0,$imgs['face_back']); createImg('face_back','face_back',$background,$num); //hair_front $num = fileNum(0,$imgs['hair_front']); createImg($hair,'hair_front',$background,$num); //face_front $num = fileNum(0,$imgs['face_front']); createImg('face_front','face_front',$background,$num); //eye $num = fileNum(0,$imgs['eye']); createImg('eye','eye',$background,$num); //accessory_front $num = fileNum(0,$imgs['accessory_front']); createImg($hair,'accessory_front',$background,$num); $font = './mikachanALL.ttc'; $text_n = array_shift($result); foreach($result as $var){ $text_p .= mb_strimwidth($var,0,50,"","UTF-8"); $text_p .= "\n"; $text_p .= mb_substr($var ,25,50,"UTF-8"); $text_p .= mb_substr($var ,50,100,"UTF-8"); $text_p .= "\n"; } imagettftext ($background, 30, 0, 300, 150, $text_color, $font, $text_n ); imagettftext ($background, 11, 0, 250, 200, $text_color, $font, $text_p ); header("Content-Type: image/png"); imagepng($background); imagedestroy($background); //ファイル数を$imgsより取得 function fileNum($min,$max){ $rnd = (int)rand($min,$max); return $rnd; } //$dir色ごとのディレクトリ名 $partsパーツ名 $back画像オブジェクト $nファイル数 function createImg($dir,$parts,$back,$n){ if($dir == $parts){$front = imagecreatefrompng("./parts/$parts/$parts"."$n.png");} else{$front = imagecreatefrompng("./parts/$parts/$dir/$parts"."$n.png");} imagecopy($back,$front,0,0,0,0 ,300, 400); } //$colorsに含まれるディレクトリ名を返す function colorSelect($c){ $n = count($c) -1 ; $color = $c[(int)rand(0,$n)]; return $color; } ?>