RPG-Maker Quartier

Hier dreht sich alles um die RPG-Maker-Reihe von ASCII/Enterbrain. Der RPG-Maker ist ein Tool, mit dem du dir dein eigenes kleines Rollenspiel erstellen kannst. Du findest hier alles, was du dazu brauchst. Aber natürlich umfasst die Community noch mehr!
Aktuelle Zeit: Di Mär 03, 2020 0:45

Alle Zeiten sind UTC + 1 Stunde



Mitglieder in diesem Forum: 0 Mitglieder und 5 Gäste



Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Autor Nachricht
Offline
Alex
Alex
Benutzeravatar
Beiträge: 3
 Betreff des Beitrags: [PHP] Zufällige Signatur und Avatar
BeitragVerfasst: Mi Jan 06, 2010 16:09 
Also ich habe aus langeweile ein kleines PHP script geschrieben, und um meinen Post count bisschen zu steigern poste ich das script mal hier für euch.
Es liest die bilder aus dem vor gegebenen ordner = SIG_DIR..
Ihr hab auch die möglichkeit eine text zeile auf das bild zu generieren und auch noch mit verschiedenen fonts. FONT_DIR
Die font dateien müssen .ttf sein.
Das ganze wird durch das array $config gesteuert, die namen sind offensichtlich das es keine grossen erklärungs worte braucht...

Nur wenn ihr es zum avatar beutzen wollt müsst ihr das script per GET method aufrufen....Danach könnt ihr auch über die GET methode alle $config mitglieder ändern..

Hoffe ihr habt spass mit dem ding... :D

Code:
rand_sig.php?generate=avatar&resize=1&width=120&height=120&generate_text=1&avatar_dir=ava&text=Rise&text_size=14&text_pos_x=5&text_pos_y=110


Code:

<?php

/***********************************************************************
* FILE: rand_sig.php                                                   *
* AUTHOR: NinjaGeek                                                    *
* LICENSE: GNU Public License  http://www.gnu.org/licenses/gpl.html    *
***********************************************************************/

// define the directory where the signature images are being stored
define("SIG_DIR", "signatures");
// define fonts directory for custom text
// only .ttf Fonts supported
define("FONT_DIR", "fonts");
// define the default font for custom text strings
define("DEFAULT_FONT", "");

// configuration array
$config = array(
    'resize' => TRUE, // resize all images to given size
    'width'  => 650,  // resize widtht                  
    'height' => 200,  // resize height
    'text'   => "NinjaGeek", // custom string
    'generate_text' => TRUE, // generate custom string
    'use_custom_font' => TRUE, // generate cusomt string with custom font
    'random_font' => TRUE, // use random font
    'text_size' => 22, // font size
    'text_pos_x' => 50, // font position left
    'text_pos_y' => 50, // font position top             
    'text_angle' => 0  // string rotation angle                       
);

// check if generate attribute was changed with the GET method
if(isset($_GET['generate']) && $_GET['generate'] == "avatar") {
    $config["generate"] = $_GET['generate']; // add new config member
    foreach($_GET as $index => $define) {
        // for each per GET defined member redeclare the old one
        $config[$index] = (isset($_GET[$index])) ? $_GET[$index] : $config[$index];
    }
    
    
// define new path form images to load
    $new_path = (!array_key_exists("avatar_dir", $config)) ? SIG_DIR : $_GET['avatar_dir'];
    define("AVA_DIR", $new_path);
}

// scan signatures directory
if(isset($new_path)) {
    // if AVA_DIR was defined update path for use
    $new_path = AVA_DIR;
}else{
    $new_path = SIG_DIR;
}

$signatures = scandir($new_path);
$clear_array = array();

// loop through signatures and clean it form unneeded entries
foreach($signatures as $value) {
    // if entry is file
    if(is_file($new_path."/".$value)) {
        $clear_array[] = $value; // add it to a clean array
    }
}

$signatures = $clear_array; // update signatures list
unset($clear_array); // delete $clear_array

//set random signature number to signatures amount
$random_max = (count($signatures) - 1);
$random = rand(0, $random_max);

// define path to the signature
$image_path = $new_path."/".$signatures[$random];

// get image data
if(!@$size = getimagesize($image_path)) {
    // if getimagesize failed kill the script
    die("Error, getimagesize() failed!");
}

// look what image resource to create
switch($size['mime']) {
    case "image/gif":
        // create from gif
        $image = imagecreatefromgif($image_path);
        break;
    case "image/jpeg":
        // create from jpeg
        $image = imagecreatefromjpeg($image_path);
        break;
    case "image/png":
        // create from png
        $image = imagecreatefrompng($image_path);
        break;
    default:
        // if mime is not one of the 3 above kill the script
        die("Not supported image format: {$size['mime']}");
}

// if resize is TRUE
if($config['resize']) {
    // create new resource with new sizes
    $resize_im = imagecreatetruecolor($config['width'], $config['height']);
    // copy original image to new size
    imagecopyresampled($resize_im, $image, 0, 0, 0, 0, $config['width'], $config['height'], $size[0], $size[1]);
    $image = $resize_im; // redeclare $image
}

if(
$config['generate_text']) {
    // create rgb color resource 
    $color = imagecolorallocate($image, 255,0,0);
    // if random fonts are enabled
    $fonts = array(); // new array for fonts
    // if random font is enabled
    if($config['random_font']) {
        // scan fonts directory
        foreach(scandir(FONT_DIR) as $font) {
            // if is file add it to font list
            if(is_file(FONT_DIR."/".$font)) {
                $fonts[] = $font;
            }
        }
        
        
// get max number for random font
        $font_max = (count($fonts) - 1);
        // random font id
        $random_font = rand(0, $font_max);
    }
    
    
// if use_custom_font is enabled
    if($config['use_custom_font']) {
        // define font path
        $font = (@$random_font) ? $fonts[$random_font] : DEFAULT_FONT;
        $font = FONT_DIR."/".$font; // update font path
        // create custom string
        imagettftext($image, $config['text_size'], $config['text_angle'], $config['text_pos_x'], $config['text_pos_y'], $color, $font, $config['text']);
    }else{
        // create custom string
        imagestring($image, $config['text_size'], $config['text_pos_x'], $config['text_pos_y'], $config['text'], $color);
    }
}

// define header as image/png
header("Content-type: image/png");

imagepng($image); // output image
imagedestroy($image); // clear memory

?>

_________________
Bild
Support Forums


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 

Alle Zeiten sind UTC + 1 Stunde


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de