Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
12-19-2009, 08:05 AM
(This post was last modified: 12-21-2009, 01:30 PM by Gaijin.)
So I didn't know Nyx- made one, but anyways I made one too...
Now you just need to set everything in the $config array and you're good to go!
The script looks for the folder that is defined as "SIG_DIR" (signatures) and gets images from that folder.
To avoid errors, plese place only images into the folder, jpg, gif and png are supported....
You can also use custom strings and custom fonts, fonts are readed from the "fonts" directory and you can define a default one or just randomize it too.
Fonts must be .ttf ones.
If you want to resize the images so that they all have the same size, just set the width and height in the $config array and set resize to TRUE.
A directory structer would look like this.
rand_sig.php
signatures/
your signatures
fonts/
your fonts
PHP 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
?>
If you use the script, and you encounter any bugs please tell me about them in this thread!
Thank you!
Posts: 43
Threads: 6
Joined: Oct 2009
Reputation:
0
Posts: 130
Threads: 13
Joined: Oct 2009
Reputation:
10
nice, way better then mine xD
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
(12-19-2009, 11:49 AM)FarOut Wrote: Cool stuff!
Thank you very much!
I have few more ideas, but later.....
Posts: 130
Threads: 13
Joined: Oct 2009
Reputation:
10
weird........ STOP FOLLOWING ME!!!
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
12-19-2009, 02:45 PM
(This post was last modified: 12-19-2009, 02:46 PM by Gaijin.)
(12-19-2009, 02:42 PM)Nyx- Wrote: nice, way better then mine xD
Thanks Nyx... lol not better it just has a function more
edit: lol wasn't following you, it was faith...
jk... it was making my way from top to bottom in new posts...
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
12-21-2009, 11:46 AM
(This post was last modified: 12-21-2009, 11:52 AM by Gaijin.)
UPDATED....
Since Xenocide posted a Changing Avatar Script....
I thought to update this one with few lines so it can do the same.
You can now set the script with the GET method, to genearte an avatar.
All values inside of $config array are defined with the GET method.
The example url would look like:
Code: rand_sig.php?generate=avatar&resize=1&width=120&height=120&generate_text=1&avatar_dir=ava&text=MOTU&text_size=14&text_pos_x=5&text_pos_y=110
generate=avatar is the key to redeclare the $config array with GET given values...
In the above string this script is set to generate an image from ava directory with the w120 and h120 size.
generate_text=0 will disable cusom strings.
EDIT:
The script is based on what I've shown with my Tutorials, so I hope this gives you an idea for the use of them!
Posts: 130
Threads: 13
Joined: Oct 2009
Reputation:
10
you should post this in english on HF ^__^ I was trying to look for it but couldnt find it other than in the Balkan section
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
(01-24-2010, 03:49 PM)Nyx- Wrote: you should post this in english on HF ^__^ I was trying to look for it but couldnt find it other than in the Balkan section
Sure, why shouldn't I...
I'll post it soon...
|