Taking website screenshot, server-side, on a Linux rented server, free
Asked Answered
S

5

10

Ok so, right now I can't really afford to pay for any service. I want to be able to take screenshots using my rented server, which is Linux based, and output them on the screen.

I know there are a lot of services that do this, but they usually have limits or watermarks, or you have to wait for your screenshot to be taken from the queue.

Is there any way to just take the screenshots myself and maybe later cache them or anything? I'm using PHP, but I'm not limited to it; I'm just on a Linux server so GD's appropriate functions wouldn't work. Help! :)

Synonymize answered 27/7, 2010 at 11:9 Comment(0)
V
10

PhantomJs is the solution

if(phantom.state.length === 0){
  phantom.state = '0_home';
  phantom.open('http://www.mini.de');
}
else if(phantom.state === '0_home'){
  phantom.viewportSize = {width: 800, height: 600};
  phantom.sleep(2000);
  phantom.render('home.png');
  phantom.exit(0);
}
Verena answered 18/10, 2011 at 22:7 Comment(1)
I think phantomjs should work no problem. If webkit can render the page, phantomjs should be able to take a screenshot.Verena
S
9

http://cutycapt.sourceforge.net/

CutyCapt is a small cross-platform command-line utility to capture WebKit's rendering of a web page into a variety of vector and bitmap formats, including SVG, PDF, PS, PNG, JPEG, TIFF, GIF, and BMP.

There is no PHP-api, but you can always use it through PHP's exec functions.

Snide answered 27/7, 2010 at 12:33 Comment(2)
Think I'd be able to run it with a hosted server?Synonymize
Timthumb provides access to cutycapt, which may help with the "no PHP-api" problem.Dimerous
S
5

Here is a better script using phantomJS 1.5

var page = require('webpage').create();

page.open('http://www.google.com', function() {

    page.viewportSize = {width: 1024, height: 768};
    page.render('screenshot.png');
    phantom.exit();
});
Sibert answered 19/4, 2012 at 23:29 Comment(2)
Brad: you might need PhantomJS 1.5. On that version this worked fine with me.Bloemfontein
You're right.. This will only work on version 1.5 Thanks for clarifying.Sibert
S
1

One of the solutions in 2017:

https://github.com/GoogleChrome/puppeteer

example:

const puppeteer = require('puppeteer');

(async() => {

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});

browser.close();
})();
Seagoing answered 18/8, 2017 at 1:46 Comment(0)
A
0

Since you have your own Linux server, the best way is to run your own screenshot service without limitation. Here is an easy solution to run it on your server: https://github.com/filovirid/screenshot_server

It creates an API so that you can access it from everywhere.

Ancilin answered 29/3, 2020 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.