Convert PNG to SVG in PHP

Place a PNG image on a slide and export the slide as SVG with Aspose.Slides for PHP via Java.

Convert PNG to SVG using PHP

Create a Presentation, load the PNG with Images::fromFile, match the slide size to the image with setSize, add it with addPictureFrame, and call writeAsSvg for that slide.

PHP code for converting PNG into SVG

$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);

    $outputStream = new Java("java.io.FileOutputStream", "output.svg");
    try {
        $slide->writeAsSvg($outputStream);
    } finally {
        $outputStream->close();
    }
} finally {
    $presentation->dispose();
}

Convert PNG to SVG in PHP

Aspose.Slides for PHP via Java can place a PNG image on a presentation slide and write the slide as SVG markup.

The exported SVG preserves the slide layout and contains the raster PNG image; this process does not trace or convert the PNG pixels into vector paths.

How to convert PNG to SVG using Aspose.Slides for PHP API

These are the steps to convert PNG to SVG in PHP.

  1. Install Aspose.Slides for PHP via Java.
  2. Create a Presentation, access its first slide, and load the PNG with Images::fromFile.
  3. Set the slide dimensions with setSize, then place the image on the slide with addPictureFrame.
  4. Create an output stream and call writeAsSvg for the slide.

Built with Aspose.Slides

Convert PNG to SVG 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 PNG files.

  • Runs in your browser, nothing to install.
  • See how Aspose.Slides converts files before you write code.
  • Upload PNG files and save them as SVG.
  • Download the result or convert more files.

Convert PNG To Other Supported Formats

You can also convert PNG and save to other file formats. See all supported formats below: