0

How can I capture snapshot webpage which is currently in my tab. Please help me, I'm beginner

Salman A
  • 262,204
  • 82
  • 430
  • 521
Muzammil Ahmed
  • 77
  • 1
  • 3
  • 14

2 Answers2

3

Can't comment yet, so I'll post an answer.

A lot depends on what you're trying to do and the system you're using.

imagegrabscreen() & imagegrabwindow() are only available on Windows & PHP 5 >= 5.2.2. If you're getting a blank image with these, you need to configure Apache to 'Allow service to interact with desktop'. Go to Windows Services, find Apache and set that in the Properties.

You could use html2canvas + JavaScript on client side to post the webpage image + PHP on server side to save that image. Here's a Tutorial to do this.

There's also a good discussion of options (some a bit dated now) in this SO question Website screenshots using PHP

Plus, there are plenty free services that provide website screenshot capabilities with a PHP API, like GrabzIt, Websnapr, et al.

Community
  • 1
  • 1
Alla
  • 153
  • 1
  • 6
0

You can try out this code to generate image on the client side, If you are using Juqery then it will be super easy to implement this feature in your application.

Here is the code you can try this out.

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://files.codepedia.info/files/uploads/iScripts/html2canvas.js"></script>
</head>
<body>
<div id="html-content-holder" style="background-color: #F0F0F1; color: #00cc65; width: 500px;
        padding-left: 25px; padding-top: 10px;">
        <strong>WEB Page to Image Conversion</strong><hr/>
        <h3 style="color: #3e4b51;">
            Html to canvas, and canvas to proper image
        </h3>
        <p style="color: #3e4b51;">
            <b>Here </b> is the example of image of text and html page that we are going to use to convert it into the image that you will be able to download and preview here. </p>
        <p style="color: #3e4b51;">
            <b>This html2canvas</b> script allows you to take "screenshots" of webpages containing anything it it., directly on the users browser. It will just capture the html and css that it will find in the DOM.
        </p>
    </div>
    <input id="btn-Preview-Image" type="button" value="Preview"/>
    <a id="btn-To-Convert-Html2Image" href="#">Download</a>
    <br/>
    <h3>Preview :</h3>
    <div id="previewImage">
    </div>


<script>
$(document).ready(function(){


var element = $("#html-content-holder"); // global variable
var getCanvas; // global variable

    $("#btn-Preview-Image").on('click', function () {
         html2canvas(element, {
         onrendered: function (canvas) {
                $("#previewImage").append(canvas);
                getCanvas = canvas;
             }
         });
    });

    $("#btn-Convert-Html2Image").on('click', function () {
    var imgageData = getCanvas.toDataURL("image/png");
    // Now browser starts downloading it instead of just showing it
    var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
    $("#btn-Convert-Html2Image").attr("download", "your_pic_name.png").attr("href", newData);
    });

});

</script>
</body>
</html>