User Tools

Site Tools


wargroundscanberra:character_sheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wargroundscanberra:character_sheet [2024/07/14 19:16] curufeawargroundscanberra:character_sheet [2024/07/19 15:56] (current) curufea
Line 1: Line 1:
 ====== Character Sheets ====== ====== Character Sheets ======
 +^  Go back to [[start|Wargrounds Canberra]]  ^
  
-[[https://www.curufea.com/image.php]]+  * Working Form: [[form|Fill in Character Sheet]] 
 +  * Working Location: [[https://www.curufea.com/image.php]]  
 +  * Test Form: [[form test|Fill in Character Sheet]] 
 +  * Test Location: [[https://www.curufea.com/image_test.php]]
  
 <code> <code>
 <?php <?php
-// Path to our font file +// Character Sheet creator for Wargrounds Canberra 
-$font = 'oldeenglish.ttf';+// To be added- some images (to be sourced) as defaults - space fillers and icons 
 +// To be added- a player photo (part of the form input)  
 +// Version 0.4 19/7/24 - curufea@yahoo.com 
 +// Currently hosted at www.curufea.com 
 + 
 +// Path to our font file (relative to the location of this file) 
 +$font = 'blackwoodcastle.ttf'; // for field names 
 +$font_data = 'oldeenglish.ttf'; // for player data 
 +// Path to images (relative to the location of this file) 
 +$imagepath = 'data/media/wargroundscanberra/'; 
 +// Bacground image texture 
 +$imageback = $imagepath.'another-rough-old-and-worn-parchment-paper.jpg'; 
 +$im2 = imagecreatefromjpeg("$imageback"); 
 + 
 +//defaults - to be overwritten by form inputs
 $fontsize = 20; $fontsize = 20;
 +$linespacing = round($fontsize*2);
 +$width = 530; // pixel size x of image
 +$height = 754; // size y of image
  
-// array of field names+// array of default field names
 $names = array( $names = array(
-"Player Name:", + "Player Name:", "Character's Name:", "Titles/Nicknames:", "Race/Species:", "Hair Colour:", "Eye Colour:", "Skin Colour:", "Class & Tier:", "School of Magic:", "Faction:", "Warband:", "Marx:"); 
-"Character's Name:", +// the field names used in the form 
-"Titles/Nicknames:", +$getnames = array( 
-" ", + "name", "character", "title", "species", "hair", "eye", "skin", "class", "magic", "faction", "warband", "marx"); 
-"Race/Species:", +  
-"Hair Colour:", +// 400px x 400px jpeg images stored on the image path (in the Dokuwiki media area) 
-"Eye Colour:", +$factions_images = array( 
-"Skin Colour:", + "clans.jpg", "empire.jpg", "greyscales.jpg", "horde.jpg", "wardens.jpg"); 
-" ", +// used to cross reference the form data to the image name (the Bureaucracy plugin for the Dokuwiki doesn't send selection number chosen) 
-"Class & Tier:", +$factions_titles = array( 
-"School of Magic:");+ "The Clans", "The Empire", "Greyscales", "The Horde", "The Wardens");
  
 +// test data - note will need some error checking in future for actual form data, probably warnings where field data is too long to fit
 +$player_data = array (
 +"Peter", "Cousin Curufea", "", "Human (?)","Natural","Natural","Natural","Mage (Tier 3)","Divine Caster","3","Bone Hearts","0"
 +);
 +
 // count number of field names // count number of field names
 $numnames = count($names)-1; $numnames = count($names)-1;
  
- +// check if any variables have been sent to this image - if they have, overwrite the default player data 
-$width 530// pixel size x of image +for ($count=0;$count<=$numnames;$count++) { 
-$height 754; // size y of image+   $player_data[$count]$_GET[$getnames[$count]]; 
 +   // Convert the text of the selection for faction to a number 
 +   if ($count==9) $player_data[$count]= array_search($_GET[$getnames[$count]],$factions_titles); 
 + };
  
 // Create image // Create image
 $image = imagecreatetruecolor($width,$height); $image = imagecreatetruecolor($width,$height);
  
-// pick color for the background 
-$bgcolor = imagecolorallocate($image, 183, 179, 159); 
 // pick color for the text // pick color for the text
 $fontcolor = imagecolorallocate($image, 0, 0, 0); $fontcolor = imagecolorallocate($image, 0, 0, 0);
  
-// fill in the background with the background color +// add background texture 
-imagefilledrectangle($image, 0, 0, $width, $height, $bgcolor);+imagecopyresized($image, $im2, 0, 0, 0, 0, $width, $height,imagesx($im2), imagesy($im2)); 
 +imagedestroy($im2);
  
 // x,y coords for imagettftext defines the baseline of the text: the lower-left corner // x,y coords for imagettftext defines the baseline of the text: the lower-left corner
 // so the x coord can stay as 0 but you have to add the font size to the y to simulate // so the x coord can stay as 0 but you have to add the font size to the y to simulate
 // top left boundary so we can write the text within the boundary of the image // top left boundary so we can write the text within the boundary of the image
-$x = 36;  +$x = $fontsize;  
-$y = 20;+$y = $fontsize;
 for ($count=0;$count<=$numnames;$count++) { for ($count=0;$count<=$numnames;$count++) {
- $y=$y+36;  // increment by estimated line separation height+ $y=$y+$linespacing;  // increment by estimated line separation height 
 +  
 +// Clunky bit to do positioning.  I'll just generate an array next time  
 + if ($count==3||$count==7) $y=$y+$linespacing;  // blank lines to separate 
 + if ($count==9) { // right column 
 + $y= $linespacing*5; 
 + $x= round($width/2); 
 + }; 
 + if ($count==$numnames) { // centre the last text in the right column 
 + $text = $names[$count] . " 999"; // add possible length  
 + $text_box = imagettfbbox($fontsize,0,$font,$text); // makes an array of co-ordinates for the text box 
 + // Get your Text Width and  
 + $text_width = $text_box[2]-$text_box[0]; 
 + $x = round(($width*2/3)-($text_width/2));  // middle of the right column minus half the size of the text 
 + $y=$y+$linespacing; 
 + }; 
 +// Field names in blackwood castle font
  imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $names[$count]);  imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $names[$count]);
 +// Player data in olde english font
 + $text_box = imagettfbbox($fontsize,0,$font,$names[$count]); // workout where the field name ends
 + $text_width = $text_box[2]-$text_box[0]+round($fontsize/2);
 + $text = $player_data[$count];
 +// Change the selected faction to readable text (and add faction logo)
 + if ($count==9) {
 + $text = $factions_titles[intval($player_data[$count])];
 + $faction= $imagepath.$factions_images[intval($player_data[$count])];
 + $im3 = imagecreatefromjpeg("$faction");
 + imagecopyresized($image, $im3, $width-80, 120, 0, 0, 50, 50,imagesx($im3), imagesy($im3));
 + imagedestroy($im3);
 + };
 +// Print the data
 + imagettftext($image, $fontsize, 0, $x+$text_width, $y, $fontcolor, $font_data, $text);
 }; };
  
 // tell the browser that the content is an image // tell the browser that the content is an image
-header('Content-type: image/png');+header('Content-type: image/jpeg');
 // output image to the browser // output image to the browser
-imagepng($image);+imagejpeg($image);
  
 // delete the image resource  // delete the image resource 
Line 60: Line 118:
 ?> ?>
 </code> </code>
 +
 +===== To do =====
 +
 +  * Images for the various bits
 +  * Possibly API use for wherever photos get stored (or just upload them) - may need to edit photos to fit
 +  * Variable sheet size - just scale everything to whatever is needed.
 +
 +
wargroundscanberra/character_sheet.1721009785.txt.gz · Last modified: 2024/07/14 19:16 by curufea