<?php
class
image{
session_start();
static
public
function
verify(
$code
,
$width
=75,
$height
=25,
$n
=4){
header(
"content-type:image/png"
);
$img
=imagecreatetruecolor(
$width
,
$height
);
$bgcolor
=imagecolorallocate(
$img
,mt_rand(200,255),mt_rand(200,255),rand(200,255));
imagefill(
$img
,0,0,
$bgcolor
);
for
(
$i
=0;
$i
<5;
$i
++){
$arccolor
=imagecolorallocate(
$img
,mt_rand(200,255),mt_rand(200,255),rand(200,255));
imagearc(
$img
,mt_rand(5,(
$width
-5)),mt_rand(5,(
$height
-5)),mt_rand(5,(
$width
-5)),mt_rand(5,(
$height
-5)),mt_rand(0,360),mt_rand(0,360),
$arccolor
);
}
for
(
$i
=0;
$i
<100;
$i
++){
$pixelcolor
=imagecolorallocate(
$img
,mt_rand(200,255),mt_rand(200,255),rand(200,255));
imagesetpixel(
$img
,mt_rand(1,(
$width
-1)),mt_rand(1,(
$height
-1)),
$pixelcolor
);
}
for
(
$i
=0;
$i
<5;
$i
++){
$linecolor
=imagecolorallocate(
$img
,mt_rand(200,255),mt_rand(200,255),rand(200,255));
imageline(
$img
,mt_rand(1,(
$width
-1)),mt_rand(1,(
$height
-1)),mt_rand(1,(
$width
-1)),mt_rand(1,(
$height
-1)),
$linecolor
);
}
$bdcolor
=imagecolorallocate(
$img
,mt_rand(150,200),mt_rand(150,200),rand(150,200));
imagerectangle(
$img
,0,0,(
$width
-1),(
$height
-1),
$bdcolor
);
$str
='';
for
(
$i
=1;
$i
<=
$n
;
$i
++){
$str
.=
substr
(
str_shuffle
(
$code
),0,1);
}
$_SESSION
['a']=
$str
;
for
(
$i
=0;
$i
<
$n
;
$i
++){
$textcolor
=imagecolorallocate(
$img
,mt_rand(100,150),mt_rand(100,150),mt_rand(100,150));
imagettftext(
$img
,1/(
$n
+1)*
$width
,mt_rand(-20,20),((1-
$n
/(5+
$n
))*
$width
/(
$n
-1)+
$i
*1/(
$n
+1)*
$width
),1/2*(
$height
+3/5*
$height
),
$textcolor
,'1.ttf',
substr
(
$str
,
$i
,1));
}
imagepng(
$img
);
imagedestroy(
$img
);
return
$str
;
}
static
public
function
thumbnail(
$source
,
$deletesource
=false,
$width
=180){
$info
=
getimagesize
(
$source
);
$createFun
=
str_replace
('/','createfrom',
$info
['mime']);
$src
=
$createFun
(
$source
);
$dst_w
=
$width
;
$dst_h
=
$width
/
$info
[0]*
$info
[1];
$dst
=imagecreatetruecolor(
$dst_w
,
$dst_h
);
imagecopyresampled(
$dst
,
$src
,0,0,0,0,
$dst_w
,
$dst_h
,
$info
['0'],
$info
['1']);
$saveFun
=
str_replace
('/','',
$info
['mime']);
$ext
=
strrchr
(
$source
,'.');
$thumbnailName
=
str_replace
(
$ext
,'',
$source
).'_thumbnail'.
$ext
;
if
(!
$deletesource
){
$saveFun
(
$dst
,
$thumbnailName
);
}
else
{
$saveFun
(
$dst
,
$thumbnailName
);
unlink(
$source
);
}
imagedestroy(
$src
);
imagedestroy(
$dst
);
return
$thumbnailName
;
}
static
public
function
watermark(
$dstimg
,
$srcimg
){
$dstinfo
=
getimagesize
(
$dstimg
);
$srcinfo
=
getimagesize
(
$srcimg
);
$createdst
=
str_replace
('/','createfrom',
$dstinfo
['mime']);
$createsrc
=
str_replace
('/','createfrom',
$srcinfo
['mime']);
$dst
=
$createdst
(
$dstimg
);
$dst_w
=imagesx(
$dst
);
$dst_h
=imagesy(
$dst
);
$src
=
$createsrc
(
$srcimg
);
$src_w
=imagesx(
$src
);
$src_h
=imagesy(
$src
);
$watermaker
=imagecopy(
$dst
,
$src
,(
$dst_w
-
$src_w
),(
$dst_h
-
$src_h
),0,0,
$src_w
,
$src_h
);
$saveFun
=
str_replace
('/','',
$dstinfo
['mime']);
$ext
=
strrchr
(
$dstimg
,'.');
$watermaker
=
str_replace
(
$ext
,'',
$dstimg
).'_water'.time().
$ext
;
$saveFun
(
$dst
,
$watermaker
);
imagedestroy(
$dst
);
imagedestroy(
$src
);
return
$watermaker
;
}
}
?>