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/18 18:07] – curufea | wargroundscanberra:character_sheet [2024/08/30 15:32] (current) – curufea | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Character Sheets ====== | ====== Character Sheets ====== | ||
| ^ Go back to [[start|Wargrounds Canberra]] | ^ Go back to [[start|Wargrounds Canberra]] | ||
| + | |||
| + | |||
| + | ===== No Longer Used ===== | ||
| + | This project has been superseded by NanDeck (makes it much easier). But I'll keep it on my website just because it was fun to do. | ||
| + | |||
| + | ==== Forms ==== | ||
| * Working Form: [[form|Fill in Character Sheet]] | * Working Form: [[form|Fill in Character Sheet]] | ||
| * Working Location: [[https:// | * Working Location: [[https:// | ||
| - | * Testing | + | * Test (same as working) |
| + | * Form: [[form test|Fill in Character Sheet]] | ||
| + | * Location: [[https:// | ||
| + | |||
| + | ==== Code ==== | ||
| - | < | + | < |
| <?php | <?php | ||
| // Character Sheet creator for Wargrounds Canberra | // Character Sheet creator for Wargrounds Canberra | ||
| - | // To be added- some images (to be sourced) as defaults - space fillers and icons | + | // Version |
| - | // To be added- a player photo (part of the form input) | + | |
| - | // Version | + | |
| // Currently hosted at www.curufea.com | // Currently hosted at www.curufea.com | ||
| Line 17: | Line 25: | ||
| $font = ' | $font = ' | ||
| $font_data = ' | $font_data = ' | ||
| + | $font_wargrounds = ' | ||
| // Path to images (relative to the location of this file) | // Path to images (relative to the location of this file) | ||
| $imagepath = ' | $imagepath = ' | ||
| - | // Bacground image texture | ||
| - | $imageback = $imagepath.' | ||
| - | $im2 = imagecreatefromjpeg(" | ||
| - | //defaults - to be overwritten by form inputs | + | // defaults |
| - | $fontsize = 20; | + | $tempwidth = round(intval($_GET[" |
| + | if (($tempwidth> | ||
| + | $width = $tempwidth; | ||
| + | } else { | ||
| + | $width = 530; // pixel size x of image | ||
| + | }; | ||
| + | $height = round($width*1.422); | ||
| + | $fontsize = round($width/ | ||
| $linespacing = round($fontsize*2); | $linespacing = round($fontsize*2); | ||
| - | $width = 530; // pixel size x of image | + | $borderwidth = round($width/100); |
| - | $height | + | $fontborder |
| + | $textlength = 30; | ||
| + | |||
| + | // default placeholder photo to be replaced by image from form url | ||
| + | $photo=" | ||
| + | if (isset($_GET[" | ||
| + | |||
| + | // the image used for the coin piles | ||
| + | $coins=$imagepath." | ||
| + | |||
| + | // the image used for the weapons space filler | ||
| + | $weapons=$imagepath." | ||
| // array of default field names | // array of default field names | ||
| $names = array( | $names = array( | ||
| - | " | + | " |
| // the field names used in the form | // the field names used in the form | ||
| $getnames = array( | $getnames = array( | ||
| - | " | + | " |
| + | // 0 | ||
| - | // 400px x 400px jpeg images stored on the image path (in the Dokuwiki media area) | + | |
| - | $factions_images = array( | + | // 400px x 400px jpeg images stored on the image path (in the Dokuwiki media area) for faction logos |
| - | "clans.jpg", "empire.jpg", "greyscales.jpg", " | + | $factions_images = array(" |
| // used to cross reference the form data to the image name (the Bureaucracy plugin for the Dokuwiki doesn' | // used to cross reference the form data to the image name (the Bureaucracy plugin for the Dokuwiki doesn' | ||
| - | $factions_titles = array( | + | $factions_titles = array(" |
| - | "The Clans", | + | // 2987px x 4250px jpeg images stored on the image path (in the Dokuwiki media area) for faction backgrounds |
| - | + | $factions_backgrounds | |
| - | // test data - note will need some error checking | + | |
| - | $player_data | + | |
| - | "Peter", "Cousin Curufea", "", | + | |
| - | ); | + | |
| // count number of field names | // count number of field names | ||
| $numnames = count($names)-1; | $numnames = count($names)-1; | ||
| + | // As it is used multiple times, make the font border thingy a function | ||
| + | function DoFontBorder ($im, | ||
| + | for ($x1=($start_x-$font_border); | ||
| + | for ($y1=($start_y-$font_border); | ||
| + | // | ||
| + | }; | ||
| + | }; | ||
| + | }; | ||
| + | |||
| // check if any variables have been sent to this image - if they have, overwrite the default player data | // check if any variables have been sent to this image - if they have, overwrite the default player data | ||
| for ($count=0; | for ($count=0; | ||
| | | ||
| // Convert the text of the selection for faction to a number | // Convert the text of the selection for faction to a number | ||
| - | if ($count==9) $player_data[$count]= array_search($_GET[$getnames[$count]], | + | if ($count==6) { |
| + | $player_data[$count]= array_search($_GET[$getnames[$count]], | ||
| + | | ||
| + | }; | ||
| }; | }; | ||
| + | |||
| + | // Background image texture - now themed to faction | ||
| + | $imageback = $imagepath.$bgimage; | ||
| + | $im2 = imagecreatefromjpeg(" | ||
| // Create image | // Create image | ||
| Line 62: | Line 101: | ||
| // pick color for the text | // pick color for the text | ||
| - | $fontcolor | + | $fontcolour |
| + | |||
| + | // pick color for text borders | ||
| + | $bordercolour = imagecolorallocate($image, | ||
| // add background texture | // add background texture | ||
| Line 73: | Line 115: | ||
| $x = $fontsize; | $x = $fontsize; | ||
| $y = $fontsize; | $y = $fontsize; | ||
| + | |||
| + | $showstuff = true; // by default show all fields | ||
| + | |||
| + | // Add weapons to the character Sheet if there' | ||
| + | if (strlen($player_data[9])+strlen($player_data[10])==0) { | ||
| + | $im6 = imageCreateFromPng($weapons); | ||
| + | imagecopyresized($image, | ||
| + | imagedestroy($im6); | ||
| + | }; | ||
| + | |||
| + | // Add coin piles to the character Sheet | ||
| + | $im5 = imageCreateFromPng($coins); | ||
| + | if (strlen($player_data[7])> | ||
| + | imagecopyresized($image, | ||
| + | } else { | ||
| + | imagecopyresized($image, | ||
| + | }; | ||
| + | imagedestroy($im5); | ||
| + | |||
| + | // Add the large W | ||
| + | imagettftext($image, | ||
| + | |||
| for ($count=0; | for ($count=0; | ||
| $y=$y+$linespacing; | $y=$y+$linespacing; | ||
| - | // Clunky bit to do positioning. | + | // Clunky bit to do positioning. |
| - | if ($count==3||$count==7) $y=$y+$linespacing; | + | if ($count==3||$count==4) $y=$y+$linespacing; |
| - | if ($count==9) { // right column | + | |
| + | if ($count==6) { // right column | ||
| $y= $linespacing*5; | $y= $linespacing*5; | ||
| $x= round($width/ | $x= round($width/ | ||
| }; | }; | ||
| - | if ($count==$numnames) { // centre the last text in the right column | + | if ($count==8) { // centre the last text in the right column |
| $text = $names[$count] . " 999"; // add possible length | $text = $names[$count] . " 999"; // add possible length | ||
| $text_box = imagettfbbox($fontsize, | $text_box = imagettfbbox($fontsize, | ||
| Line 90: | Line 155: | ||
| $y=$y+$linespacing; | $y=$y+$linespacing; | ||
| }; | }; | ||
| - | // Field names in blackwood castle font | + | |
| - | imagettftext($image, | + | if ($count==9) { // Do the new Fletching field |
| + | $y=$fontsize+($linespacing*10); | ||
| + | $x = $fontsize; | ||
| + | }; | ||
| + | |||
| + | if ($count==10) { // Do the new background field | ||
| + | $y=$fontsize+($linespacing*12); | ||
| + | $x = $fontsize; | ||
| + | }; | ||
| + | |||
| // Player data in olde english font | // Player data in olde english font | ||
| $text_box = imagettfbbox($fontsize, | $text_box = imagettfbbox($fontsize, | ||
| $text_width = $text_box[2]-$text_box[0]+round($fontsize/ | $text_width = $text_box[2]-$text_box[0]+round($fontsize/ | ||
| $text = $player_data[$count]; | $text = $player_data[$count]; | ||
| + | |||
| + | // Hide the magic, fletching and background fields if they aren't filled in | ||
| + | if (($count==5) and strlen($text)< | ||
| + | if (($count==9) and strlen($text)< | ||
| + | if (($count==10) and strlen($text)< | ||
| + | |||
| + | // Do the border for the field names | ||
| + | if ($showstuff) DoFontBorder ($image, | ||
| + | |||
| + | // Field names in blackwood castle font | ||
| + | if ($showstuff) imagettftext($image, | ||
| + | |||
| + | if ($showstuff==false) $showstuff=true; | ||
| + | |||
| // Change the selected faction to readable text (and add faction logo) | // Change the selected faction to readable text (and add faction logo) | ||
| - | if ($count==9) { | + | if ($count==6) { |
| $text = $factions_titles[intval($player_data[$count])]; | $text = $factions_titles[intval($player_data[$count])]; | ||
| $faction= $imagepath.$factions_images[intval($player_data[$count])]; | $faction= $imagepath.$factions_images[intval($player_data[$count])]; | ||
| - | $im3 = imagecreatefromjpeg("$faction"); | + | $im3 = imageCreateFromPng($faction); |
| - | imagecopyresized($image, | + | $ratio = imagesy($im3)/ |
| + | imagecopyresized($image, | ||
| imagedestroy($im3); | imagedestroy($im3); | ||
| }; | }; | ||
| + | |||
| // Print the data | // Print the data | ||
| - | imagettftext($image, | + | |
| + | // Put titles, magic type, fletching and background on the next line so it fits | ||
| + | if (($count==5) or ($count==9)or ($count==10)) { | ||
| + | if ($count==10) { | ||
| + | $maxlen=25; | ||
| + | $shorter = explode(" | ||
| + | $currentlength=0; | ||
| + | $currentline=1; | ||
| + | $currentword=0; | ||
| + | $text=""; | ||
| + | for ($wordcount=0; | ||
| + | $currentlength=$currentlength+strlen($shorter[$wordcount]); | ||
| + | $text=$text.$shorter[$wordcount]." | ||
| + | if ($currentlength> | ||
| + | $currentlength=0; | ||
| + | if ($currentline< | ||
| + | DoFontBorder ($image, | ||
| + | imagettftext($image, | ||
| + | }; | ||
| + | $text=""; | ||
| + | $currentline++; | ||
| + | }; | ||
| + | }; | ||
| + | } else { | ||
| + | DoFontBorder ($image, | ||
| + | imagettftext($image, | ||
| + | }; | ||
| + | } else { | ||
| + | if (($count==2) or ($count==4) or ($count==7)) { // make titles, class and background smaller to fit | ||
| + | $maxlen=15; | ||
| + | if ($count==2) $maxlen=25; | ||
| + | if (strlen($text)> | ||
| + | $string_break=stripos($text," | ||
| + | if (strlen($text)> | ||
| + | DoFontBorder ($image, | ||
| + | DoFontBorder ($image, | ||
| + | imagettftext($image, | ||
| + | imagettftext($image, | ||
| + | } else { | ||
| + | DoFontBorder ($image, | ||
| + | imagettftext($image, | ||
| + | }; | ||
| + | } else { | ||
| + | DoFontBorder ($image, | ||
| + | imagettftext($image, | ||
| + | }; | ||
| + | }; | ||
| }; | }; | ||
| + | |||
| + | // Add the photo to the character Sheet | ||
| + | $im4 = imagecreatefromjpeg($photo); | ||
| + | $ratio = imagesy($im4)/ | ||
| + | |||
| + | $start_x=round($width/ | ||
| + | $start_y= round($width/ | ||
| + | |||
| + | $i_width= round($width*0.4); | ||
| + | $i_height= round($i_width*$ratio); | ||
| + | |||
| + | $end_x= $start_x+$i_width; | ||
| + | $end_y= $start_y+$i_height; | ||
| + | |||
| + | |||
| + | // Draw border | ||
| + | imagefilledrectangle($image, | ||
| + | |||
| + | // Resize and place in character Sheet | ||
| + | imagecopyresized($image, | ||
| + | imagedestroy($im4); | ||
| // tell the browser that the content is an image | // tell the browser that the content is an image | ||
| Line 118: | Line 275: | ||
| </ | </ | ||
| - | ===== To do ===== | ||
| - | |||
| - | * A [[form test]] with default text for field names prefilled (but not as complex as the one in this link) | ||
| - | * 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.1721351277.txt.gz · Last modified: by curufea
