PHP 将 GD 图像转换为用于验证码的 CSS 代码
为了生成难以被机器破解的验证码,我计划将文本图像(仅限黑白)转换为 CSS 代码以显示给用户。
所以这个问题有两个方面:
- 让验证码难以被机器读取是个好主意吗?
- 如果是这样,将 GD 图像转换为 CSS 的最佳方法是什么?
我计划循环遍历图像中的所有像素,检查它们是否是黑色的,如果是黑色的,则将像素写入 CSS 中。但我不知道如何在CSS中编写黑色像素(我的CSS技能缺乏。)所以对于我的第二个问题,我想知道如何在CSS中编写黑色像素。除非有人对生成 CSS 代码有更好的想法,或者已经存在一个工具可以做到这一点。
请注意,我正在构建自己的验证码系统,因为除了我自己的目的之外,我将使用输入的输入将文本图像转换为文本(就像使用 ReCAPTCHA 系统所做的那样)。所以我必须自己构建验证码系统。
For generating captchas which would be difficult to be cracked by a machine, I plan to convert images of text (B&W only) into CSS code to be displayed to the user.
So there are 2 aspects to this question:
- Is this a good idea to make the captcha difficult to be read by a machine?
- If so, what would be the best way of converting the GD image to CSS?
I plan to loop through all pixels in the image, check if they are black, and if so then write the pixel in CSS. But I don't know how to write black pixels in CSS (my CSS skills are lacking.) So for my second question, I would like to know how to write black pixels in CSS. Unless someone has a better idea for generating the CSS code, or if there exists a tool to do this already.
Please note that I am building my own CAPTCHA system, as I will be using the entered input to convert images of text into text (just like is done with the ReCAPTCHA system) except for my own purposes. So I must build the CAPTCHA system myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完全不知道如何将图像转换为CSS。它只会增加大量额外的开销并造成 CSS 的混乱,同时不会增加任何实际价值。通过混淆实现的安全性很差——尤其是在这里。
此外 - 是什么让你认为验证码破解软件不会只是截取你的 CSS 混乱的屏幕截图,然后瞧:将你的验证码作为图像?不要这样做。
如果您只是专注于使您的验证码文本变得复杂,那么您就不会有问题。或者您也可以像大多数人一样 - 使用 reCAPTCHA。
There is absolutely no idea in converting the image to CSS. It just adds lots of extra overhead and creates a gigantic CSS mess, whilst not adding any real value. Security through obfuscation is bad - especially here.
Besides - what makes you think the CAPTCHA cracking software wouldn't just take a screenshot of your CSS mess and voilà: have your CAPTCHA as an image? Don't do it.
If you just focus on making your CAPTCHA text complex, you won't have a problem. Or you could just do as most people do - use reCAPTCHA.
你应该这样做:
这将直接在 HTML 文件中输出图像数据,并且它将显示在大多数浏览器中(可能不是 IE7)。
You should do something like this:
This will output the image data directly in the HTML file, and it will show up in most browsers (maybe not IE7).