forked from sirkris/phpMeow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimal.phpmeow.class.php
190 lines (150 loc) · 4.49 KB
/
animal.phpmeow.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/*
* phpMeow - A Cute and Fuzzy Alternative to CAPTCHA
* Created by Kris Craig. April - July, 2011.
*
* phpMeow is the first fully-functional, secure
* implementation of KittenAuth in PHP.
*
* This software is open-source and you're free to
* use and/or distribute it as you see fit. See
* LICENSE file for more information.
*
* Get the latest version at: http://www.github.com/sirkris/phpmeow
*/
class phpmeow_animal
{
function load_image( $imagepath, $widthmod = 0, $heightmod = 0 )
{
require( "config.phpmeow.php" );
$im = @imagecreatefromjpeg( $imagepath );
if ( !$im )
{
$im = imagecreatetruecolor( $phpmeow_animal_width + $widthmod, $phpmeow_animal_height + $heightmod );
$bgc = imagecolorallocate( $im, 255, 255, 255 );
$tc = imagecolorallocate( $im, 0, 0, 0 );
imagefilledrectangle( $im, 0, 0, $phpmeow_animal_width + $widthmod, $phpmeow_animal_height + $heightmod, $bgc );
imagestring( $im, 1, 5, 5, "Error loading : " . $imagepath, $tc );
}
if ( $widthmod != 0 || $heightmod != 0 )
{
$im_old = $im;
$im = imagecreatetruecolor( $phpmeow_animal_width + $widthmod, $phpmeow_animal_height + $heightmod );
imagecopyresized( $im, $im_old, 0, 0, 0, 0, $phpmeow_animal_width + $widthmod, $phpmeow_animal_height + $heightmod, imagesx( $im_old ), imagesy( $im_old ) );
}
return $im;
}
function add_static( $im )
{
require( "config.phpmeow.php" );
$coefficient = ( imagesx( $im ) * imagesy( $im ) ) / 10;
$static = round( ( mt_rand( $phpmeow_min_static, $phpmeow_max_static ) / 100 ) * $coefficient );
for ( $sloop = 1; $sloop <= $static; $sloop++ )
{
$static_length = mt_rand( 0, $phpmeow_static_max_length );
$static_r = mt_rand( 0, 255 );
$static_g = mt_rand( 0, 255 );
$static_b = mt_rand( 0, 255 );
$static_color = imagecolorallocate( $im, $static_r, $static_g, $static_b );
$static_x1 = mt_rand( 0, imagesx( $im ) );
$static_y1 = mt_rand( 0, imagesy( $im ) );
$static_x2 = mt_rand( $static_x1 - $static_length, $static_x1 + $static_length );
$static_y2 = mt_rand( $static_y1 - $static_length, $static_y1 + $static_length );
imageline( $im, $static_x1, $static_y1, $static_x2, $static_y2, $static_color );
}
return $im;
}
function modify_tint( $im )
{
require( "config.phpmeow.php" );
$tint_r = 0;
$tint_g = 0;
$tint_b = 0;
if ( mt_rand( 1, $phpmeow_tint_probability ) == 1 )
{
$tint_r = mt_rand( 1, $phpmeow_tint_max );
}
if ( mt_rand( 1, $phpmeow_tint_probability ) == 1 )
{
$tint_g = mt_rand( 1, $phpmeow_tint_max );
}
if ( mt_rand( 1, $phpmeow_tint_probability ) == 1 )
{
$tint_b = mt_rand( 1, $phpmeow_tint_max );
}
if ( $tint_r != 0 || $tint_g != 0 || $tint_b != 0 )
{
imagefilter( $im, IMG_FILTER_COLORIZE, $tint_r, $tint_g, $tint_b );
}
return TRUE;
}
function sketch( $im )
{
require( "config.phpmeow.php" );
if ( mt_rand( 1, $phpmeow_sketch_probability ) == 1 )
{
imagefilter( $im, IMG_FILTER_MEAN_REMOVAL );
}
}
function negative( $im )
{
require( "config.phpmeow.php" );
if ( mt_rand( 1, $phpmeow_negative_probability ) == 1 )
{
imagefilter( $im, IMG_FILTER_NEGATE );
}
}
function blur( $im )
{
require( "config.phpmeow.php" );
if ( mt_rand( 1, $phpmeow_blur_probability ) == 1 )
{
if ( mt_rand( 1, 2 ) == 1 )
{
imagefilter( $im, IMG_FILTER_GAUSSIAN_BLUR );
}
else
{
imagefilter( $im, IMG_FILTER_SELECTIVE_BLUR );
}
}
}
function grayscale( $im )
{
require( "config.phpmeow.php" );
if ( mt_rand( 1, $phpmeow_grayscale_probability ) == 1 )
{
imagefilter( $im, IMG_FILTER_GRAYSCALE );
}
}
/* This sends the image directly to the browser! --Kris */
function render( $im )
{
header( "Content-Type: image/jpeg" );
$ok = imagejpeg( $im );
return $ok;
}
/* For the sake of convenience. --Kris */
function create( $imagepath, $widthmod = 0, $heightmod = 0, $skiprender = FALSE )
{
require( "config.phpmeow.php" );
require_once( "imagedir.phpmeow.class.php" );
$imagedir = new phpmeow_imagedir();
if ( !( $animals = $imagedir->load_cute_fuzzy_animals( $phpmeow_animalsdir ) ) )
{
return FALSE;
}
$im = self::load_image( $imagepath, $widthmod, $heightmod );
$im = self::add_static( $im );
self::modify_tint( $im );
self::sketch( $im );
self::negative( $im );
self::blur( $im );
self::grayscale( $im );
if ( $skiprender == FALSE )
{
self::render( $im );
}
return $im;
}
}