<?php

require_once 'vendor/autoload.php';
use Knp\Snappy\Image;
$snappy = new Image('/usr/local/bin/wkhtmltoimage', ['format' => 'png']);
$snappy->setDefaultExtension('png');
$snappy->setOptions(['crop-w' => 200, 'crop-h' => 200, 'crop-x' => 400, 'crop-y' => 20]);
// Cabeçalho para o navegador entender que o conteúdo é uma imagem PNG
header('Content-Type: image/png');
// Se quiser forçar o download, descomente a linha abaixo e
// modifica o valor do parâmetro filename para o valor desejado
//header('Content-Disposition: attachment; filename="schoolofnet-blog-home.png"');
echo $snappy->getOutput('http://www.schoolofnet.com/blog/');
// Se quiser salvar numa pasta do servidor ao invés mostrar no navegador,
// comente a linha do getOutput(),
// descomente a linha abaixo e arrume o segundo parâmetro.
//$snappy->generate('http://www.schoolofnet.com/blog/', '/app/arquivos/son/home-blog.png');
Exemplo n.º 2
0
function generate_for_gallery($theme_id)
{
    $theme = find_theme($theme_id);
    if (is_null($theme)) {
        return false;
    }
    if ($theme["share"] != 1) {
        return false;
    }
    $path_image = BASE_PATH . get_thumbnail_path($theme_id);
    if (!file_exists(dirname($path_image))) {
        mkdir(dirname($path_image), 0777, true);
    }
    if (!file_exists($path_image)) {
        $snappy = new Image(COMMAND_WKHTMLTOIMAGE, array("format" => "png", "width" => 200, "zoom" => 0.75, "quality" => 50, "disable-javascript" => true));
        $snappy->setDefaultExtension("png");
        $params = array("api_type" => $theme["api_type"], "id" => $theme["cs_id"], "c" => $theme["_c"], "design" => "thumbnail");
        $url = BASE_URL . "preview?" . http_build_query($params);
        $url = str_replace("%5B", "[", $url);
        $url = str_replace("%5D", "]", $url);
        $image = $snappy->getOutput($url);
        file_put_contents($path_image, $image);
    }
    return true;
}