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.
目录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 条加载评论中…
相关文章
System.Text.Json使用中的几个常见问题
前言 以前.NetCore是不内置JSON库的,所以大家都用Newtonsoft的JSON库,而且也确实挺好用的,不过既然官方出了标准库,那更方便更值得我们多用用,至少不用每次都nuget安装Newtonsoft.Json库了。 不过日常开发使用中会有一些问题,本文记录一下解决方法,欢迎交流~ ~~(文章末尾包含小彩蛋)~~ 字符编码问题 默认的 System.Text.Json 序列化的时候会把
2022-05-27 · C# · 约 1 分钟
C#学习(一)委托的概念和使用
前言 C#学习系列是根据我以前的笔记整理出来复习,顺便发一下文章做个记录。 先引用一个介绍: C# 中的委托(Delegate)类似于 C 或 C++ 中函数的指针。委托(Delegate) 是存有对某个方法的引用的一种引用类型变量。引用可在运行时被改变。 委托(Delegate)特别用于实现事件和回调方法。所有的委托(Delegate)都派生自 System.Delegate 类。 根据使用其他
2021-12-18 · C# · 约 1 分钟
C#中的Attribute与Python-TypeScript的装饰器是同个东西吗
前言 最近成功把「前端带师」带入C#的坑~~(实际是前端带师开始从cocos转unity游戏开发了)~~ 某天,「前端带师」看到这段代码后问了个问题:[这个是装饰器]? [HttpGet] public Response Get() { return ... } 我第一反应觉得不是,这玩意在C#中叫“特性”(英文名Attribute,下文统称为特性),在Java中叫注解,虽然写法和Pyth
2022-06-26 · C# · 约 1 分钟
使用C#和MemoryCache组件实现轮流调用APIKey以提高并发能力
本文介绍了如何利用C#语言中的MemoryCache组件,结合并发编程技巧,实现轮流调用多个API Key以提高系统的并发能力。通过示例代码和详细说明,读者将了解如何有效地管理API Key的调用次数限制,并优化系统性能。
2024-03-09 · C# · 约 1 分钟