C# Thumbnail Maker
C# Image Thumbnail Maker is a simple program that will make thumbnails of all images in the .exe's Images directory. Be sure to only have valid images in that directory and that it exists before you run the program.
Just wanted to share this code and created a snippet of it in case I need it later. Basically I had to create several dozens of thumbnails, so instead of loading each one in PhotoShop to make a thumbnail, why not use the amazing Magick.NET Magick++-based NuGet package?
namespace ThumbnailMaker { using System; using System.IO; using System.Linq; using ImageMagick; //install ImageMagick via Nuget ////// Requirements: nuget install ImageMagick /// Then, when the program runs, it will resize all images in the Images /// directory of the current .exe location. You can change anything /// in this "script" to fit whatever case you want. /// internal static class Program { const string THUMB_PREPEND = "thumb_"; const string IMAGES_DIR = @"Images\"; internal static void Main(string[] args) { string[] imagePaths = Directory.GetFiles(IMAGES_DIR) .Where(f => !f.Contains(THUMB_PREPEND)) .Select(f => f) .ToArray(); Console.WriteLine($"Will create {imagePaths.Length} thumbnail images."); try { foreach (var imagePath in imagePaths) { //set ignoreAspectRatio to true to ignore aspect ratio ResizeImage(new FileInfo(imagePath), ignoreAspectRatio: false); } } catch (Exception ex) { Console.WriteLine("Error!"); Console.WriteLine(ex.Message); } Console.WriteLine("Done. Press enter to exit."); Console.ReadLine(); } private static void ResizeImage(FileInfo imageFileInfo, bool ignoreAspectRatio = false) { // Read from file using (var image = new MagickImage(imageFileInfo.FullName)) { var size = new MagickGeometry(100, 100); // This will resize the image to a fixed size without maintaining the aspect ratio. // Normally an image will be resized to fit inside the specified size. size.IgnoreAspectRatio = ignoreAspectRatio; image.Resize(size); string resizedName = imageFileInfo.Directory + "\\" + THUMB_PREPEND //prepend "thumb" so all thumbnails are grouped nicely + imageFileInfo.Name; // Save the result image.Write(resizedName); Console.WriteLine("Created a thumbnail of: " + imageFileInfo.Name); } } } }