3

I want to see if I can solve captchas with PHP for a bit of a personal challenge. Nothing too hard; words in the same line, words always in same colour, etc. Here's an example.

http://www.simplyshows.com/img.jpg

Just wanted to see how hard would it be. My question is, are there PHP based function which I can use to check pixel by pixel for colour etc? I want to divide the letters and then do a load of checks to determine if the letter is upper case, lower case, and what it can be (depending on coordinates on colours)

4
  • +1 - It would be pretty cool to see a solution! It would definitely be hard though. Very hard. Commented Nov 27, 2011 at 1:14
  • yeah, well I want to devide the image into 5 parts(as its 5 letters) then process each one seperatly and check for letter paterns in each one, still researching! Commented Nov 27, 2011 at 1:19
  • If it's always black font on bright background, simply change the pixels with bright colors to white and you have the letters only. Next step is the OCR part. I wrote a similar captcha parser with this approach, worked nice expect for the case the letters cross each other. Commented Nov 27, 2011 at 1:27
  • MMm, i'm decreasing quality as the letters have different shades of black, then making array of all letters cordinates(where the black is) and then writing a function to scan from left to right and make array then just match it to the letter array, hard to explain, should work like a charm tho :) Commented Nov 27, 2011 at 4:01

4 Answers 4

4

If you're really interested in solving it from the ground up like this, start with libraries like GD and ImageMagick.

If you're interested in getting it done faster by leveraging the work of others, use Google or StackOverflow to see if there's a usable OCR library/project for PHP.

Lastly, I know you said you just want to do it for fun. Still, PHP has many strengths, but I don't think I would choose it for heavy-duty image processing and AI. You may wish to consider other languages with more robust and rich support for those sorts of things if you find yourself getting serious about this. But if it's just for fun, well, have fun!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, going to have a look, it's just for a bit of fun, not making a decaptcher sort of website, so PHP should be just fine, thanks!
2

imagecolorat (http://php.net/manual/en/function.imagecolorat.php) is what you want.

Comments

1

I have done something similar , although it seems pretty hard there is a solution: As you can see the letters in your image are written with a spefic color, that means that your php script will look for pixels with a specific hex color value. Now imagine that you have your captcha image zoomed x100 You will see the letters pixelated, imagine also a big 2 dimensional square array each block has an id ( i x j). In the image that I have attached that I have managed to create the letter "T" in a 10x10 array, using the id of each square i can make patterns for each letter and number. Using gd library you can achieve many things, don't bother to ask any other questions, I have just vage you the main frame GD Library manual

Image

Comments

1

Using PHP to do this kind of thing is a very good way to turn your server into a grill ;) Your best bet if you want something that is realistically usable then you probably want call a binary using exec() - write it in C or whatever and then call that from PHP. The only direct way using vanilla PHP I can think of is to read the hex from the image and use the resulting "text file" to do the analysis on, but it won't be pretty.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.