Skip to content

VesninAndrey/browsershot

 
 

Repository files navigation

Convert a webpage to an image

Build Status Latest Stable Version License

The package can convert a webpage to an image. To accomplish this conversion Phantomjs (included in the project) is used.

This package is used to generate the sitepreviews on the homepage of spatie.be

Installation

This package can be installed through Composer.

{
    "require": {
		"spatie/browsershot": "dev-master"
	}
}

When using Laravel there is a service provider that you can make use of.

// app/config/app.php

'providers' => [
    '...',
    'Spatie\Browsershot\BrowsershotServiceProvider'
];

Usage

Here is a sample call to create an image of a webpage:

    $browsershot = new Spatie\Browsershot\Browsershot();
    $browsershot
        ->setURL('http://www.arstechnica.com')
        ->setWidth('1024')
        ->setHeight('768')
        ->save('targetdirectory/arstechnica-browsershot.jpg');

These methods are provided:

  • setBinPath(): Specify the path to your own phantomjs-binary.
  • setWidth(): Set the width of the image (defaults to 640).
  • setHeight(): Set the height of the image (defaults to 480).
  • setURL(): Set the URL of the webpage which should be converted to an image
  • save($targetFile): Starts the conversion-process. The targetfile should have one of these extensions: png, jpg, jpeg.

About

Convert a webpage to an image

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%