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.
_EOF_
Pure C# implementation + AOT-built multifunctional image processing tool ImageGlider
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
C#高性能数组拷贝实验
前言 昨天 wc(Wyu_Cnk) 提了个问题 C# 里多维数组拷贝有没有什么比较优雅的写法? 这不是问对人了吗?正好我最近在搞图像处理,要和内存打交道,我一下就想到了在C#里面直接像C/C++一样做内存拷贝。 优雅?no,要的就是装逼,而且性能还要强🕶 概念 首先澄清一下 C# 里的多维数组 (Multi-dimensional Array) 是这样的 byte[,] arr = new by
2023-01-30 · C# · 约 1 分钟
C#实现解析Markdown文档并处理图片链接
前言 又是好久没写博客了 其实也不是没写,是最近在「做一个博客」,从2月21日开始,大概一个多星期的时间,疯狂刷进度,边写代码边写了一整系列的博客开发笔记,目前为止已经写了16篇了,然后上3月之后工作有点忙~~加上有点沉迷原神~~,然后进度就暂时慢下来了 事实证明做什么事情一旦停下来就会产生惰性,于是停了这么久,我终于下定决心继续更新! 这次开发的博客用的是C#语言,搭配.netcore技术栈;前
2022-03-19 · C# · 约 1 分钟
C#爬虫:CatSpider#-开发笔记
前言 (PS:我这里用了#号代替了Sharp这个单词) CatSpider是毕设里的数据采集模块,本来爬虫类的应用肯定使用python来开发嘛,不过用request_html做解析的时候,python的动态类型真的把我恶心到了,而且感觉这个库也不是很成熟,html5lib也不好用,也没心思去深入了,之前看到有大佬用.net core平台做爬虫,于是我也来试试,没想到效果贼好,特别是配合LinqPa
2022-05-27 · C# · 约 1 分钟
开发现代化的.NetCore控制台程序:(1)项目介绍以及依赖注入/配置/日志等使用细节
开发.NET Core控制台工具,依赖注入和日志整合得比Go优雅多了。哼,配置文件丝滑,但AOT?反射问题,放弃。
2023-11-10 · C# · 约 1 分钟
讨论
共 0 条加载评论中…