SVG Rasterizing API

Last modified by Admin on 2017/11/29 19:42

vectorAPIs to rasterize SVG images
TypeJAR
CategoryAPI
Developed by

XWiki Development Team

Active Installs0
Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1
Installable with the Extension Manager

Description

Should be used as a replacement of the older SVG Plugin (which had no documentation).

Java API

public interface SVGRasterizer
{
   /**
     * Rasterize an image as PNG into a temporary file.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @return the file where the PNG is stored
     * @throws IOException if temporary files can't be accessed
     */

    File rasterizeToTemporaryFile(String content, int width, int height) throws IOException;

   /**
     * Rasterize an image as PNG as a temporary resource belonging to the current document, which can be accessed with
     * the /temp/ action.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @return the temporary resource where the PNG is stored
     * @throws IOException if temporary files can't be accessed
     */

    TemporaryResourceReference rasterizeToTemporaryResource(String content, int width, int height) throws IOException;

   /**
     * Rasterize an image as PNG as a temporary resource belonging to the specified document, which can be accessed with
     * the /temp/ action.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @param targetContext the document which will "own" the new temporary resource
     * @return the temporary resource where the PNG is stored
     * @throws IOException if temporary files can't be accessed
     */

    TemporaryResourceReference rasterizeToTemporaryResource(String content, int width, int height,
        DocumentReference targetContext) throws IOException;

   /**
     * Rasterize an image as PNG into the current response.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @throws IOException if writing the response fails
     */

   void rasterizeToResponse(String content, int width, int height) throws IOException;
}

Scripting API

   /**
     * Rasterize an image as PNG as a temporary resource belonging to the current document, which can be accessed with
     * the /temp/ action.
     *
     * @param content the SVG image
     * @return URL pointing to the temporary resource where the PNG is stored
     */

   public ExtendedURL rasterizeToTemporaryResource(String content)

   /**
     * Rasterize an image as PNG as a temporary resource belonging to the current document, which can be accessed with
     * the /temp/ action.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @return URL pointing to the temporary resource where the PNG is stored
     */

   public ExtendedURL rasterizeToTemporaryResource(String content, int width, int height)

   /**
     * Rasterize an image as PNG as a temporary resource belonging to the current document, which can be accessed with
     * the /temp/ action.
     *
     * @param content the SVG image
     * @param targetContext the document which will "own" the new temporary resource
     * @return URL pointing to the temporary resource where the PNG is stored
     */

   public ExtendedURL rasterizeToTemporaryResource(String content, DocumentReference targetContext)

   /**
     * Rasterize an image as PNG as a temporary resource belonging to the current document, which can be accessed with
     * the /temp/ action.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @param targetContext the document which will "own" the new temporary resource
     * @return URL pointing to the temporary resource where the PNG is stored
     */

   public ExtendedURL rasterizeToTemporaryResource(String content, int width, int height,
        DocumentReference targetContext)

   /**
     * Rasterize an image as PNG into the current response.
     *
     * @param content the SVG image
     * @return {@code true} if the image was successfully rasterized and written to the response, {@code false} in case
     *         of exceptions
     */

   public boolean rasterizeToResponse(String content)

   /**
     * Rasterize an image as PNG into the current response.
     *
     * @param content the SVG image
     * @param width the desired width of the raster image, in pixels; if 0 or a negative number, the image's native size
     *            is used
     * @param height the desired height of the raster image, in pixels; if 0 or a negative number, the image's native
     *            size is used
     * @return {@code true} if the image was successfully rasterized and written to the response, {@code false} in case
     *         of exceptions
     */

   public boolean rasterizeToResponse(String content, int width, int height)
}

For example from Velocity:

$services.svg.rasterizeToResponse("... svg content...")

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Dependencies

Dependencies for this extension (org.xwiki.platform:xwiki-platform-svg-rasterizer 9.10.1):

Tags:
Created by Vincent Massol on 2016/02/04 13:44
    

Get Connected