1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Website Screenshot Script

Discussion in 'PHP' started by mudanoman, Jun 28, 2006.

  1. marcel

    marcel Well-Known Member

    Messages:
    1,503
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    150
    #21
    marcel, Jan 1, 2008 IP
    SEMrush
  2. commandos

    commandos Notable Member

    Messages:
    3,652
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #22
    nothing to do with php ...
     
    commandos, Jan 1, 2008 IP
  3. vsingh69

    vsingh69 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #23
    PHP like any scripting language has all the features.certainly thumbsnail scripts are there.
     
    vsingh69, Jan 2, 2008 IP
  4. commandos

    commandos Notable Member

    Messages:
    3,652
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #24
    FIND IT :D
     
    commandos, Jan 3, 2008 IP
  5. thapame

    thapame Well-Known Member

    Messages:
    739
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    180
    #25
    thapame, Jan 6, 2008 IP
  6. commandos

    commandos Notable Member

    Messages:
    3,652
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #26
    That's not based on php ;)
     
    commandos, Jan 6, 2008 IP
  7. thapame

    thapame Well-Known Member

    Messages:
    739
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    180
    #27
    creating an php screenshot application is not an easy task. for that you must have dedicated application or you must use services provided by another providers. :)
     
    thapame, Jan 6, 2008 IP
  8. Andy Peters

    Andy Peters Peon

    Messages:
    430
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #28
    I don't know that it would be impossible with PHP, certainly not if it could call on an external program.
    I mean, you only have to use curl to get the html source, then convert the html to image before resizing it with gd library.
    If you could write a command line program (or if one exists) to convert html to jpg your laughing.
     
    Andy Peters, Jan 18, 2008 IP
  9. dsiembab

    dsiembab Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #29
    I've been tinkering with this idea myself and wrote this but after writing it I contact the service provider and they told me I could not use it
    it was basically a webservice that showed you your page in IE7 and I thought I would be a smart ass and grab the images and shrink them to thumbnail size. I guess I should get permission first back to the drawing board I was thinking of getting the html for the page and then getting the stylesheet pregmatch all the div's with the ones on the stylesheet and then using gd to render the appropriate sizes and for the dives and a couple of switch casses for if a div is in a div or span basically every webpage start with the either the html size, body size or a container size of some sortlike if you have float:left; and capture all the attributes for that div get the width limits by the containing div if the width is the same than on if another occurence of the div shows up than move said div down if the containing box is is less than the div's I'll let you know how much it is worth when I am done. kidding of course os
     
    dsiembab, Mar 6, 2008 IP
  10. Andy Peters

    Andy Peters Peon

    Messages:
    430
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #30
    There is imagegrabwindow in GD library but it only works on windows.
     
    Andy Peters, Mar 6, 2008 IP
  11. dotWdot

    dotWdot Peon

    Messages:
    685
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #31
    andy peters can i just say you have the best name/emoticon combo i have seen on dp....lol

    I have got imagegrabwindow and imagegrabscreen working - they are slow but useful ;)
     
    dotWdot, May 13, 2008 IP
    Andy Peters likes this.
  12. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #32
    It's buggy, it's restrictive, and limited to certain systems. Oh, and some of the code is weird.
    But it works, for me.

    http://danltn.com/bin/8g9.phps

    Windows, PHP 5.2.2+ only, GD Lib, Working IE with desktop access.

    (Yeah, I'll finish it when my exams are over.)

    
    <?php
    
    /**
     * Danltn | http://danltn.com/
     * MSN: msn[at]danltn.com
     * Email: daniel[at]neville.tk
     * Tested: Yes
     * Extra Details: Buggy
     * PHP 4/5: 5.2.2+
     * No warranty is given to code used. AT ALL. I MEAN IT! USE IT AT YOUR OWN RISK!
     */
    
    set_time_limit(120);
    
    class screenshot
    {
        protected $started = false;
    
        public static $image = null;
        public $details = array();
    
        public $pagecontent = false;
    
        public static $manipulate;
    
        protected $IE = null;
        protected $url = false;
    
        protected static $instance;
    
        protected $visible = false;
        protected $fullscreen = false;
        protected $height = false;
        protected $width = false;
        protected $silent = false;
        protected $status_bar = false;
        protected $address_bar = false;
        protected $top = false;
        protected $left = false;
        protected $resizable = false;
        protected $theatermode = false;
        protected $toolbar = false;
    
        public $pump = false;
    
        public function __construct($pump = false, $width = false, $height = false)
        {
            $this->started = true;
            $this->check_compatibility() or die($this->error('PHP too old or functions missing!'));
            register_shutdown_function(array(&$this, "__destruct"));
            $this->start_ie();
            $this->set_visible(true);
            $this->size($height, $width);
            if ($pump)
            {
                $this->pump = true;
            }
            return $this;
        }
    
        public function manipulate($image = null)
        {
            $this->manipulate = new manipulate($image);
            return $this;
        }
    
        public function manipulate_end($image = null)
        {
            if ($image)
            {
                $this->image = $image;
            }
            $this->manipulate = null;
            unset($this->manipulate);
        }
    
        public function getimage()
        {
            return ($this->image) ? $this->image : false;
        }
    
        public function navigate($url = 'about:blank')
        {
            $url = ($url) ? $url : 'about:blank';
            $this->IE->Navigate(($url) ? $url : 'about:blank');
            $this->url = $url;
            $time = time();
            while ($this->IE->ReadyState != '4' and $time + 10 > time())
            {
                $this->pump();
            }
            if ($this->pump)
            {
                $this->pump(1000);
            }
        }
    
        public function silent($silent = true)
        {
            if ($silent == SWAP)
            {
                $this->IE->Silent = !$this->silent;
                $this->silent = !$this->silent;
            }
            else
            {
                $this->IE->Silent = (bool)$silent;
                $this->silent = (bool)$silent;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function get_handle()
        {
            return $this->IE->HWND;
        }
    
        private function check_compatibility()
        {
            if (version_compare(phpversion(), "5.2.2", "<"))
            {
                $this->error('PHP Version too old, 5.2.2 required.', 1);
                return false;
            }
            if (!function_exists('imagegrabwindow') or !function_exists('com_message_pump') or !function_exists('imagepng') or !class_exists('COM'))
            {
                $this->error('Required PHP functions missing.', 1);
                return false;
            }
    
            return true;
        }
    
        public function start_ie()
        {
            $this->IE = new COM("InternetExplorer.Application") or die($this->error('Could not start Internet 
    
    Explorer instance.'));
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function quit()
        {
            if (isset($this->IE))
            {
                if (is_object($this->IE))
                {
                    $this->IE->Quit();
                }
                $this->IE = null;
                unset($this->IE);
            }
            return $this;
        }
    
        public function details()
        {
            $this->details['path'] = $this->IE->Path;
            $this->details['fullname'] = $this->IE->FullName;
            $this->details['name'] = $this->IE->Name;
            $this->details['offline'] = $this->IE->Offline;
            return $this;
        }
    
        public function set_visible($visible = true)
        {
            if ($visible == SWAP)
            {
                $this->IE->Visible = !$this->visible;
                $this->visible = !$this->visible;
            }
            else
            {
                $this->IE->Visible = (bool)$visible;
                $this->visible = (bool)$visible;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function set_resizable($resizable = true)
        {
            if ($resizable == SWAP)
            {
                $this->IE->Resizable = !$this->resizable;
                $this->resizable = !$this->resizable;
            }
            else
            {
                $this->IE->Resizable = (bool)$resizable;
                $this->resizable = (bool)$resizable;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function status_bar($status_bar = false)
        {
            if ($status_bar == SWAP)
            {
                $this->IE->StatusBar = !$this->status_bar;
                $this->status_bar = !$this->status_bar;
            }
            else
            {
                $this->IE->StatusBar = (bool)$status_bar;
                $this->status_bar = (bool)$status_bar;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function address_bar($address_bar = false)
        {
            if ($address_bar == SWAP)
            {
                $this->IE->AddressBar = !$this->address_bar;
                $this->address_bar = !$this->address_bar;
            }
            else
            {
                $this->IE->AddressBar = (bool)$address_bar;
                $this->address_bar = (bool)$address_bar;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function set_fullscreen($fullscreen = true)
        {
            if ($fullscreen == SWAP)
            {
                $this->IE->Fullscreen = !$this->fullscreen;
                $this->fullscreen = !$this->fullscreen;
            }
            else
            {
                $this->IE->Fullscreen = (bool)$fullscreen;
                $this->fullscreen = (bool)$fullscreen;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function set_toolbar($toolbar = true)
        {
            if ($toolbar == SWAP)
            {
                $this->IE->ToolBar = !$this->toolbar;
                $this->toolbar = !$this->toolbar;
            }
            else
            {
                $this->IE->ToolBar = (bool)$toolbar;
                $this->toolbar = (bool)$toolbar;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function go($where = '', $times = 1)
        {
            $where = ucfirst(strtolower(($where)));
            if (!in_array($where, array('Home', 'Back', 'Forward')))
            {
                $where = 'Back';
            }
            $do = 'Go' . $where;
            for ($i = 0; $i < $times; $i++)
            {
                $this->IE->$do();
            }
        }
    
        public function document($element, $set)
        {
            eval('$this->IE->document->' . $element . ' = $set;');
            /* I hate eval too, but I couldn't think of another way of doing this without going into a
    
            ridiculous loop, any ideas? */
            return $this;
        }
    
        public function body($element, $set)
        {
            eval('$this->IE->document->body->' . $element . ' = $set;');
            /* I hate eval too, as above */
            return $this;
        }
    
        public function set_theatermode($theatermode = true)
        {
            if ($theatermode == SWAP)
            {
                $this->IE->TheaterMode = !$this->theatermode;
                $this->theatermode = !$this->theatermode;
            }
            else
            {
                $this->IE->TheaterMode = (bool)$theatermode;
                $this->theatermode = (bool)$theatermode;
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function title($title)
        {
            $this->IE->document->title = $title;
            return $this;
        }
    
        public function content($content)
        {
            $this->IE->document->body->InnerHTML = $content;
            return $this;
        }
    
        public function size($height = false, $width = false)
        {
            if (!$height and !$this->height)
            {
                $this->height = 600;
                $this->IE->Height = 600;
            } elseif ($height)
            {
                $this->height = intval($height);
                $this->IE->Height = intval($height);
            }
    
            if (!$width and !$this->width)
            {
                $this->width = 600;
                $this->IE->Width = 600;
            } elseif ($width)
            {
                $this->width = intval($width);
                $this->IE->Width = intval($width);
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        public function position($top = false, $left = false)
        {
            if (!$left and !$this->left)
            {
                $this->left = 100;
                $this->IE->Left = 100;
            } elseif ($left)
            {
                $this->left = intval($left);
                $this->IE->Left = intval($left);
            }
    
            if (!$top and !$this->top)
            {
                $this->top = 100;
                $this->IE->Top = 100;
            } elseif ($top)
            {
                $this->top = intval($top);
                $this->IE->Top = intval($top);
            }
            if ($this->pump)
            {
                $this->pump();
            }
            return $this;
        }
    
        private function error($errmsg = '', $die = 0)
        {
            if (!$errmsg)
            {
                $errmsg = 'An unspecified error occured.';
            }
            echo '<h1>Error</h1><h2>' . $errmsg . '</h2>';
            if ($die) die();
            return false;
        }
    
        public function pump($time = 100, $force = 0)
        {
            if ($force == 1)
            {
                com_message_pump(intval($time));
            }
            while ($this->IE->Busy)
            {
                com_message_pump(intval($time));
            }
        }
    
        public function capture($what = WINDOW)
        {
            if (!$this->visible)
            {
                $this->set_visible(true);
                $reset_visible = true;
            }
            $this->image = null;
            $this->pump(500);
            $function = 'imagegrab' . (($what == 3 or strtolower($what) == 'screen') ? 'screen' : 'window');
            $im = $function($this->IE->HWND, 0);
            $this->image = $im;
            if (isset($reset_visible))
            {
                $this->set_visible(false);
            }
            return $this;
        }
    
        public function output($imagetype = 'png')
        {
            if (!$this->image)
            {
                $this->capture();
            }
            if ($imagetype == 'jpg')
            {
                $imagetype = 'jpeg';
            }
            if (!in_array($imagetype, array('jpeg', 'gif', 'png')))
            {
                $imagetype = 'png';
                /* We know this one works */
            }
            $function = 'image' . $imagetype;
            header('Content-type: image/' . $imagetype);
            $function($this->image);
        }
    
        public function __toString()
        {
            if ($this->image)
            {
                echo $this->image;
            } elseif ($this->url)
            {
                echo $this->url;
            }
            else
            {
                echo '';
            }
            return $this;
        }
    
        public function save($file, $imagetype = 'png')
        {
            if (!$this->image)
            {
                $this->capture();
            }
            if ($imagetype == 'jpg')
            {
                $imagetype = 'jpeg';
            }
            if (!in_array($imagetype, array('jpeg', 'gif', 'png')))
            {
                $imagetype = 'png';
                /* We know this one works */
            }
            $function = 'image' . $imagetype;
            $function($this->image, $file);
        }
    
        final public static function getInstance()
        {
            if (!isset(self::$instance))
            {
                $c = __class__;
                $instance = new $c;
            }
            return self::$instance;
        }
    
        public function __destruct()
        {
            $this->quit();
        }
    }
    
    class manipulate extends screenshot
    {
        public $nimage;
    
        public function __construct($nimage = '')
        {
            if ($nimage)
            {
                $this->setImage = $nimage;
            }
        }
    
        public function setImage($nimage)
        {
            if ($nimage)
            {
                $this->nimage = $nimage;
            }
            return $this;
        }
    
        public function callback()
        {
            return $this->nimage;
        }
    
        public function crop($x = 10, $y = 100, $width = 400, $height = 400)
        {
            $temp = imagecreate($width, $height);
            imagecopy($temp, $this->nimage, 0, 0, $x, $y, $width, $height);
            $this->nimage = $temp;
            return $this;
        }
    
        public function border($px = 5, $colour = array('255', '255', '255'))
        {
            $img_width = $this->getImageWidth() + (2 * $px);
            $img_height = $this->getImageHeight() + (2 * $px);
            $temp = imagecreate($img_width, $img_height);
            $border = imagecolorallocate($temp, $colour[0], $colour[1], $colour[2]);
            if (!is_array($colour))
            {
                $border = imagecolorallocatealpha($temp, 0, 0, 0, 127);
            }
            else
            {
                $border = imagecolorallocate($temp, ($colour[0]) ? $colour[0] : 0, ($colour[1]) ? $colour[1] : 0, ($colour[2]) ? $colour[2] : 0);
            }
            imagefilledrectangle($temp, 0, 0, $img_width, $img_height, $border);
            imagecopy($temp, $this->nimage, $px, $px, 0, 0, $this->getImageWidth(), $this->getImageHeight());
            $this->nimage = $temp;
            return $this;
        }
    
        public function rotate($angle = 90, $bg_colour = 0)
        {
            $this->nimage = imagerotate($this->image, $angle, $bg_colour, 0);
            return $this;
        }
    
        public function quick()
        {
            header('Content-type: image/png');
            imagepng($this->nimage);
        }
    
        private function getImageWidth()
        {
            return (int)imagesx($this->nimage);
        }
    
        private function getImageHeight()
        {
            return (int)imagesy($this->nimage);
        }
    }
    
    function wait($time)
    {
        /* I like the name wait() */
        return sleep($time);
    }
    
    /**
    
    	Example usage:
    
    $screen = new screenshot(true, 720, 500);
    $screen->set_visible(true);
    $screen->navigate('http://google.com');
    $screen->title('You can set custom titles too (and custom body if you want)');
    $screen->position(0, 0);
    $screen->capture();
    $screen->save('image.png');
    $screen->manipulate();
    $screen->manipulate->setImage($screen->getimage());
    $screen->manipulate->crop(10, 100, 685, 390);
    $screen->manipulate_end($screen->manipulate->callback());
    $screen->output();
    $screen->quit();
    
    */
    
    ?>
    PHP:
     
    Danltn, May 15, 2008 IP
    commandos likes this.
  13. coolcurrent

    coolcurrent Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #33
    Hello,


    Have you completed the script. am getting some errors
     
    coolcurrent, Jan 7, 2011 IP
  14. mr_share

    mr_share Active Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #34
    previous I write follow it is work
    but now, it don't working
    Please help me
     
    mr_share, Mar 12, 2012 IP
  15. MikeWay

    MikeWay Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #35
    I know there's been a few places posted in here, but I found one called MPZImg a few days ago that seems a bit cheaper than most and has some decent PHP examples on there.

    Might have a look at that MS solution tho, is it free?
     
    MikeWay, Feb 19, 2013 IP
  16. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #36
    Ok, let's go pro for a bit (assuming you are going to use a dedicated server or a VPS): http://code.google.com/p/wkhtmltopdf/

    Left menu bar, download the wkhtml2img, install it in your server and bind it via php. Then you create your API and sell access to others :)
     
    YoGem, Feb 23, 2013 IP
    sarahk likes this.
  17. jusob

    jusob Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #37
    You can try https://browshot.com/ (100 free screenshots a month):
    • PHP library at https://github.com/juliensobrier/browshot-php
    • examples using PHP at https://browshot.com/api/libraries/php
    • Full API description at https://browshot.com/api/documentation
     
    jusob, Mar 24, 2013 IP
  18. annaharris

    annaharris Active Member

    Messages:
    119
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    51
    #38
    imagescreengrab - Captures the whole screen - a PHP-script that scrapes 500 different sites and stores the results as thumbnails. Refer this link, you can get some idea from that. http://stackoverflow.com/questions/757675/website-screenshots-using-php
     
    annaharris, Mar 25, 2013 IP
  19. domusmaximus

    domusmaximus Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #39
    The easiest way to create screenshots using a PHP script is to use a third party service like GrabzIt's PHP API: http://grabz.it/api/php/
     
    domusmaximus, May 12, 2014 IP
  20. msx

    msx Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #40
    Even if you be able to get/make script for screenshoting, it's heavy server resource task, and most important, all libraries you need won't be available on shared hosting....been there already :)
    There are few sites giving you API where you can fetch screenshots from them, cost is usually $5 per month...do research
     
    msx, May 15, 2014 IP