Get QString data from the QPixmap
-
Hi! I want to get
QString
data fromQPixmap
image which was constructed byloadFromData
function.connect(netManager, &QNetworkAccessManager::finished, [this](QNetworkReply *reply) { QByteArray data = reply->readAll(); QPixmap captchaPixmap; captchaPixmap.loadFromData(data); qDebug() << data; }
It's a captcha from the website, from
PHP
script it hasheader("Content-type: image/gif");
So it returns image, also I have the captcha code but it is stored in a$_SESSION
global variable. I can't parse this$_SESSION
variable fromC++
becauseheader("Content-type: image/gif");
loads only images.I want to compare
captcha
data and user input.Any ideas how to do it? Thanks.
-
Hi,
You don't want to QString if you want to access images data. QString as its name suggest is for manipulating strings.
If you want to manipulate the data from the image you should rather use QImage and then you can access the underlying bytes through QImage::bits.
Out of curiosity, why not use something like recaptcha ?
-
Hi,
You don't want to QString if you want to access images data. QString as its name suggest is for manipulating strings.
If you want to manipulate the data from the image you should rather use QImage and then you can access the underlying bytes through QImage::bits.
Out of curiosity, why not use something like recaptcha ?
I will try it. Thanks.
-
Hi,
You don't want to QString if you want to access images data. QString as its name suggest is for manipulating strings.
If you want to manipulate the data from the image you should rather use QImage and then you can access the underlying bytes through QImage::bits.
Out of curiosity, why not use something like recaptcha ?
I have checked your solution, but how to translate those bits to
QString
or something to compare with the user input. I have tried different solutions but it failed. Thanks. -
Do you mean you want to extract the text the user has input stored in the gif ?
-
No, I want extract it to compare with user input from
QLineEdit
text function.So for example, the captcha code: ABCD.
User input: ABCD.
So I can compare it as text or some hash to validate if it matches.qDebug() << data.bits(); // it returns 0xa1ff200
-
QImage::bits
gives you the starting address of the raw image data.Where do you get that gif from ?
-
QImage::bits
gives you the starting address of the raw image data.Where do you get that gif from ?
I parse it from my website.
Here is the some
PHP
code:$_SESSION["image"] = implode('', $cod); // gets code captcha header("Content-type: image/gif"); //loads the captcha image imagegif($src); imagedestroy($src);
I need this -
$_SESSION["image"] = implode('', $cod);
to be parsed so I can compare later with user input.
I use$_SESSION["image"]
to validate captcha code on the website. So I need to parse it to the application but since the header content type is the image, I can't access the captcha code.Another solution is to use this project from GitHub:
QtCaptchaAlso I can port
PHP
captcha generation to theC++
but it will take long. -
What are you using to generate that captcha ?
-
-
So basically, you want to decipher the captcha image you generate client side to check whether the use input is correct ?
-
So basically, you want to decipher the captcha image you generate client side to check whether the use input is correct ?
Yes.
-
You do realise that the goal of the captcha is to make it really difficult for computer to deduce what's on it ?
-
You do realise that the goal of the captcha is to make it really difficult for computer to deduce what's on it ?
Yes, I know it. I think I have the idea how to decipher it. I will try it and reply.
-
You do realise that the goal of the captcha is to make it really difficult for computer to deduce what's on it ?
So my solution is:
I have stored
$_SESSION["image"]
value to the txt file witch is thecaptcha
code. Then I read this file and now get the value to compare with the user input. Also I'm thinking about putting it to the database or restrict access to the file. -
By the way, why do it on the client side ?