返回文章列表文章索引阅读全文
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.

_EOF_

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

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

C#中的Attribute与Python-TypeScript的装饰器是同个东西吗

前言 最近成功把「前端带师」带入C#的坑~~(实际是前端带师开始从cocos转unity游戏开发了)~~ 某天,「前端带师」看到这段代码后问了个问题:[这个是装饰器]? [HttpGet] public Response Get() { return ... } 我第一反应觉得不是,这玩意在C#中叫“特性”(英文名Attribute,下文统称为特性),在Java中叫注解,虽然写法和Pyth

2022-06-26 · C# · 约 1 分钟

C#中AES加密的实现

AES算法简介 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院(NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日

2022-05-27 · C# · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…