, October 2002. $Id: render.hack,v 1.6 2006-10-08 11:55:48 cky Exp $ Copyright (c) 2002, 2005, 2006 Chris K. Young. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public Licence as published by the Free Software Foundation; either version 2 of the Licence, or (at your option) any later version. This program 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 Licence for more details. You should have received a copy of the GNU General Public Licence along with this program; if not, write to Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ class render { var $_args; function print_header() {} function _validate_num(&$var, $field, $min, $max, $def = 0, $opt = false) { $val = $_POST[$field]; if (strlen($val)) { if (!is_numeric($val) || $val < $min || $val > $max) return false; $var = $val; return true; } $var = $def; return $opt; } function _validate_str(&$var, $field, $pcre, $def = '', $opt = false) { $val = $_POST[$field]; if (strlen($val)) { if (!preg_match($pcre, $val)) return false; $var = $val; return true; } $var = $def; return $opt; } function _validate_col(&$var, $field, $def = '', $opt = false) { if (!$this->_validate_str($val, $field, '/^#[[:xdigit:]]{6}$/', $def, $opt)) return false; sscanf($val, '#%2x%2x%2x', $r, $g, $b); $var = array($r, $g, $b); return true; } function validate_input() { if ($this->_validate_str($face, 'face', ':^[^/]+$:') && $this->_validate_num($size, 'size', 1, 72) && /* arbitrary */ $this->_validate_str($text, 'text', '//') && $this->_validate_num($angle, 'angle', 0, 360, 0, true) && $this->_validate_num($ls, 'ls', -10, 10, 1, true) && /* arbitrary */ $this->_validate_col($fg, 'fgcol', '#000000', true) && $this->_validate_col($bg, 'bgcol', '#ffffff', true) && $this->_validate_num($pad, 'pad', 0, 64, 0, true)) /* arbitrary */ { $this->_args = array($face, $size, $text, $angle, $ls, $fg, $bg, $pad); return true; } return false; } function process_input() { list($face, $size, $text, $angle, $ls, $fg, $bg, $pad) = $this->_args; $face = "php/$face"; $bbox =& imageftbbox($size, $angle, $face, $text, array('linespacing' => $ls)); if (!$bbox) return; $xs = array($bbox[0], $bbox[2], $bbox[4], $bbox[6]); $ys = array($bbox[1], $bbox[3], $bbox[5], $bbox[7]); $maxx = max($xs); $minx = min($xs); $maxy = max($ys); $miny = min($ys); $im =& imagecreate($maxx - $minx + 1 + 2 * $pad, $maxy - $miny + 1 + 2 * $pad); if (!$im) return; imagecolortransparent($im, imagecolorresolve($im, $bg[0], $bg[1], $bg[2])); $fgcol = imagecolorresolve($im, $fg[0], $fg[1], $fg[2]); if (isset($_POST['frame'])) { imagerectangle($im, $pad, $pad, $maxx - $minx + $pad, $maxy - $miny + $pad, $fgcol); } if (!imagefttext($im, $size, $angle, $pad - $minx, $pad - $miny, isset($_POST['noaa']) ? -$fgcol : $fgcol, $face, $text, array('linespacing' => $ls))) return; header('Content-Type: image/png'); imagepng($im); } function print_form() { $tmpl = new template('The render gimmick'); $tmpl->set_rcsid('$Id: render.hack,v 1.6 2006-10-08 11:55:48 cky Exp $'); $tmpl->print_header(); ?>
The render gimmick allows you to look at a text string rendered in a font of your choice by FreeType. An explanation of the fields is available.
print_footer(); } function print_footer() {} } class render_help { var $tmpl; function render_help() { $this->tmpl = new template('Information on the render gimmick'); $this->tmpl->set_rcsid('$Id: render.hack,v 1.6 2006-10-08 11:55:48 cky Exp $'); } function print_header() { $this->tmpl->print_header(); } function validate_input() { return false; } function process_input() { return; } function print_form() { ?>Here is a description of all the fields. They all have access keys corresponding to the first letter of the field name (the text field has an access key of t); you may be able to, for example, press Alt-r to select the ‘Render now!’ button.
The text, font, and size fields have no defaults, and thus must be filled in for this program to work.