Skip to content

Image actions

Add action parameters to an image's URL and Veva resizes, crops or sharpens the image on the way out. This article lists the built-in actions in Veva 7.26, the order they run in, and how to add an action of your own.

An image in the asset library has a URL under /library/. Add one or more action parameters to that URL, and Veva changes the image before it sends it. The original asset is never changed.

Actions work on JPEG, PNG, GIF, BMP, TIFF and WebP images. Veva saves each processed version and reuses it until the asset changes, so only the first request does the work. The processed image can come back in another format than the original: on this site a PNG comes back as WebP.

Action names are not case sensitive, and every number has one to four digits. An action that Veva does not recognise is ignored. With download=true in the URL the original file is sent and no action runs.

Resizing

All four keep the image's aspect ratio.

  • action=width:(width) sets the width. The height follows from the aspect ratio. A smaller image is not enlarged.
  • action=height:(height) sets the height. The width follows from the aspect ratio. A smaller image is not enlarged.
  • action=fit:(width)x(height) makes the image fit inside the given size. Both sides end up equal to or smaller than the numbers given. A smaller image is not enlarged.
  • action=cover:(width)x(height) makes the image cover the given size. Both sides end up equal to or larger than the numbers given, so a smaller image is enlarged.

Example: /library/sampleimages/landscape.png?action=width:200

Cropping

action=crop:(width)x(height) cuts the image to exactly that size.

When the asset has a focus point, set on the image in the asset library, Veva cuts around that point without scaling the image. Without a focus point, Veva scales the image until it covers the size and cuts from the centre.

Example: /library/sampleimages/landscape.png?action=crop:100x100

Sharpening

A resized image often looks clearer with a little sharpening. action=sharpen on its own means medium.

  • action=sharpen:light
  • action=sharpen:medium
  • action=sharpen:strong

The order matters

Actions run in the order they stand in the URL.

/library/sampleimages/landscape.png?action=crop:100x100&action=width:200 crops to 100 by 100 pixels first. The width action then finds an image that is already narrower than 200 pixels and leaves it alone.

/library/sampleimages/landscape.png?action=width:200&action=crop:100x100 resizes to 200 pixels wide first and then crops to 100 by 100.

The difference shows most on an image with a focus point. Cropping first cuts a 100 pixel piece out of the full-size image. Resizing first cuts the same size out of the 200 pixel version, which keeps much more of the picture.

Default actions

A website's asset settings hold a list of default image actions. They run on every image URL that has no action parameter of its own. A URL with an action gets only the actions it names.

Adding an action of your own

Veva hands each action value to every registered IActionParser (namespace Veva.Modules.Assets.Domain.Services). A parser that knows the value returns one or more steps, each an IImageProcedureStepHandler (namespace Veva.Modules.Assets.Domain.Handlers). A parser that does not know the value returns null.

The image work is done with SkiaSharp. The three built-in parsers, ResizeParser, CropParser and SharpenParser, are in Veva.Modules.Assets.Infrastructure.SkiaSharp.

public interface IActionParser
{
	IEnumerable<IImageProcedureStepHandler> ParseActionString(string action);
}

public interface IImageProcedureStepHandler
{
	bool PixelRatioSensitive();

	Task ApplyStep(ImageProcedureSubject subject);

	string ToString();
}

Two things to know when you write a step:

  • ApplyStep returns a Task. In 2022 it returned void.
  • Veva names the saved version of an image after the ToString values of its steps. Return a text that holds every setting of the step. Two steps with different settings and the same text would share one saved image.

Register the parser in your module's ConfigureServices, the same way Veva registers its own:

services.AddSingleton<IActionParser, MyActionParser>();

Back to top

Type to search the docs, components and API.

↑↓ to move ↵ to open Esc to close Search by Veva