wargroundscanberra:character_sheet
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wargroundscanberra:character_sheet [2024/07/14 19:24] – curufea | wargroundscanberra:character_sheet [2024/07/19 15:56] (current) – curufea | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Character Sheets ====== | ====== Character Sheets ====== | ||
+ | ^ Go back to [[start|Wargrounds Canberra]] | ||
- | [[https:// | + | * Working Form: [[form|Fill in Character Sheet]] |
+ | * Working Location: | ||
+ | * Test Form: [[form test|Fill in Character Sheet]] | ||
+ | * Test Location: [[https:// | ||
< | < | ||
<?php | <?php | ||
- | // Path to our font file | + | // Character Sheet creator for Wargrounds Canberra |
- | $font = ' | + | // 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 = ' | ||
+ | $font_data | ||
+ | // Path to images (relative to the location of this file) | ||
+ | $imagepath = ' | ||
+ | // Bacground image texture | ||
+ | $imageback = $imagepath.' | ||
+ | $im2 = imagecreatefromjpeg(" | ||
+ | |||
+ | //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 |
$names = array( | $names = array( | ||
- | " | + | " |
- | " | + | // the field names used in the form |
- | " | + | $getnames = array( |
- | " ", | + | " |
- | " | + | |
- | "Hair Colour:", | + | // 400px x 400px jpeg images stored on the image path (in the Dokuwiki media area) |
- | "Eye Colour:", | + | $factions_images = array( |
- | "Skin Colour:", | + | " |
- | " ", | + | // used to cross reference the form data to the image name (the Bureaucracy plugin for the Dokuwiki doesn' |
- | "Class & Tier:", | + | $factions_titles = array( |
- | " | + | "The Clans", |
+ | // 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 ( | ||
+ | " | ||
+ | ); | ||
+ | |||
// 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< |
- | $height | + | |
+ | // Convert the text of the selection for faction to a number | ||
+ | if ($count==9) $player_data[$count]= array_search($_GET[$getnames[$count]], | ||
+ | }; | ||
// Create image | // Create image | ||
$image = imagecreatetruecolor($width, | $image = imagecreatetruecolor($width, | ||
- | // pick color for the background | ||
- | $bgcolor = imagecolorallocate($image, | ||
// pick color for the text | // pick color for the text | ||
$fontcolor = imagecolorallocate($image, | $fontcolor = imagecolorallocate($image, | ||
- | // fill in the background | + | // add background |
- | imagefilledrectangle($image, 0, 0, $width, $height, $bgcolor); | + | imagecopyresized($image, $im2, 0, 0, 0, 0, $width, $height,imagesx($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; | for ($count=0; | ||
- | $y=$y+36; // increment by estimated line separation height | + | $y=$y+$linespacing; // increment by estimated line separation height |
+ | |||
+ | // Clunky bit to do positioning. | ||
+ | if ($count==3||$count==7) $y=$y+$linespacing; | ||
+ | if ($count==9) { // right column | ||
+ | $y= $linespacing*5; | ||
+ | $x= round($width/ | ||
+ | }; | ||
+ | if ($count==$numnames) { // centre the last text in the right column | ||
+ | $text = $names[$count] . " 999"; // add possible length | ||
+ | $text_box = imagettfbbox($fontsize, | ||
+ | // Get your Text Width and | ||
+ | $text_width = $text_box[2]-$text_box[0]; | ||
+ | $x = round(($width*2/ | ||
+ | $y=$y+$linespacing; | ||
+ | }; | ||
+ | // Field names in blackwood castle font | ||
imagettftext($image, | imagettftext($image, | ||
+ | // Player data in olde english font | ||
+ | $text_box = imagettfbbox($fontsize, | ||
+ | $text_width = $text_box[2]-$text_box[0]+round($fontsize/ | ||
+ | $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(" | ||
+ | imagecopyresized($image, | ||
+ | imagedestroy($im3); | ||
+ | }; | ||
+ | // Print the data | ||
+ | imagettftext($image, | ||
}; | }; | ||
// tell the browser that the content is an image | // tell the browser that the content is an image | ||
- | header(' | + | header(' |
// output image to the browser | // output image to the browser | ||
- | imagepng($image); | + | imagejpeg($image); |
// delete the image resource | // delete the image resource | ||
Line 63: | Line 121: | ||
===== To do ===== | ===== To do ===== | ||
- | * A form with default text for field names prefilled | ||
* Images for the various bits | * Images for the various bits | ||
* Possibly API use for wherever photos get stored (or just upload them) - may need to edit photos to fit | * 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.1721010250.txt.gz · Last modified: 2024/07/14 19:24 by curufea