View difference between Paste ID: gp3wFa9M and 2rY80Qaa
SHOW: | | - or go back to the newest paste.
1
<?PHP
2
/**
3-
 * PROJECT CLEVERWEB GENERAL LESSER LICENSE INFORMATION v3.1
3+
 * PROJECT CLEVERWEB GENERAL LESSER LICENSE INFORMATION v2
4
 * ------------------------------------------------------------
5-
 * Copyright (C) 2011-2012 Nicholas Jordon
5+
 * Copyright (C) 2012 Nicholas Jordon
6-
 * All rights reserved
6+
 * http://projcleverweb.com
7-
 * Package: Project CleverWeb
7+
8-
 * http://ProjectCleverWeb.com
8+
 * Licenses: 
9
 *   GNU LESSER GENERAL PUBLIC LICENSE VERSION 3
10-
 * License:
10+
 *   APACHE LICENSE, VERSION 2.0
11
 *
12
 * This software is free software: you can redistribute it
13
 * and/or modify it under both the terms of the GNU Lesser
14-
 * and/or modify it under the terms of the GNU Lesser
14+
15
 * Foundation, version 3 of the License, and the Apache
16-
 * Foundation, version 3 of the License, You may not use this
16+
 * License, version 2.0 of the License; you may not use this
17-
 * software except in compliance with the license.
17+
 * software except in compliance with both licenses.
18
 *
19-
 * You may obtain a copy of the license at:
19+
 * You may obtain a copy of the licenses at:
20-
 *   http://www.gnu.org/licenses/lgpl-3.0.html
20+
 * @Apache v2.0: http://www.apache.org/licenses/LICENSE-2.0
21
 * @GNU LGPL v3: http://www.gnu.org/licenses/lgpl-3.0.html
22
 *
23-
 * software distributed under the license is distributed on
23+
24
 * software distributed under the licenses is distributed on
25-
 * KIND, either express or implied.
25+
26
 * KIND, either express or implied. See the licenses for the
27
 * specific language governing permissions and other details.
28
 *
29
 * Verfication Key: e450edcbe7703e40d9edcf19a18fb4bc
30
 */
31-
 * Multi-Line Text-To-Image Function
31+
32
/**
33-
 * Takes a text string and converts it to 
33+
 * Multi-Line Text-To-Image Function v2
34-
 *   an image.
34+
35
 * Summery: Takes a text string and
36
 *   converts it to an image.
37
 * Notice: Converts \r to \n regardless
38
 *   if it is actual EOL delimiter.
39
 *
40
 * @Param: (string) $string
41
 *   The string to be converted.
42
 * @Param: (int) $font_size
43
 *   Size of the output text.
44
 * @Param: (int) $font_color
45
 *   Hexdecimal color of the font.
46
 * @Param: (int) $bg_color
47
 *   Hexdecimal color of the background.
48
 */
49
50
function txtimg($string,$font_size=5,$font_color='0',$bg_color='f'){
51
  if(strpos($string,"\r")){ // unix/windows compatible
52
    $string = str_replace("\r","\n",$string);
53
  }
54
  $lines=explode("\n",$string);
55
  foreach($lines as $key=>$line){
56
    $linecount++;
57
	if(strlen($line)>strlen($longest)){
58
	  $longest = $line;
59
	}
60-
  $height = bcmul($lheight,$linecount); 
60+
61
	$linearray[$key]=array('txt'=>$line,'len'=>strlen($line));
62
  }
63
  $width = imagefontwidth($font_size)*strlen($longest);
64-
    preg_match("/^#{0,1}([0-9a-f]{1,6})$/i",$hex,$match);
64+
65-
    if(!isset($match[1])){return false;}
65+
  $height = $lheight*$linecount; 
66-
    if(strlen($match[1])==6){
66+
67-
      list($r, $g, $b) = array($hex[0].$hex[1],$hex[2].$hex[3],$hex[4].$hex[5]);
67+
68
    $hex=str_replace('#','',$hex);
69-
    elseif(strlen($match[1])==3){
69+
    $length = strlen($hex);
70-
      list($r, $g, $b) = array($hex[0].$hex[0],$hex[1].$hex[1],$hex[2].$hex[2]);
70+
    if(!$length){return false;} // if null return false
71
    switch($length){ // full
72-
    else if(strlen($match[1])==2){
72+
	  case 6:
73-
      list($r, $g, $b) = array($hex[0].$hex[1],$hex[0].$hex[1],$hex[0].$hex[1]);
73+
	    $r=$hex[0].$hex[1];$g=$hex[2].$hex[3];$b=$hex[4].$hex[5];
74
		break;
75-
    else if(strlen($match[1])==1){
75+
      case 3: // 1/2
76-
      list($r, $g, $b) = array($hex.$hex,$hex.$hex,$hex.$hex);
76+
	    $r=$hex[0].$hex[0];$g=$hex[1].$hex[1];$b=$hex[2].$hex[2];
77
        break;
78-
    else {
78+
      case 2: // partial
79-
      return false;
79+
	    $r=$hex[0].$hex[1];$g=$hex[0].$hex[1];$b=$hex[0].$hex[1];
80
        break;
81-
    $color = array();
81+
      case 1: // single
82-
    $color['r'] = hexdec($r);
82+
	    $r=$hex.$hex;$g=$hex.$hex;$b=$hex.$hex;
83-
    $color['g'] = hexdec($g);
83+
        break;
84-
    $color['b'] = hexdec($b);
84+
    default:
85-
    return $color;
85+
      return false; // if incorrect # of char return false
86
    }
87
    return array('r'=>hexdec($r),'g'=>hexdec($g),'b'=>hexdec($b));
88
  }
89
  $font_color = hextorgb($font_color);
90
  $bg_color = hextorgb($bg_color);
91
  $bg = imagecolorallocate($img,$bg_color['r'],$bg_color['g'],$bg_color['b']);
92
  $color = imagecolorallocate($img,$font_color['r'],$font_color['g'],$font_color['b']);
93
  foreach($linearray as $key=>$value){
94
    $len = $value['len'];
95
	$string = $value['txt'];
96-
	  $ypos = bcmul($key,$lheight);
96+
97
	if($key){
98
	  $ypos = $key*$lheight;
99
	}
100
	imagestring($img,$font_size, 0,$ypos,$string, $color);
101
  }
102
  header("Content-Type: image/png"); // loads faster
103
  imagepng($img);
104
  imagedestroy($img);
105
}
106-
txtimg(
106+
107-
"This is your IP: ".$_SERVER['REMOTE_ADDR'].PHP_EOL.
107+
108-
"This is your User-Agent: ".$_SERVER['HTTP_USER_AGENT'],
108+
foreach($_SERVER as $key => $value){
109-
4,'#ff0000','#444444');
109+
  $str .= $key." = ".$value.PHP_EOL;
110
}
111
txtimg($str,4,'#ff0000');
112
113
?>