Convert PNG to JPG in PHP
Place a PNG image on a slide and render the slide in JPEG format with Aspose.Slides for PHP via Java.
Convert PNG to JPG in PHP
Aspose.Slides for PHP via Java can place a PNG image on a presentation slide and render the slide as a JPEG image.
Load the PNG with Images::fromFile, resize the slide with setSize, add the image with addPictureFrame, and render the slide with getImage. Because JPEG does not support transparency, transparent PNG areas are rendered against the slide background.
Convert PNG to JPG using PHP
Create a Presentation, match the slide size to the PNG, place the image on the slide, call getImage, and save the rendered image with ImageFormat::Jpeg.
PHP code for converting PNG into JPG
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$sourceImage = Images::fromFile("input.png");
try {
$embeddedImage = $presentation->getImages()->addImage($sourceImage);
} finally {
$sourceImage->dispose();
}
$imageWidth = java_values($embeddedImage->getWidth());
$imageHeight = java_values($embeddedImage->getHeight());
$presentation->getSlideSize()->setSize(
$imageWidth, $imageHeight, SlideSizeScaleType::DoNotScale);
$slide->getShapes()->addPictureFrame(
ShapeType::Rectangle, 0, 0, $imageWidth, $imageHeight, $embeddedImage);
$slideImage = $slide->getImage(1.0, 1.0);
try {
$slideImage->save("output.jpg", ImageFormat::Jpeg);
} finally {
$slideImage->dispose();
}
} finally {
$presentation->dispose();
}
How to convert PNG to JPG using Aspose.Slides for PHP API
These are the steps to convert PNG to JPG in PHP.
Install Aspose.Slides for PHP via Java .
Create a
Presentation, access its first slide, and load the PNG withImages::fromFile.Set the slide dimensions with
setSize, then place the image on the slide withaddPictureFrame.Render the slide with
getImageand save it withImageFormat::Jpeg.
Free Online Converter
Convert PNG To Other Supported Formats
You can also convert PNG and save to other file formats. See all supported formats below: