Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
 
5
/**
6
 * Image_Text example.
7
 *
8
 * Example file for the usage of Image_Text.
9
 *
10
 * PHP versions 4 and 5
11
 *
12
 * LICENSE: This source file is subject to version 3.0 of the PHP license
13
 * that is available through the world-wide-web at the following URI:
14
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
15
 * the PHP License and are unable to obtain it through the web, please
16
 * send a note to license@php.net so we can mail you a copy immediately.
17
 *
18
 * @category   Image
19
 * @package    Text
20
 * @author     Tobias Schlitt <toby@php.net>
21
 * @copyright  1997-2005 The PHP Group
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
23
 * @version    CVS: $Id: example.php,v 1.10 2007/04/16 09:52:34 cweiske Exp $
24
 * @link       http://pear.php.net/package/Net_FTP2
25
 * @since      File available since Release 0.0.1
26
 */
27
 
28
// ini_set('include_path', '.:/cvs/pear/Image_Text:/usr/share/pear');
29
 
30
require_once 'Image/Text.php';
31
 
32
function getmicrotime()
33
{
34
    list($usec,$sec) = explode(' ', microtime());
35
    return ((float)$usec+(float)$sec);
36
}
37
 
38
$colors = array(
39
 
40
    1 => '#e8ce7a',
41
    2 => '#7ae8ad'
42
);
43
 
44
$texts[] = "a passion for php"; // Short Text
45
$texts[] = "a good computer is like a tipi - no windows, no gates and an apache inside"; // Normal Text
46
$texts[] = "What is PEAR?\nThe fleshy pome, or fruit, of a rosaceous tree (Pyrus communis), cultivated in many varieties in temperate climates.\nPEAR is a framework and distribution system for reusable PHP components. PECL, being a subset of PEAR, is the complement for C extensions for PHP. See the FAQ and manual for more information."; // Long Text
47
$texts[] = "EXTERIOR: DAGOBAH -- DAY\nWith Yoda\nstrapped to\n\nhis back, Luke climbs up one of the many thick vines that grow in the swamp until he reaches the Dagobah statistics lab. Panting heavily, he continues his exercises -- grepping, installing new packages, logging in as root, and writing replacements for two-year-old shell scripts in PHP.\nYODA: Code! Yes. A programmer's strength flows from code maintainability. But beware of Perl. Terse syntax... more than one way to do it... default variables. The dark side of code maintainability are they. Easily they flow, quick to join you when code you write. If once you start down the dark path, forever will it dominate your destiny, consume you it will.\nLUKE: Is Perl better than PHP?\nYODA: No... no... no. Orderless, dirtier, more seductive.\nLUKE: But how will I know why PHP is better than Perl?\nYODA: You will know. When your code you try to read six months from now...";
48
$texts[] = "1. The idea:\nThe idea is very simple. I wanted to have 2 versions of PHP (4.3.4 and 5.0beta3) running together on 1 maschine, both as Apache 1.3 modules.\n2. Compiling PHP:\nI had a PHP 4.3.4 running on my devbox and compiled a PHP 5 version in addition. This can be managed in a bloody simple way. Download a copy of PHP 5, unpack the archive to any directory. Copy the './configure' statement from your installed PHP version and exchange/create the prefix option, e.g. '--prefix=/usr/php5' and change the '--with-config-file-path' to a different location (e.g. '/etc/php5').\n\nRun the './configure' statement inside the unpack directory using './configure '. You can get a complete list opf PHP 5 supported option with './configure --help'.\n\nPHP 5 make files had been created successfully (most errors shouls result from version conflicts of libraries and header files, you can easiely solve this by installing or compiling new versions of the required packages/development-packages). Now you should run the 'make' statement and get a coffee, during your first PHP 5 compile... ein Wort \nmehr";
49
$texts[] = "1. The idea: \n\n\n\nThe idea is very simple. I wanted to have 2 versions of PHP (4.3.4 and 5.0beta3) running together on 1 maschine, both as Apache 1.3 modules. \n\n \n\n2. Compiling PHP: \n\n \n\nI had a PHP 4.3.4 running on my devbox and compiled a PHP 5 version in addition. This can be managed in a bloody simple way. Download a copy of PHP 5, unpack the archive to any directory. Copy the './configure' statement from your installed PHP version and exchange/create the prefix option, e.g. '--prefix=/usr/php5' and change the '--with-config-file-path' to a different location (e.g. '/etc/php5'). \n\n \n\nRun the './configure' statement inside the unpack directory using './configure '. You can get a complete list opf PHP 5 supported option with './configure --help'. \n\n \n\nPHP 5 make files had been created successfully (most errors shouls result from version conflicts of libraries and header files, you can easiely solve this by installing or compiling new versions of the required packages/development-packages). Now you should run the 'make' statement and get a coffee,\nduring your first PHP 5 compile...";
50
$texts[] = "1. The idea: The idea is very simple. I wanted to have 2 versions of PHP (4.3.4 and 5.0beta3) running together on 1 maschine, both as Apache 1.3 modules. 2. Compiling PHP: I had a PHP 4.3.4 running on my devbox and compiled a PHP 5 version in addition. This can be managed in a bloody simple way. Download a copy of PHP 5, unpack the archive to any directory. Copy the './configure' statement from your installed PHP version and exchange/create the prefix option, e.g. '--prefix=/usr/php5' and change the '--with-config-file-path' to a different location (e.g. '/etc/php5'). Run the './configure' statement inside the unpack directory using './configure '. You can get a complete list opf PHP 5 supported option with './configure --help'. PHP 5 make files had been created successfully (most errors shouls result from version conflicts of libraries and header files, you can easiely solve this by installing or compiling new versions of the required packages/development-packages). Now you should run the 'make' statement and get a coffee, during your first PHP 5 compile...";
51
 
52
$options = array(
53
            'cx'            => 300,
54
            'cy'            => 300,
55
            'canvas'        => array('width'=> 600,'height'=> 600),
56
            'width'         => 300,
57
            'height'        => 300,
58
            'line_spacing'  => 1,
59
            'angle'         => 0,
60
            'color'         => $colors,
61
            'background_color' => '#FF0000', //red background
62
            'max_lines'     => 100,
63
            'min_font_size' => 2,
64
            'max_font_size' => 50,
65
            'font_path'     => './',
66
            'antialias'     => true,
67
            'font_file'     => 'Vera.ttf',
68
            'halign'        => IMAGE_TEXT_ALIGN_LEFT
69
        );
70
 
71
$text = $texts[array_rand($texts)];
72
 
73
foreach ($_GET as $key => $val) {
74
    switch ($key) {
75
        case 'font_size':
76
            $options['font_size'] = (int)$val;
77
            break;
78
        case 'line_spacing':
79
            $options['line_spacing'] = $val;
80
            break;
81
        case 'halign':
82
            $options['halign'] = $val;
83
            break;
84
        case 'valign':
85
            $options['valign'] = $val;
86
            break;
87
        case 'angle':
88
            $options['angle'] = $val;
89
            break;
90
        case 'text':
91
            $text = $texts[$val];
92
            break;
93
    }
94
}
95
 
96
$start = getmicrotime();
97
 
98
$itext = new Image_Text($text, $options);
99
 
100
$ret = $itext->init();
101
if (PEAR::isError($ret)) {
102
    echo $ret->getMessage() . "\n";
103
    die();
104
}
105
 
106
if (empty($options['font_size'])) {
107
    $itext->autoMeasurize();
108
} else {
109
    $itext->measurize();
110
}
111
 
112
$itext->render();
113
 
114
$end = getmicrotime();
115
 
116
$time = $end - $start;
117
 
118
if (isset($_GET['debug'])) {
119
    echo "<h1>-- DEBUGGING MODE --</h1>";
120
} else {
121
 
122
    $img =& $itext->getImg();
123
 
124
    $red = imagecolorallocate($img, 255, 0, 0);
125
 
126
    imagefilledellipse($img, 300, 300, 10, 10, $red);
127
 
128
    if (isset($_GET['info'])) {
129
        imagettftext($img, 10, 0, 10, 550, $red, "./Vera.ttf", "$time sec.");
130
    }
131
 
132
    $itext->display();
133
 
134
}
135
 
136
?>