Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function generate($path, $html)
 {
     $image = new Image();
     $image->setBinary($this->_getBinDir() . 'wkhtmltoimage-' . $this->_getBinaryType());
     foreach ($this->_options as $key => $value) {
         $image->setOption($key, $value);
     }
     if (is_file($path)) {
         unlink($path);
     }
     $image->generateFromHTML($html, $path);
     return new File($path);
 }
Exemplo n.º 2
0
 /**
  * Save the image to a file
  *
  * @param $filename
  *
  * @return static
  */
 public function save($filename, $overwrite = false)
 {
     if ($this->html) {
         $this->snappy->generateFromHtml($this->html, $filename, $this->options, $overwrite);
     } elseif ($this->file) {
         $this->snappy->generate($this->file, $filename, $this->options, $overwrite);
     }
     return $this;
 }
Exemplo n.º 3
0
<?php

require_once 'vendor/knplabs/knp-snappy/src/autoload.php';
$size = isset($_POST['size']) ? $_POST['size'] : 1;
use Knp\Snappy\Image;
$snappy = new Image('/usr/local/bin/wkhtmltoimage');
$snappy->setOption('disable-javascript', true);
$snappy->setOption('disable-local-file-access', true);
$snappy->setOption('quality', 100);
$snappy->setOption('zoom', $size);
$description = $size == 1 ? 'Normal' : ($size == 2 ? 'Big' : 'Large');
$filename = 'My NUSMods.com Timetable (' . $description . ').jpg';
header('Content-Type: image/jpeg');
header('Content-Disposition: attachment; filename=' . $filename);
echo $snappy->getOutputFromHtml(urldecode($_POST['html']));
<?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');
<?php

require_once 'vendor/autoload.php';
use Knp\Snappy\Image;
$snappy = new Image('/usr/local/bin/wkhtmltoimage', ['format' => 'png']);
$snappy->setDefaultExtension('png');
// 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="relatorio.png"');
$html = <<<'EOD'
<h1 style="color: red;">Relatório</h1>
<br/>
<table width="100%">
    <thead>
        <tr>
            <th>Nome</th>
            <th>E-mail</th>
            <th>Telefone</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Fulano da Silva</td>
            <td>fulano@dasilva.com</td>
            <td>11 99999-8888</td>
        </tr>
        <tr>
            <td>Sicrano Santos</td>
            <td>sicrano@gmail.com</td>
Exemplo n.º 6
0
 /**
  * @param \Illuminate\Filesystem\Filesystem
  * @param string $binary
  * @param array $options
  */
 public function __construct(Filesystem $fs, $binary, array $options)
 {
     parent::__construct($binary, $options);
     $this->fs = $fs;
 }
Exemplo n.º 7
0
 public function saveModule($data)
 {
     $this->load->helper('file');
     $docNameNew = uniqid('', true);
     $docName = $docNameNew . '.php';
     $category = $data['category'];
     if (!write_file($this->config->item('moduleDir') . $category . '/files/' . $docName, $data['html'])) {
         $msg = array('status' => 'error', 'msg' => 'There was an error writing the new module to a file.');
         echo json_encode($msg);
         exit;
     } else {
         $image = new Image($this->config->item('image_binary'));
         $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip');
         $newImage = $this->config->item('moduleDir') . $category . '/files/thumbnails/' . $docNameNew . '.jpg';
         $image->generateFromHtml($data['html'], $newImage, $options, true);
         $config['source_image'] = $newImage;
         $config['maintain_ratio'] = true;
         $config['height'] = 200;
         $this->load->library('image_lib', $config);
         $this->image_lib->resize();
         $module = array('category' => $category, 'owner' => $this->session->id, 'description' => $data['description'], 'created' => date('Y-m-d H:i:s'), 'publishable' => 1, 'location' => $docName);
         $this->db->insert('modules', $module);
         $msg = array('status' => 'success', 'msg' => 'We successfully created the new module, and inserted the data into the database.');
         echo json_encode($msg);
     }
 }
<?php

require_once 'vendor/autoload.php';
use Knp\Snappy\Image;
$snappy = new Image('/usr/local/bin/wkhtmltoimage', ['format' => 'png']);
$snappy->setDefaultExtension('png');
$snappy->setOptions(['width' => 200]);
// 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');
<?php

require_once 'vendor/autoload.php';
use Knp\Snappy\Image;
$snappy = new Image('/usr/local/bin/wkhtmltoimage', ['format' => 'png']);
$snappy->setDefaultExtension('png');
// 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-artigos.png"');
echo $snappy->getOutput(array('http://www.schoolofnet.com/2015/07/trabalhando-com-repository-no-laravel/', 'http://www.schoolofnet.com/2015/04/como-usar-os-metodos-magicos-no-php/', 'http://www.schoolofnet.com/2015/04/enviando-emails-utilizando-swift-mailer/', 'http://www.schoolofnet.com/2015/04/instalando-e-integrando-apache-com-php-no-windows/'));
// 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/artigos.png');
Exemplo n.º 10
0
 public static function snapThumbAndSave($url, $snap_width, $snap_height, $save_width, $save_height, $is_text, $is_image, $dest)
 {
     set_time_limit(120);
     try {
         $snappy = new ThumbDL('/usr/local/bin/wkhtmltoimage');
         $snappy->setOption('stop-slow-scripts', true);
         $snappy->setOption('width', $snap_width);
         $snappy->setOption('height', $snap_height);
         $host = parse_url($url, PHP_URL_HOST);
         if (strcmp($host, "www.youtube.com") == 0) {
             parse_str(parse_url($url, PHP_URL_QUERY), $vars);
             $image = $snappy->getOutput(URL::to("/util/imagewrapper?url=" . urlencode("http://img.youtube.com/vi/" . $vars['v'] . "/0.jpg")));
         } else {
             if (strcmp($host, "youtu.be") == 0) {
                 $image = $snappy->getOutput(URL::to("/util/imagewrapper?url=" . urlencode("http://img.youtube.com/vi" . parse_url($url, PHP_URL_PATH) . "/0.jpg")));
             } else {
                 if (strcmp($host, "vimeo.com") == 0) {
                     $img_id = parse_url($url, PHP_URL_PATH);
                     $img_hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video{$img_id}.php"));
                     $image = $snappy->getOutput(URL::to("/util/imagewrapper?url=" . $img_hash[0]['thumbnail_large']));
                 } else {
                     if ($is_text) {
                         $image = $snappy->getOutput($url);
                     } else {
                         if ($is_image) {
                             $image = $snappy->getOutput(URL::to("/util/imagewrapper?url=" . urlencode($url)));
                         } else {
                             Log::error("image neither text nor image");
                             return false;
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return false;
     }
     try {
         $tmpfname = tempnam("/tmp", "spreadit");
         $handle = fopen($tmpfname, "w");
         fwrite($handle, $image);
         fclose($handle);
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return false;
     }
     try {
         $resizer = Image::make($tmpfname);
         $resizer->resize($save_width, $save_height);
         $resizer->save($dest);
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return false;
     }
     return true;
 }
Exemplo n.º 11
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;
}
<?php

require_once 'vendor/autoload.php';
use Knp\Snappy\Image;
$snappy = new Image('/usr/local/bin/wkhtmltoimage', ['format' => 'png']);
$snappy->setDefaultExtension('png');
// 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');