The Image Tools Module provides comprehensive image processing capabilities for the Virto Commerce platform. It enables automatic thumbnail generation for product images, category banners, and other visual assets stored in blob storage.
The module features a format-agnostic architecture that supports both raster formats (JPEG, PNG, WebP) via SixLabors.ImageSharp and vector formats (SVG) with native XML manipulation, ensuring scalability without quality loss.
- Multi-Format Support: Process raster images (JPEG, PNG, WebP, GIF, BMP, TIFF) and vector graphics (SVG)
- Flexible Resize Methods:
FixedSize- Proportional fit within specified dimensions with optional paddingFixedWidth- Maintain aspect ratio, resize to target widthFixedHeight- Maintain aspect ratio, resize to target heightCrop- Crop to exact dimensions using configurable anchor positions
- Background Processing: Batch thumbnail generation via Hangfire jobs with progress tracking
- Event-Driven Generation: Automatic thumbnail creation on blob upload events
- Incremental Processing: Only process new or modified images since last run
- Extensible Architecture: Plugin-based format handlers for easy addition of new formats
Configure the module in appsettings.json:
{
"ImageTools": {
"Thumbnails": {
"EnableImageProcessJob": false,
"EventBasedThumbnailGeneration": true,
"ImageProcessJobCronExpression": "0 0 * * *",
"ProcessBatchSize": 50
}
}
}| Setting | Type | Default | Description |
|---|---|---|---|
EnableImageProcessJob |
Boolean | false |
Enable scheduled background job for thumbnail processing |
EventBasedThumbnailGeneration |
Boolean | true |
Generate thumbnails automatically when images are uploaded |
ImageProcessJobCronExpression |
String | 0 0 * * * |
Cron expression for scheduled job (daily at midnight) |
ProcessBatchSize |
Integer | 50 |
Number of images to process before reporting progress |
Formats can be enabled/disabled via Platform Settings UI:
- Raster: JPEG, PNG, WebP (default), GIF, BMP, TIFF, TGA, PBM
- Vector: SVG
The module implements a Handler-Based Architecture for format-agnostic image processing:
┌─────────────────────────────────────────────────────────────────┐
│ ThumbnailGenerationProcessor │
│ (Orchestrates batch jobs) │
└─────────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────────▼───────────────────────────────────┐
│ IThumbnailHandlerFactory │
│ (Routes to format-specific handler) │
└─────────────────────────────┬───────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
│ │ │
┌─────────▼─────────┐ ┌───────▼───────┐ ┌────────▼────────┐
│ RasterThumbnail │ │ SvgThumbnail │ │ Custom Format │
│ Handler │ │ Handler │ │ Handler │
│ (JPEG, PNG, WebP) │ │ (SVG, SVGZ) │ │ (Extensible) │
└─────────┬─────────┘ └───────┬───────┘ └─────────────────┘
│ │
┌─────────▼─────────┐ ┌───────▼───────┐
│ IThumbnailGen │ │ ISvgService │
│ (ImageSharp) │ │ ISvgResizer │
└───────────────────┘ └───────────────┘
To add support for a new format:
- Implement
IFormatThumbnailHandler:
public class PdfThumbnailHandler : IFormatThumbnailHandler
{
public int Priority => 10;
public Task<bool> CanHandleAsync(string imageUrl)
=> Task.FromResult(imageUrl.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase));
public Task<ThumbnailGenerationResult> GenerateThumbnailsAsync(
string source, string destination, IList<ThumbnailOption> options, ICancellationToken token)
{
// Custom PDF thumbnail generation logic
}
}- Register in DI:
serviceCollection.AddTransient<IFormatThumbnailHandler, PdfThumbnailHandler>();| Interface | Description |
|---|---|
IImageService |
Load/save raster images from blob storage |
IImageResizer |
Raster image resize operations |
ISvgService |
Load/save SVG content from blob storage |
ISvgResizer |
SVG dimension manipulation |
IAllowedImageFormatsService |
Check if image format is in allowed formats list |
IFormatThumbnailHandler |
Format-specific thumbnail generation |
IThumbnailHandlerFactory |
Route to appropriate format handler |
IThumbnailGenerator |
Core thumbnail generation (obsolete - use handlers) |
IThumbnailGenerationProcessor |
Batch processing with progress tracking |
IImagesChangesProvider |
Detect new/modified images in blob storage |
| Service | Description |
|---|---|
ImageService |
ImageSharp-based raster image I/O |
ImageResizer |
ImageSharp resize with multiple methods |
SvgService |
SVG blob storage operations |
SvgResizer |
SVG XML manipulation for resizing |
AllowedImageFormatsService |
Settings-based format validation |
ThumbnailHandlerFactory |
Priority-based handler selection |
RasterThumbnailHandler |
Raster format processing via IThumbnailGenerator |
SvgThumbnailHandler |
Vector format processing via ISvgService |
| Job | Description |
|---|---|
ThumbnailProcessJob |
Hangfire job for scheduled/manual thumbnail generation |
| Model | Description |
|---|---|
ThumbnailTask |
Configuration for a thumbnail generation task (work path, options) |
ThumbnailOption |
Single thumbnail variant (size, method, quality, suffix) |
SvgDimensions |
SVG width, height, and viewBox attributes |
Copyright (c) Virto Solutions LTD. All rights reserved.
Licensed under the Virto Commerce Open Software License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://virtocommerce.com/opensourcelicense
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
