Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

.NET binding for libvips.

License

NotificationsYou must be signed in to change notification settings

kleisauke/net-vips

Repository files navigation

NuGetCI status (Linux, macOS and Windows)CI status (NetVips nightly packaging)

This NuGet package provides a .NET binding for thelibvips image processing library.

This binding passes the vips test suite cleanly with no leaks on Windows, macOS and Linux.

We have formatted docs online here:

https://kleisauke.github.io/net-vips/

How it works

Programs that useNetVips don't manipulate images directly, insteadthey create pipelines of image processing operations building on a sourceimage. When the end of the pipe is connected to a destination, the wholepipeline executes at once, streaming the image in parallel from source todestination a section at a time.

BecauseNetVips is parallel, it's quick, and because it doesn't need tokeep entire images in memory, it's light. For example, theNetVips benchmark:

NetVips.Benchmarks

Loads a large image, shrinks by 10%, sharpens, and saves again. On this testNetVips is around 31 times faster than Magick.NET and 6 times faster than ImageSharp.

Thelibvips documentationhas achapter explaining how libvips opens fileswhich gives some more background.

Supported platforms

  • .NET Framework 4.6.2 and higher
  • .NET 6.0 and higher

Install

You need the libvips shared library on your library search path, version 8.2 orlater. There are separate NuGet packages that will contain the pre-compiledlibvips binaries for the most common platforms (seethis repo for details):

NuGet Package1
Windows 64-bitNetVips.Native.win-x64-badge
Windows 32-bitNetVips.Native.win-x86-badge
Windows ARM64NetVips.Native.win-arm64-badge
Linux x64 glibc2NetVips.Native.linux-x64-badge
Linux x64 musl3NetVips.Native.linux-musl-x64-badge
Linux ARM64v8 glibc2NetVips.Native.linux-arm64-badge
Linux ARM64v8 musl3NetVips.Native.linux-musl-arm64-badge
Linux ARMv7NetVips.Native.linux-arm-badge
macOS x64NetVips.Native.osx-x64-badge
macOS ARM64NetVips.Native.osx-arm64-badge

These binaries provides support for the JPEG, PNG, WebP, AVIF (limited to 8-bit depth), TIFF, GIF and SVG (input) image formats.

Then just install this package, perhaps:

Install-Package NetVips

To test your install, try this test program:

if(ModuleInitializer.VipsInitialized){Console.WriteLine($"Inited libvips{NetVips.Version(0)}.{NetVips.Version(1)}.{NetVips.Version(2)}");}else{Console.WriteLine(ModuleInitializer.Exception.Message);}Console.ReadLine();

If NetVips was able to find the libvips shared library, you should see:

Inited libvips [VERSION_NUMBER]

However, if you see something else, NetVips was unable to initialize libvips.This can happen for a variety of reasons, even though most of the times it's because NetVipswas not able to find libvips or due to x86/x64 architecture problems:

Inner exceptionHRESULTSolution
DllNotFoundException0x8007007EMake sure to add thebin folder of the libvips Windows build to yourPATH environment variable (if you wish to not use the separate NuGet packages).
BadImageFormatException0x8007000BMake sure when you target theAnyCPU platform thePrefer 32-bit option is unchecked. Or try to targetx64 instead.

Example

usingNetVips;usingvarim=Image.NewFromFile("image.jpg");// put im at position (100, 100) in a 3000 x 3000 pixel image,// make the other pixels in the image by mirroring im up / down /// left / right, see// https://www.libvips.org/API/current/method.Image.embed.htmlusingvarembed=im.Embed(100,100,3000,3000,extend:Enums.Extend.Mirror);// multiply the green (middle) band by 2, leave the other two aloneusingvarmultiply=embed*new[]{1,2,1};// make an image from an array constant, convolve with itusingvarmask=Image.NewFromArray(new[,]{{-1,-1,-1},{-1,16,-1},{-1,-1,-1}},8);usingvarconvolve=multiply.Conv(mask,precision:Enums.Precision.Integer);// finally, write the result back to a file on diskconvolve.WriteToFile("output.jpg");

Footnotes

  1. The version number of these NuGet packages is in sync with libvips' version number.

  2. Uses glibc as the standard C library (Ubuntu, Debian, etc).2

  3. Uses musl as the standard C library (Alpine, Gentoo Linux, etc).2

Sponsor this project

    Packages

    No packages published

    Contributors6

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp