I hope all of you are doing well. I am new in PHP. Would anyone please guide me how to take screenshot of a webpage ,crop it at run-time and send it as an email. Basically the idea is that there is a site MEPCO Electricity Bill checker where a MEPCO consumer can check his bill online. I want to take screenshot of a webpage of this website, crop some part and send it as an email to customer.
Now, I am able to take the screenshot and send it as email. But I need to crop some part and this the area where I am stuck.
Following is the code I am using for taking screenshot and sending email.
use JonnyW\PhantomJs\Client;
use PHPMailer\PHPMailer\PHPMailer;
$client = Client::getInstance();
$request = $client->getMessageFactory()->createRequest('https://checkmepcobill.pk', 'GET');
$response = $client->getMessageFactory()->createResponse();
$client->send($request, $response);
if ($response->getStatus() === 200) {
$imageData = $response->getContent();
file_put_contents('screenshot.png', $imageData);
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your_email@gmail.com';
$mail->Password = 'your_email_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('your_email@gmail.com', 'Your Name');
$mail->addAddress('recipient_email@example.com');
$mail->addAttachment('screenshot.png', 'Screenshot.png');
Would anyone plz guide me how to crop some part of the page from all sides. Thanks in advance
source https://stackoverflow.com/questions/75942726/how-to-take-screenshot-of-a-webpage-and-crop-it-in-php
No comments:
Post a Comment