Convert JPG to Image in PHP
Place a JPG image on a slide and render the slide as a PNG image with Aspose.Slides for PHP via Java.
Convert JPG to Image in PHP
Aspose.Slides for PHP via Java lets you add a JPG image to a presentation slide and render the slide in a supported image format. The example below uses PNG output.
Use Images::fromFile to load the JPG file, getImage to render the slide, and ImageFormat::Png to select PNG output.
Convert JPG to Image using PHP
To convert JPG to an image, add the source file to a Presentation, place it on a slide, render the slide with getImage, and save the result with ImageFormat::Png.
PHP code for converting JPG into Image
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$sourceImage = Images::fromFile("input.jpg");
try {
$embeddedImage = $presentation->getImages()->addImage($sourceImage);
} finally {
$sourceImage->dispose();
}
$imageWidth = java_values($embeddedImage->getWidth());
$imageHeight = java_values($embeddedImage->getHeight());
$slide->getShapes()->addPictureFrame(
ShapeType::Rectangle, 0, 0, $imageWidth, $imageHeight, $embeddedImage);
$slideImage = $slide->getImage(1.0, 1.0);
try {
$slideImage->save("output.png", ImageFormat::Png);
} finally {
$slideImage->dispose();
}
} finally {
$presentation->dispose();
}
How to convert JPG to Image using Aspose.Slides for PHP API
These are the steps to convert JPG to Image in PHP.
Install Aspose.Slides for PHP via Java .
Configure Aspose.Slides in your PHP project.
Create a
Presentation, access its first slide, and load the JPG file withImages::fromFile.Add the JPG image with
addPictureFrame, render the slide withgetImage, and save it withImageFormat::Png.
Free Online Converter
Convert JPG To Other Supported Formats
You can also convert JPG and save to other file formats. See all supported formats below: