曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
C#

Pure C# implementation + AOT-built multifunctional image processing tool ImageGlider

The ImageGlider, built with pure C# and AOT, has image processing features piled up like a mountain, yet it insists on touting zero dependencies? ImageSharp is wrapped quite smoothly, but it's uncertain how far this modular architecture can go. The Web API and CLI tools have some merit, but don't expect me to praise it excessively.

曦远 (DealiAxy)约 18 分钟
目录9 个章节

Preface

Last time, I developed an ICO Icon Generator using C# + AOT.

This practical little tool attracted a lot of attention from friends as soon as it was released.

Recently, it was even made into a website with a graphical interface for one-click generation of .ico icons, making it more convenient for regular users.

This kind of C# development with automated GitHub Actions publishing of NuGet packages and dotnet tools offers such a great one-stop experience that I became somewhat addicted to the feeling.

Recently, I've developed a couple of similar tools in succession, one of which is the image processing tool I will introduce in this article.

The project is open-source. Stars and PRs are welcome: https://github.com/star-plan/image-glider

About ImageGlider

Initially, I developed this tool simply to batch convert jfif images in a directory to jpg or png format that Windows File Explorer could display as thumbnails.

However, during the development process, I discovered how convenient it is to build small utilities with C#, so I gradually added a bunch of additional features.

Next, I also plan to add a similar image recognition function.

Here is the current project introduction:

ImageGlider is a powerful, cross-platform image processing toolkit, implemented in C# (.NET 9) using ImageSharp. The project uses a modular architectural design, including a core class library, command-line tool, Web API, sample programs, and comprehensive unit tests. It supports AOT compilation for native performance.

With ImageGlider, you can easily perform image processing operations, completely free from external dependencies. It does not require ImageMagick, Node.js, or Python, making it suitable for embedding within .NET projects, distribution, or integration into automated workflows.

The goal is to create a cross-platform, zero-dependency, high-performance, and fully-featured image processing solution! (It can be understood as a simplified version of ImageMagick)

Project Repository: https://github.com/star-plan/image-glider

Features

🎯 Core Image Processing Functions

  • 🖼️ Format Conversion: Supports mutual conversion between various image formats such as JPEG, PNG, GIF, BMP, TIFF, WebP, etc.
  • 📏 Resizing: Supports multiple adjustment modes including stretching, maintaining aspect ratio, and cropping
  • 🗜️ Compression Optimization: Smart compression algorithms to reduce file size while maintaining quality
  • ✂️ Image Cropping: Precise cropping of specified areas, supports center cropping and custom coordinate cropping
  • 🖼️ Thumbnail Generation: Quickly generate high-quality thumbnails with support for multiple size modes
  • 💧 Watermark Function: Supports text and image watermarks with 9 position choices, adjustable transparency and scaling
  • 🧹 Metadata Cleaning: One-click removal of privacy-sensitive metadata information such as EXIF, ICC, XMP
  • 🎨 Color Adjustment: Adjust color parameters including brightness, contrast, saturation, hue, gamma value, etc.
  • ℹ️ Information Extraction: Obtain detailed image information with support for JSON format output

🛠️ Technical Features

  • 🚀 Cross-platform: Based on .NET 9 and ImageSharp, supporting Windows, Linux, macOS
  • ⚡ AOT Compilation: Supports native AOT compilation for fast startup and low memory usage
  • 📦 Zero-dependency: No need to install additional image processing tools or runtime environments
  • 🧩 Modular Design: Core functionalities encapsulated as independent class libraries for easy integration and extension
  • 🔧 Multiple Interfaces: Provides three usage modes: CLI tool, Web API, and core class library

💻 Usage

  • Command-line Tools: 16 professional commands, supporting single-file and batch processing
  • Web API: RESTful interface, supporting HTTP file upload and processing
  • Core Library: Directly integrate into .NET projects for use
  • Batch Processing: Automatically scan directories, supporting recursive processing and file filtering
  • Detailed Logging: Complete log recording, supporting multiple log levels
  • Error Handling: Robust exception handling mechanism, providing detailed processing result information

Usage

Install as a .NET Global Tool (Recommended)

dotnet tool install --global ImageGlider.Cli

After installation, you can use it from the command line.

$ imageglider
=== ImageGlider Command Line Tool ===

Usage:
  ImageGlider.Cli <command> [options]
  ImageGlider.Cli help [command]    Show help information

Available Commands:
  adjust                Adjust color properties of a single image file (brightness, contrast, saturation, hue, gamma)
  batch-adjust          Batch adjust color properties of image files in a specified directory (brightness, contrast, saturation, hue, gamma)
  batch-compress        Batch compress and optimize image files
  batch-convert         Batch convert image files
  batch-crop            Batch crop image files in a specified directory
  batch-info            Batch view detailed information of image files in a directory
  batch-resize          Batch resize image files
  batch-strip-metadata  Batch strip metadata from image files in a specified directory
  batch-thumbnail       Batch generate thumbnails for image files in a specified directory
  batch-watermark       Batch add watermarks to image files
  compress              Compress and optimize a single image file
  convert               Convert a single image file
  crop                  Crop a single image file
  info                  View detailed information of an image file
  resize                Resize a single image file
  strip-metadata        Strip metadata from a single image file
  thumbnail             Generate a thumbnail for a single image file
  watermark             Add a watermark to a single image file

Use 'ImageGlider.Cli help <command>' to view detailed help for a specific command.

Examples:
  ImageGlider.Cli convert -s image.jfif -t image.jpeg -q 85
  ImageGlider.Cli batch-convert -se .jfif -te .jpeg -q 90
  ImageGlider.Cli resize -s input.jpg -t output.jpg -w 800 -h 600
  ImageGlider.Cli compress -s input.jpg -t output.jpg -l 60
  ImageGlider.Cli help convert

AOT and Other Methods

Installation via other methods (such as scoop, brew) and AOT compilation releases will not be detailed in this article. Please refer to the Project Documentation.

Summary

This development workflow is so pleasant that I even want to integrate it into my template project FluentConsole.

Next, I will publish several articles related to this workflow. If you are interested, feel free to follow along.

关于本文

Pure C# implementation + AOT-built multifunctional image processing tool ImageGlider

本文作者:程序设计实验室

版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
讨论

讨论

共 0 条

加载评论中…

相关文章

C#学习(三)深入理解委托、匿名方法和-Lambda-表达式

前言 lambda的概念建立在委托的基础上,委托,实现了类型安全的回调方法。在.NET 中回调无处不在,所以委托也无处不在,事件模型建立在委托机制上,Lambda 表达式本质上就是一种匿名委托。本文中将完成一次关于委托的旅行,全面阐述委托及其核心话题,逐一梳理委托、委托链、事件、匿名方法和 Lambda 表达式。 委托的定义 了解委托,从其定义开始,通常一个委托被声明为: public deleg

2021-12-18 · C# · 约 1 分钟

讨论