How to add template in codeigniter |how to create template in codeigniter| template in codeigniter 4
capture screenshot
In this tutorial ,Today I am going to discuss on a topic , How to capture screenshot of website using google api in php.There are so many extension and third party api available for that.Here I am using google api for that.
Screenshot is a visual element that meant for capturing what’s immediately visible on the browser.To take the screenshot you must a valid url for that with http.
Example of code
<html> <head> <title>Take website screen shot</title> </head> <body> <form method="post"> Website url: <input type="text" name="url"><br><br> <input type="submit" name="submit" value="Take screenshot"> </form> </body> </html>
<?php if(isset($_POST['submit'])) { $url=$_POST['url']; $api_response = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$url&screenshot=true"); //decode json data $result = json_decode($api_response, true); //screenshot data $screenshot = $result['screenshot']['data']; $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); //display screenshot image echo "<img src=\"data:image/jpeg;base64,".$screenshot."\" style='width:100%;height:100%'/>"; } ?>
That’s all.
Related posts
Hey! I could have sworn I’ve been to this website before but after
checking through some of the post I realized it’s new to
me. Nonetheless, I’m definitely glad I found it and I’ll
be book-marking and checking back often!