/************************************************************\ * * GD Fontmaker Copyright 2005 Howard Yeend * www.puremango.co.uk * * This file is part of GD Fontmaker. * * GD Fontmaker is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GD Fontmaker is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GD Fontmaker; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * \************************************************************/ if(!empty($_POST['numchars'])) { // create GD image from PNG $im = @ImageCreateFromPNG($_FILES['pngfile']['tmp_name']); if(!$im) { exit("Cannot create image!"); } // get user supplied data $numchars = $_POST['numchars']; $startchar = ord($_POST['startchar']); $pixelwidth = $_POST['pixelwidth']; $pixelheight = $_POST['pixelheight']; // encode this at start of font $fontdata = chr($numchars).chr(0).chr(0).chr(0).chr($startchar).chr(0).chr(0).chr(0).chr($pixelwidth).chr(0).chr(0).chr(0).chr($pixelheight).chr(0).chr(0).chr(0); // loop through each pixel of each character of the PNG // (we know the dimensions of the characters because the user told us what they were) $y=0; $x=0; $start_x=0; for($c=0; $c<$numchars*$pixelwidth ; $c+=$pixelwidth) { for($y=0 ; $y<$pixelheight ; $y++) { for($x=$c ; $x<$c+$pixelwidth ; $x++) { // get colour of this pixel $rgb = ImageColorAt($im, $x, $y); if($rgb==0) { // it's black; font data $fontdata .= chr(255); } else { // it's not black; background $fontdata .= chr(0); } $i++; } } } // remove image from memory ImageDestroy($im); // let user download font header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=font.gdf"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".strlen($fontdata)); echo $fontdata; exit(); } ?>