Image Merger Licensing Plugin

Contents
[ ]

         Utilize the Image Merger License plugin to effortlessly create photo collages by seamlessly combining images in various layouts, including horizontal, vertical, tiled, and customizable arrangements. Source image files in various formats from the list of supported image formats to merge them seamlessly. Before applying the merge operation, ensure you acquire a Metered license by providing your public key and private password using the `SetMeteredKey()` method. In the C# code example below, we create a new `Image` object with a white background and dimensions equal to the total sum of source images. Then, place images in the specified directions using the DrawImage() method of the `Graphics` class and save the resulting image in the supported image format. Utilizing unlicensed features of the Aspose.Imaging graphic library will result in a watermark appearing on the output image.

//---------------------------------------------------------------------------------------
// Image merge plug-in use examples
//---------------------------------------------------------------------------------------
using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Emf;
using Aspose.Imaging.FileFormats.Png;
using Aspose.Imaging.FileFormats.Tiff;
using Aspose.Imaging.FileFormats.Tiff.Enums;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Sources;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;
Run4();
void Run4()
{
// Valid image merge license use example
Metered license = new Metered();
// Only metered plug-in license is supported
license.SetMeteredKey("<your public key>", "<your private key>");
string OutputDirectory = templatesFolder;
var images = new List<Image>();
int maxWidth = 0;
int maxHeight = 0;
int totalWidth = 0;
int totalHeight = 0;
string[] imagePaths = new string[] { "template.png", "template.jpg", "template.bmp" };
foreach (string fileName in imagePaths)
{
var image = Image.Load(Path.Combine(templatesFolder, fileName));
totalWidth += image.Width;
if (image.Width > maxWidth)
{
maxWidth = image.Width;
}
totalHeight += image.Height;
if (image.Height > maxHeight)
{
maxHeight = image.Height;
}
images.Add(image);
}
try
{
var outputPath = Path.Combine(OutputDirectory, "licensed_merge_horizontal.jpg");
MergeImages(images, MergeDirection.Horizontal, totalWidth, maxHeight, outputPath);
File.Delete(outputPath);
outputPath = Path.Combine(OutputDirectory, "licensed_merge_vertical.jpg");
MergeImages(images, MergeDirection.Vertical, totalHeight, maxWidth, outputPath);
File.Delete(outputPath);
// Unlicensed crop with merge plug-in license
outputPath = Path.Combine(OutputDirectory, "trial_merge_vertical.jpg");
MergeImages(images, MergeDirection.Vertical, totalHeight, maxWidth, outputPath,
(image) =>
{
var rasterImage = image as RasterImage;
if (rasterImage == null)
{
return false;
}
rasterImage.Crop(new Rectangle(0, 0, image.Width >> 1, image.Height >> 1));
return true;
}
);
File.Delete(outputPath);
}
finally
{
images.ForEach(image => image.Dispose());
}
}
void MergeImages(List<Image> images, MergeDirection direction, int totalSize, int maxSize, string outputPath, Func<Image, bool> callback = null)
{
int targetWidth, targetHeight;
switch (direction)
{
case MergeDirection.Horizontal:
{
targetWidth = totalSize;
targetHeight = maxSize;
break;
}
case MergeDirection.Vertical:
{
targetWidth = maxSize;
targetHeight = totalSize;
break;
}
default:
throw new ArgumentException("Unexpected merge direction");
}
var pngOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha };
using (Stream stream = new MemoryStream())
{
pngOptions.Source = new StreamSource(stream);
using (var image = Image.Create(pngOptions, targetWidth, targetHeight))
{
image.BackgroundColor = Color.White;
var graphics = new Graphics(image);
float x = 0, y = 0;
images.ForEach(image =>
{
graphics.DrawImage(image, new RectangleF(x, y, image.Width, image.Height));
if (direction == MergeDirection.Horizontal)
{
x += image.Width;
}
if (direction == MergeDirection.Vertical)
{
y += image.Height;
}
});
if (callback != null)
{
callback(image);
}
image.Save(outputPath);
}
}
}
enum MergeDirection
{
Horizontal = 0,
Vertical = 1
}

Discover the capabilities of our free online Aspose.Imaging Merge Application demo site.