Convert HTML to JPG in PHP
Import HTML content into presentation slides and render each slide as a JPG image with Aspose.Slides for PHP via Java.
Convert HTML to JPG using PHP
To convert HTML content to JPG, create a Presentation, import the HTML with addFromHtml, and render each generated slide.
PHP code for converting HTML into JPG
$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) . ".jpg";
$slideImage->save($filePath, ImageFormat::Jpeg);
} finally {
$slideImage->dispose();
}
}
} finally {
$presentation->dispose();
}Convert HTML to JPG in PHP
Aspose.Slides for PHP via Java can import HTML content into presentation slides and render those slides as JPG images. The example below exports every generated slide to a separate JPG file.
Aspose.Slides provides a straightforward API for HTML-to-JPG conversion and can also export the imported content to PDF, PowerPoint, and other supported formats.
How to convert HTML to JPG using Aspose.Slides for PHP API
These are the steps to convert HTML to JPG 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::Jpeg.
Built with Aspose.Slides
Convert HTML to JPG Online
The free Aspose.Slides Conversion app is built with Aspose.Slides for PHP via Java, the same API as the code above. Open it and see what the API can do with your own HTML files.
- Runs in your browser, nothing to install.
- See how Aspose.Slides converts files before you write code.
- Upload HTML files and save them as JPG.
- Download the result or convert more files.
Convert HTML To Other Supported Formats
You can also convert HTML and save to other file formats. See all supported formats below: