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 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();
}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.
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.
Built with Aspose.Slides
Convert JPG to Image 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 JPG files.
- Runs in your browser, nothing to install.
- See how Aspose.Slides converts files before you write code.
- Upload JPG files and save them as Image.
- Download the result or convert more files.
Convert JPG To Other Supported Formats
You can also convert JPG and save to other file formats. See all supported formats below: