Code: Select all
var imageFiles = Directory.GetFiles(imageFolder, "*.png");
var magickImages = new List<MagickImage>();
var imageHeight = new List<string>;
foreach (var imageFile in imageFiles)
{
var image = new MagickImage(imageFile);
imageHeight.Add(imageFile);
var heightLengthInPixels = getHeightInPixels(imageFile).ToString();
image.Resize(new MagickGeometry("154x" + heightLengthInPixels + "!"));
magickImages.Add(image);
}
var settings = new MagickReadSettings
{
Width = 154,
Height = getFullHeightInPixels(imageHeight.First(), imageHeight.Last())
};
var canvas = new MagickImage("xc:white", settings) {Format = MagickFormat.Png32};
for (int i = 0; i < magickImages.Count; i++)
{
canvas.Composite(magickImages[i], 0, getHeightInPixels(imageHeight[i]));
}
canvas.Resize(new MagickGeometry("154x10000!"));
canvas.Write(imageFolder + "/CombinedImage.png");
On my personal computer, this literally takes less than a second. But I need this to run on a backend server, provided by a VM in Azure, and this takes several hours. I've tried different VMs, with and without GPU, and with varying CPU and Memory size, and they are all incredibly slow. (At the moment of writing, my VM is using 13% CPU power and 8% memory). I was expecting them to be a bit slower, sure, but not by a factor of 7000+.
Has anyone had similar problems before? And/or have I written the code stupidly?