• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    C#
  • License
    GNU Affero Genera...
  • Created about 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The official .NET API for Imageflow, the Rust image processing and optimization engine for web servers

.NET Core Build status

Imageflow.NET is a .NET API for Imageflow, the fast image optimization and processing library for web servers. Imageflow focuses on security, quality, and performance - in that order. Imageflow.NET is a .NET Standard 2.0 library, and as such is compatible with .NET 4.6.2+, .NET Core 2.0+, and .NET 5/6/7.

On .NET Core 3.x and .NET 5/6/7 (or if using PackageReference on .NET 4.x)

dotnet add package Imageflow.AllPlatforms

If you're still using packages.config on .NET 4.x (such as for ASP.NET projects), you have to install Imageflow directly

PM> Install-Package Imageflow.Net
PM> Install-Package Imageflow.NativeRuntime.win-x86 -pre
PM> Install-Package Imageflow.NativeRuntime.win-x86_64 -pre
PM> Install-Package Imageflow.NativeRuntime.osx-x86_64 -pre
PM> Install-Package Imageflow.NativeRuntime.ubuntu-x86_64 -pre

Note: On .NET 4.x you must install the appropriate NativeRuntime(s) in the project you are deploying - they have to copy imageflow.dll to the output folder. They are not copied transitively.

Also note: Older versions of Windows may not have the C Runtime installed (Install 32-bit or 64-bit).

License

  • Imageflow is dual licensed under a commercial license and the AGPLv3.
  • Imageflow.NET is tri-licensed under a commercial license, the AGPLv3, and the Apache 2 license.
  • Imageflow.NET Server is dual licensed under a commercial license and the AGPLv3.
  • We offer commercial licenses at https://imageresizing.net/pricing
  • Imageflow.NET's Apache 2 license allows for integration with non-copyleft products, as long as jobs are not actually executed (since the AGPLv3/commercial license is needed when libimageflow is linked at runtime). This can allow end-users to benefit from optional imageflow integration in products.

Examples

Getting image dimensions and format

using Imageflow.Fluent;

public async void TestGetImageInfo()
{
    var imageBytes = Convert.FromBase64String(
        "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");

    var info = await ImageJob.GetImageInfo(new BytesSource(imageBytes));
    
    Assert.Equal(info.ImageWidth, 1);
    Assert.Equal(info.ImageHeight, 1);
    Assert.Equal(info.PreferredExtension, "png");
    Assert.Equal(info.PreferredMimeType, "image/png");
}

Edit images with the fluent API

using Imageflow.Fluent;
public async Task TestAllJob()
{
    var imageBytes = Convert.FromBase64String(
        "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");
    using (var b = new ImageJob())
    {
        var r = await b.Decode(imageBytes)
            .FlipVertical()
            .FlipHorizontal()
            .Rotate90()
            .Rotate180()
            .Rotate270()
            .Transpose()
            .CropWhitespace(80, 0.5f)
            .Distort(30, 20)
            .Crop(0,0,10,10)
            .Region(-5,-5,10,10, AnyColor.Black)
            .RegionPercent(-10f, -10f, 110f, 110f, AnyColor.Transparent)    
            .BrightnessSrgb(-1f)
            .ContrastSrgb(1f)
            .SaturationSrgb(1f)
            .WhiteBalanceSrgb(80)
            .ColorFilterSrgb(ColorFilterSrgb.Invert)
            .ColorFilterSrgb(ColorFilterSrgb.Sepia)
            .ColorFilterSrgb(ColorFilterSrgb.Grayscale_Bt709)
            .ColorFilterSrgb(ColorFilterSrgb.Grayscale_Flat)
            .ColorFilterSrgb(ColorFilterSrgb.Grayscale_Ntsc)
            .ColorFilterSrgb(ColorFilterSrgb.Grayscale_Ry)
            .ExpandCanvas(5,5,5,5,AnyColor.FromHexSrgb("FFEECCFF"))
            .FillRectangle(2,2,8,8, AnyColor.Black)
            .ResizerCommands("width=10&height=10&mode=crop")
            .ConstrainWithin(5, 5)
            .Watermark(new BytesSource(imageBytes), 
                new WatermarkOptions()
                   .SetMarginsLayout(
                        new WatermarkMargins(WatermarkAlign.Image, 1,1,1,1), 
                        WatermarkConstraintMode.Within, 
                        new ConstraintGravity(90,90))
                    .SetOpacity(0.5f)
                    .SetHints(new ResampleHints().SetSharpen(15f, SharpenWhen.Always))
                    .SetMinCanvasSize(1,1))
            .EncodeToBytes(new MozJpegEncoder(80,true))
            .Finish().InProcessAsync();

        Assert.Equal(5, r.First.Width);
        Assert.True(r.First.TryGetBytes().HasValue);
    }
}

Generate multiple versions of one image

using Imageflow.Fluent;
public async Task TestMultipleOutputs()
{
    var imageBytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");
    using (var b = new ImageJob())
    {
        var r = await b.Decode(imageBytes).
            Constrain(new Constraint(ConstraintMode.Fit, 160, 120))
            .Branch(f => f.ConstrainWithin(80, 60).EncodeToBytes(new WebPLosslessEncoder()))
            .Branch(f => f.ConstrainWithin(40, 30).EncodeToBytes(new WebPLossyEncoder(50)))
            .EncodeToBytes(new LodePngEncoder())
            .Finish().InProcessAsync();

        Assert.Equal(60, r.TryGet(1).Width);
        Assert.Equal(30, r.TryGet(2).Width);
        Assert.Equal(120, r.TryGet(3).Width);
        Assert.True(r.First.TryGetBytes().HasValue);
    }

}

Edit images using a command string

using Imageflow.Fluent;

public async Task TestBuildCommandString()
{
    var imageBytes = Convert.FromBase64String(
        "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");
    // We wrap the job in a using() statement to free memory faster
    using (var b = new ImageJob())
    {
        
        var r = await b.BuildCommandString(
            new BytesSource(imageBytes), // or new StreamSource(Stream stream, bool disposeStream)
            new BytesDestination(), // or new StreamDestination
            "width=3&height=2&mode=stretch&scale=both&format=webp&webp.quality=80")
            .Finish().InProcessAsync();

        Assert.Equal(3, r.First.Width);
        Assert.Equal("webp", r.First.PreferredExtension);
        Assert.True(r.First.TryGetBytes().HasValue);
    }
}

More examples are in the tests

More Repositories

1

imageflow

High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
Rust
4,154
star
2

resizer

The official repository for ImageResizer
C#
567
star
3

imageflow-dotnet-server

A super-fast image server to speed up your site - deploy as a microservice, serverless, or embeddable.
C#
248
star
4

slimmage

Context-friendly responsive image solution
JavaScript
167
star
5

libwebp-net

A .NET wrapper for libwebp
C#
136
star
6

studiojs

[Deprecated] A set of jQuery plugins that compose a flexible, web-based image editing studio.
JavaScript
92
star
7

imageflow-node

An Image manipulation Library for Nodejs. Based on https://github.com/imazen/imageflow
TypeScript
87
star
8

Graphics-vNext

The future of server-side graphics in ASP.NET
C#
68
star
9

keyhub

License management portal from Imazen & Lucrasoft. Looking for new maintainer (has been replaced by Chargebee, S3, & a ruby script)
C#
52
star
10

reunion

Repeatable, evidence-based expense and income accounting
Ruby
39
star
11

freeimage

DEPRECATED. This repository is not maintained, it is an old mirror of the inactive FreeImage project
C
34
star
12

hardwired

Hardwired - A 'NonCMS' for coders that applies the DRY and KISS principles to both content and code.
Ruby
25
star
13

imageflow-go

Go bindings for Imageflow -> https://github.com/imazen/imageflow
Go
17
star
14

resizer-web

Less
16
star
15

folioxml

Folio Flat File to XML/HTML/Lucene conversion framework
Java
12
star
16

slimresponse

Painless responsive images for .Net with Slimmage and ImageResizer
C#
11
star
17

resizer-images

This repository holds the ASP.NET project we use to deploy ImageResizer to z.zr.io
JavaScript
7
star
18

imageflow-ruby

These bindings are a work in progress; do not use
Ruby
5
star
19

repositext-idml-inspection

CSS
5
star
20

psdplugin-with-text

Fork of PsdPlugin with support for reading (and rendering) text layers
C#
4
star
21

reunion-sample

Starter sample for working with reunion
Ruby
4
star
22

repositext

Ruby
4
star
23

gd-libgd

Fork of LibGD for Windows & .NET support [deprecated]
C
3
star
24

libjpeg-turbo

DEPRECATED! Use libjpegturbo (without the dash) instead!
C
3
star
25

imageflow-web

Jekyll site for imageflow.io
HTML
3
star
26

imagetones

Tiny library to extract primary colors from a Bitmap.
C#
2
star
27

repositext-guide

Getting started with Repositext
Ruby
2
star
28

deprecated-gd-bindings-generator-old

Generates .NET bindings for libgd using CppSharp.
C#
2
star
29

dockerfiles_imageflow

DEPRECATED - do not use. These have been moved to imazen/imageflow/docker
Dockerfile
2
star
30

rust-openssl

Rust
1
star
31

repositext-web

repositext.org source
CSS
1
star
32

resizer-docs

Doxygen and Docu documentation for the ImageResizer project and its plugins
Graphviz (DOT)
1
star
33

ruby-vips-riapi

An experimental ruby wrapper for VIPS which may eventually be RIAPI compliant.
Ruby
1
star
34

suspension

Enables cross-format merging through token suspension.
Ruby
1
star
35

dhcpmanager

Better DHCP reservation management for Windows Server
JavaScript
1
star
36

gd-appveyor-helpers

PowerShell
1
star
37

hardwired-sample-minimal

An absurdly minimal example of a site running Hardwired
Ruby
1
star
38

collected

Collects documentation and API info from Imageflow*/ImageResizer* into a single markdown file for AI support use.
Python
1
star
39

paragon

Help create a demo for delivering unmanaged dependencies with NuGet
1
star
40

gd-dotnet-bindings-generator

Generates C# bindings for the LibGD library
C#
1
star