Rasterize SVG Content as GIF
Aspose.HTML for Java
converts SVG files, markup, and URLs to GIF with
Converter.convertSVG()
. Load the source into SVGDocument, select ImageFormat.Gif, and specify the destination path. The conversion rasterizes SVG shapes, text, styles, and referenced resources.
Java Code for Static GIF Output
The example loads an SVG file and saves its rendered appearance as output.gif. Try-with-resources guarantees cleanup of the SVG document.
Convert SVG to GIF in Java
import com.aspose.html.converters.Converter;
import com.aspose.html.dom.svg.SVGDocument;
import com.aspose.html.rendering.image.ImageFormat;
import com.aspose.html.saving.ImageSaveOptions;
// Load the SVG document
try (SVGDocument document = new SVGDocument("document.svg")) {
// Select GIF output
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif);
// Convert SVG to GIF
Converter.convertSVG(document, options, "output.gif");
}
Test SVG to GIF Conversion Online
Upload an SVG file or specify its URL to preview the GIF result before adding the same conversion to Java code.
SVG to GIF API Steps
- Add Aspose.HTML for Java to the project.
- Open the vector source with
SVGDocument. - Select
ImageFormat.GifinImageSaveOptions. - Pass the document, options, and destination path to
Converter.convertSVG().
Configure GIF Dimensions and Quality
Use ImageSaveOptions to set resolution, page size, margins, background color, smoothing, CSS processing, and text rendering. GIF uses a limited color palette and this workflow creates a static raster result. Choose
SVG to PNG
when a broader color range or lossless detail is required.
See
Convert SVG to JPG in Java
for the shared image workflow and the
ImageSaveOptions API Reference
.
Install Aspose.HTML for Java
Add Aspose.HTML for Java from the official Aspose repository. Replace ASPOSE_HTML_VERSION with an exact version from the
Aspose.HTML for Java releases
page, then reload or rebuild the project so the dependency is resolved.
Add the repository and dependency to the Maven project:
Maven – pom.xml
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-html</artifactId>
<version>ASPOSE_HTML_VERSION</version>
</dependency>
</dependencies>Add the repository and dependency to the Gradle project:
Gradle – build.gradle
repositories {
maven {
url = uri('https://releases.aspose.com/java/repo/')
}
}
dependencies {
implementation 'com.aspose:aspose-html:ASPOSE_HTML_VERSION'
}Use a JDK compatible with the selected release. For manual JAR installation, Kotlin DSL, updates, and dependency troubleshooting, see Install Aspose.HTML for Java .
SVG to GIF Conversion FAQ
1. Does SVG to GIF preserve SVG animation?
No. This conversion creates a static GIF image. It does not turn SVG animation or scripted changes into a sequence of GIF frames.
2. Why can SVG colors change in GIF output?
GIF uses a limited color palette. Complex gradients, photographs, and illustrations with many colors can lose detail during rasterization.
3. Can SVG text and strokes be antialiased in the GIF?
Rendering quality and smoothing can be configured through ImageSaveOptions. The final appearance is still constrained by the GIF color model.
4. Can I convert SVG to GIF online for free?
Yes. Use the free online SVG to GIF converter for a manual conversion, or use the Java API for automation.
Related Java Conversions
Choose another SVG output or a related HTML rendering workflow.