PHP code example of erichfournier / html-to-image-php
1. Go to this page and download the library: Download erichfournier/html-to-image-php library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
erichfournier / html-to-image-php example snippets
use ErichFournier\HtmlToImagePhp\HtmlConverter;
$html = "<h1>Olá Mundo!</h1><p>Gerando imagem com PHP.</p>";
HtmlConverter::make($html)
->setDimensions(500, 600)
->save('caminho/do/arquivo.jpg');
try {
$html = view('recibos.venda', compact('venda'))->render();
$path = public_path('recibos/recibo_' . $venda->id . '.jpg');
\ErichFournier\HtmlToImagePhp\HtmlConverter::make($html)
->setDimensions(500, 650)
->save($path);
return response()->json(['message' => 'Imagem gerada com sucesso!']);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}