Convert HTML to Image in PHP
Import HTML content into presentation slides and render each slide as an image with Aspose.Slides for PHP via Java.
Convert HTML to Image in PHP
Aspose.Slides for PHP via Java can import HTML content into presentation slides and render those slides as images. The example below exports each generated slide as a PNG image with a few lines of PHP code.
You can select another supported image format by changing the value from ImageFormat. Aspose.Slides can also export the imported HTML content to PDF, PowerPoint, and other supported formats.
Convert HTML to Image using PHP
To convert HTML content to images, create a Presentation, import the HTML with addFromHtml, and render each generated slide.
PHP code for converting HTML into Image
$presentation = new Presentation();
try {
$slides = $presentation->getSlides();
$slides->removeAt(0);
$htmlContent = file_get_contents("input.html");
$slides->addFromHtml($htmlContent);
$slideCount = java_values($slides->size());
for ($slideIndex = 0; $slideIndex < $slideCount; $slideIndex++) {
$slide = $slides->get_Item($slideIndex);
$slideImage = $slide->getImage(1, 1);
try {
$filePath = "slide_" . ($slideIndex + 1) . ".png";
$slideImage->save($filePath, ImageFormat::Png);
} finally {
$slideImage->dispose();
}
}
} finally {
$presentation->dispose();
}
How to convert HTML to Image using Aspose.Slides for PHP API
These are the steps to convert HTML to Image in PHP.
Install Aspose.Slides for PHP via Java .
Configure Aspose.Slides in your PHP project.
Read the HTML content with
file_get_contentsand pass it toaddFromHtml.Render each slide with
getImageand save it withImageFormat::Png.
Free Online Converter
Convert HTML To Other Supported Formats
You can also convert HTML and save to other file formats. See all supported formats below: