Jump to content

webelious

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by webelious

  1. I have to show you the way the bitmap font is loaded, to generate the png out of .nfo, .diz & txt files, BUT i need to know how to generate a bitmap font file (mine has no extension, it is an extension of a tiny script i found years ago on a google repository, so it has no extension, its just called 'nfo2pngfont' here is how it's called in the nfo2png.php file-: // Load the Bitmap-Font $fnt = imageloadfont("nfo2pngfont"); Here is the nfo2png.php file: (it shows you can alter the font size, but only the [Generated by: NFOPic] is made larger od smaller by changing numbers 1 - 5 ??? it used to work, it's bizzre, not sure if someone who help do some code for me changed something, but DEFINARELY a BUG? <?php function buildNFO($nfotext, $footer = "", $fg = "000000", $bg = "FFFFFF", $file_name = 'new_image', $path = 'uploads/' ) { // header("Content-Type: image/png"); // header("Content-Disposition: inline; filename=\"" . $file_name . ".png\""); $nfotext = ( empty( $nfotext ) ? "Empty String submitted." : $nfotext ); $nfo = explode("\n", $nfotext); // Load the Bitmap-Font $fnt = imageloadfont("nfo2pngfont"); $nxo = array(); $xmax = 0; $bigger_than_footer = false; // Reformat each line foreach( $nfo as $line ) { $line = chop($line); if ( empty( $line ) ) { array_push($nxo,$line); continue; } if ( strlen( $line ) > strlen( $footer ) ) { $bigger_than_footer = true; } $fill = ''; //add white space to each line until we have one bigger than the footer if ( !$bigger_than_footer ) { $fill = str_repeat(" ", ( strlen( $footer ) - strlen( $line ) ) ); } if($xmax < strlen($line.$fill)) $xmax = strlen($line.$fill); array_push($nxo,$line.$fill); } // Show footer if(strlen($footer)) { array_push($nxo,""); $repeat_count = $xmax - strlen($footer)>>1; $repeat_count = ( $repeat_count >= 0 ? $repeat_count : 0 ); //add whitespace to footer to push out to the middle //this line overrides the centering and only pushed it two from the left //remove this line to have it go back to the center //$repeat_count = 0; $fill = str_repeat(" ", $repeat_count ); array_push($nxo,$fill.$footer); } // Linecount $ymax = count($nxo); // Set foreground color $color = array(0, 0, 0); if(strlen($fg) == 6) { $color[0] = intval(substr($fg,0,2), 16); $color[1] = intval(substr($fg,2,2), 16); $color[2] = intval(substr($fg,4,2), 16); } $bg_color = array(0, 0, 0); if(strlen($bg) == 6) { $bg_color[0] = intval(substr($bg,0,2), 16); $bg_color[1] = intval(substr($bg,2,2), 16); $bg_color[2] = intval(substr($bg,4,2), 16); } // Render NFO $im = imagecreate($xmax*8,$ymax*16); imageinterlace($im,1); // $background_color = ImageColorTransparent($im, ImageColorAllocate ($im, 254, 254, 126)); $background_color = imagecolorallocate($im, $bg_color[0], $bg_color[1], $bg_color[2]); $text_color = imagecolorallocate($im, $color[0], $color[1], $color[2]); foreach($nxo as $y=>$line) { //shrink the last line if ( $y == count($nxo) - 1 ) { $fnt = 1; //to use preloaded fonts, 1 - 5 only. 1 is tiny, 2 is decent, 3-5 are bolder/worse } imagestring($im, $fnt, 0, $y*16, $line, $text_color); } imagepng( $im, $path . $file_name . '.png' ); } function buildNFONew($imageWidth=600, $padding=array(),$nfotext, $footer = "", $fg = "000000", $bg = "FFFFFF", $file_name = 'new_image', $path = 'uploads/') { $nfotext = ( empty( $nfotext ) ? "Empty String submitted." : $nfotext ); $nfo = explode("\n", $nfotext); // Load the Bitmap-Font $fnt = imageloadfont("nfo2pngfont"); // $charWidth=imagefontwidth($fnt); $charHeight=imagefontheight($fnt); if(!isset($imageWidth) or !is_numeric($imageWidth)) { $imageWidth=600; } $pDefaults=array("top"=>2,"right"=>0,"bottom"=>2,"left"=>0); if(!isset($padding) or !$padding) { $padding=$pDefaults; } else { if(is_array($padding)) { foreach($pDefaults as $pKey=>$pValue) { if(!isset($padding[$pKey])) { $padding[$pKey]=$pValue; } } } else { $tPadding=(string)$padding; $padding=array(); $tPadding=explode(" ",$tPadding); if(count($tPadding)==1) { if(is_numeric($tPadding[0])) { foreach(array("top","right","bottom","left") as $pKey=>$pValue) { $padding[$pValue]=(int)$tPadding[0]; } } } elseif(count($tPadding)>1) { foreach(array("top","right","bottom","left") as $pKey=>$pValue) { if(!empty($tPadding)) { $padding[$pValue]=(int)array_shift($tPadding); } } } if(!isset($padding["bottom"])) { $padding["bottom"]=$padding["top"]; } if(!isset($padding["left"])) { $padding["left"]=$padding["right"]; } } } // $nxo = array(); $max_linewidth=$padding["left"]+$padding["right"]; $didWrap=false; // Reformat each line foreach($nfo as $line) { $line = chop($line); if(empty($line)) { array_push($nxo,$line); continue; } $words=explode(" ",$line); $cLine=""; do { $word=array_shift($words); $cWidth=((int)(($charWidth*strlen($cLine.(($cLine=="")?"":" ").$word))+$padding["left"]+$padding["right"])); if($cWidth<=$imageWidth) { $cLine.=(($cLine=="")?"":" ").$word; if($max_linewidth<$cWidth) { $max_linewidth=$cWidth; } } else { array_push($nxo,$cLine); $cLine=$word; $didWrap=true; } } while(!empty($words)); array_push($nxo,$cLine); } // Show footer if(strlen($footer)) { array_push($nxo,""); $repeat_count = $xmax - strlen($footer)>>1; $repeat_count = ( $repeat_count >= 0 ? $repeat_count : 0 ); //add whitespace to footer to push out to the middle //this line overrides the centering and only pushed it two from the left //remove this line to have it go back to the center //$repeat_count = 0; $fill = str_repeat(" ", $repeat_count ); array_push($nxo,$fill.$footer); } // Linecount $imageHeight = ($padding["top"]+(count($nxo)*$charHeight)+$padding["bottom"]); if($didWrap===false) { $imageWidth=$max_linewidth; } // Set foreground color $color = array(0, 0, 0); if(strlen($fg) == 6) { $color[0] = intval(substr($fg,0,2), 16); $color[1] = intval(substr($fg,2,2), 16); $color[2] = intval(substr($fg,4,2), 16); } $bg_color = array(0, 0, 0); if(strlen($bg) == 6) { $bg_color[0] = intval(substr($bg,0,2), 16); $bg_color[1] = intval(substr($bg,2,2), 16); $bg_color[2] = intval(substr($bg,4,2), 16); } // Render NFO $im = imagecreate($imageWidth,$imageHeight); imageinterlace($im,1); // $background_color = ImageColorTransparent($im, ImageColorAllocate ($im, 254, 254, 126)); $background_color = imagecolorallocate($im, $bg_color[0], $bg_color[1], $bg_color[2]); $text_color = imagecolorallocate($im, $color[0], $color[1], $color[2]); foreach($nxo as $rIndex=>$line) { //shrink the last line if($rIndex == count($nxo) - 1) { $fnt = 3; //to use preloaded fonts, 1 - 5 only. 1 is tiny, 2 is decent, 3-5 are bolder/worse } if($rIndex==0) { $y=$padding["top"]; } else { $y=($padding["top"]+$rIndex*$charHeight); } imagestring($im, $fnt, $padding["left"], $y, $line, $text_color); } imagepng( $im, $path . $file_name . '.png' ); } ?> Here is generate_image.php (this generates the PNG file)-: <?php require_once 'include/db.php'; require_once 'nfo2png.php'; $file = explode( '.', $_FILES['user_file']['name'] ); $original_file_name = $_FILES['user_file']['name']; $valid_file_types = array( 'txt', 'nfo', 'diz' ); $found = false; foreach ( $valid_file_types AS $valid_file_type ) { if ( strtoupper( $file[count($file)-1] ) == strtoupper( $valid_file_type ) ) { $found = true; break; } } if ( !$found ) { // echo '0|File must be one of the following types: ' . implode( ', ', $valid_file_types ); die( '0|File must be one of the following types: ' . implode( ', ', $valid_file_types ) ); } $content = file_get_contents( $_FILES['user_file']['tmp_name'] ); $file_name = 'image_' . str_replace( '.', '', microtime(true) ); buildNFONew(800, "20 50 20 50", $content, '[Generated by: NFOPic.com]', $_POST['fg_color'], $_POST['bg_color'], $file_name); echo '1|'.$file_name . '.png|'.$original_file_name; // if ( !is_local() ) if($conn) { $sql = "INSERT INTO nfo_images (original_file_name, file_name, user_ip) VALUES ( '" . mysqli_real_escape_string( $original_file_name ) . "', '" . mysqli_real_escape_string( $file_name.'.png' ) . "', '" . $_SERVER['REMOTE_ADDR'] . "' ) "; // echo $sql; // mysql_query( $sql ); $conn->query( $sql ); } and get_image.php (shows the link to the PNG image to hotlink or download, etc) -: <?php require_once 'include/db.php'; $file_name = $_GET['f']; if ( empty( $file_name ) || !file_exists( 'uploads/' . $file_name )) { die( 'File not found...' ); } $sql = "SELECT original_file_name FROM nfo_images WHERE file_name = '" . $file_name . "'"; $rs = mysql_query( $sql ); $file = mysql_fetch_assoc( $rs ); $original_file_name = explode( '.', $file['original_file_name'] ); //just get rid of the last, then put back together array_pop( $original_file_name ); $original_file_name = implode( '.', $original_file_name ); header("Content-Type: image/png"); //start edit 10.07.2014 DrTech76, flow the direct image link through here to keep the actuall location unknown if(!isset($_REQUEST["dl"])) {//it's not a request through a direct link, so process as file download, as it was originally header("Content-Disposition: attachment; filename=\"" . $original_file_name . ".png\""); } //end edit 10.07.2014 DrTech76, flow the direct image link through here to keep the actuall location unknown echo file_get_contents( 'uploads/' . $file_name ); ?> I hope someone can help figure this out, you can see live version of the site, to see the trouble, no matter what i change 1-5 to, only the 'footer' [GFenerated By: NFOPic] changes size..... so i'm thinking create a whole new monospaced ascii style bitmap font file like the one the original coder produced...... but not sure how. this is a community project going back years,, just re-launched it as i'm going back to learning php/mysql again after years in JS/jQuery/AJAX/CSS (UX Design & Illustration).... VERY GRATEFUL FOR ANNNNNY HELP! CAN HELP YOU OUT IN RETURN I HOPE, HAVE SOME GREAT RESOURCES, THOUGH LOVE HELP 4 HELP.... GREAT AT ILLUSTRATION!!!! LOGOS ETC.
  2. Welcome, Me too, learning the same as you, but have bavkground in HTML/CSS & can "Read" PHP just getting hang of writing it out so it is structured (alot like a sentence when u can read, but need help with writing sentences is the way i put it lol) ... I found a Collaborative of like-minded individuals who help on projects etc, we help each other out, there used to be a site called forrst.me (the old one, before new owners), we got the Crowd-Sourced/Community-Based idea from them to help eaxh other learn and help with each others projects, it's been going good for a few years, but now i'm going from front-end design, as loosing my mates to covid crisis to help with my problems, sp phpFreaks seems like the BB to ask PHP/mySQL based questions for my current 1st project :-) GOOD LUCK, feel free to ask for help over my way, if i can i will!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.