skip to main
|
skip to sidebar
Most3
Easy to get, easy to lose
Tuesday, May 29, 2007
how to decode del.icio.us's captcha
This is a uncompleted script, maybe you can help me to finish it.
I try to decode the
del.icio.us's
captcha with the next php script.
/* @author tiekil@gmail.com */
class Code {
protected $_srcFile;
public function __construct($file) {
$this->_srcFile = $file;
}
public function filter() {
$size = getimagesize($this->_srcFile);
$im = imagecreatefrompng($this->_srcFile);
imagejpeg($im, $this->_srcFile . '.jpg', 100); //convert the png to jpeg
$im = imagecreatefromjpeg($this->_srcFile . '.jpg');
for($x=0;$x<$size[0];$x++) {
for($y=0;$y<$size[1];$y++) {
$rgb = imagecolorat($im,$x,$y);
$r = ($rgb >> 16) & 0xFF;
if ($r > 100) { // set the light color to white
$rgb = imagecolorallocate($im, 255, 255, 255);
} else { //javascript:void(0)
Publish Post set the dark color to black
$rgb = imagecolorallocate($im, 0, 0, 0);
}
imagesetpixel($im, $x, $y, $rgb);
# remove the "Z" block
// x-1, y-1 black
$rgb = imagecolorat($im,$x-1,$y-1);
$r1 = ($rgb >> 16) & 0xFF;
// x-1, y white
$rgb = @imagecolorat($im,$x-1,$y);
$r2 = ($rgb >> 16) & 0xFF;
// x, y-1 white
$rgb = @imagecolorat($im,$x,$y-1);
$r3 = ($rgb >> 16) & 0xFF;
if (($r3 == 255) && ($r2 == 255) && ($r1 == 0)) {
$rgb = imagecolorallocate($im, 255, 255, 255);
if ($rgb) {
imagesetpixel($im, $x-1, $y-1, $rgb);
}
}
}
}
# remove others
for($x=0;$x<$size[0];$x++) {
for($y=0;$y<$size[1];$y++) {
$rgb = imagecolorat($im,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$rgb = imagecolorat($im,$x-1,$y);
$r2 = ($rgb >> 16) & 0xFF;
$rgb = imagecolorat($im,$x+1,$y);
$r3 = ($rgb >> 16) & 0xFF;
$rgb = imagecolorat($im,$x,$y-1);
$r4 = ($rgb >> 16) & 0xFF;
$rgb = imagecolorat($im,$x,$y+1);
$r5 = ($rgb >> 16) & 0xFF;
# clean dot
if (($r == 0) && ($r2 == 255) && ($r3 == 255) && ($r4 == 255)
&& ($r5 == 255)) {
$rgb = imagecolorallocate($im, 255,255,255);
imagesetpixel($im, $x, $y, $rgb);
}
# clean bottom border
if (($y == $size[1]-1) && ($r == 0) && ($r2 == 255) && ($r3 == 255)
&& ($r4 == 255)) {
$rgb = imagecolorallocate($im, 255,255,255);
imagesetpixel($im, $x, $y, $rgb);
}
# clean right border
if (($x == $size[0]-1) && ($r == 0) && ($r2 == 255) && ($r4 == 255)
&& ($r5 == 255)) {
$rgb = imagecolorallocate($im, 255,255,255);
imagesetpixel($im, $x, $y, $rgb);
}
}
}
imagejpeg($im, $this->_srcFile . '.new.jpg',100);
}
}
# demo
$code = new Code('1986312480.png');
$code->filter();
?>
before:
after:
No comments:
Post a Comment
Older Post
Home
Subscribe to:
Post Comments (Atom)
Enter your search terms
Submit search form
Labels
cod highlight blogger
(1)
code syntax highlighter blogger
(1)
decode captcha
(1)
delicious
(1)
Fullshape
(1)
Halfshape
(1)
php imagecolorat
(1)
php rand
(1)
random string
(1)
Zend Filter
(1)
Zend Framework
(1)
全角
(1)
半角
(1)
转换
(1)
Archive
May
(4)
Domain Tools
No comments:
Post a Comment