GithubHelp home page GithubHelp logo

rolends1986 / webpwrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edward-hsu-1994/webpwrapper

0.0 1.0 0.0 343 KB

.NET Standard 2.0的WebP轉檔器包裝套件

License: MIT License

C# 99.50% Shell 0.50%

webpwrapper's Introduction

WebPWrapper

Build Status NuGet Version NuGet Download Github license

這是一個可以在.NET Standard 2.0環境運行的WebP包裝套件。提供包裝好的CLI參數建構器幫助調用WebP CLI。

有關WebP詳細資訊請參考官方網站: https://developers.google.com/speed/webp/

快速上手

安裝套件

dotnet add package WebPWrapper

編碼

using WebPWrapper;
using WebPWrapper.Encoder;

WebPExecuteDownloader.Download();

var builder = new WebPEncoderBuilder();

var encoder = builder
	.Resize(100, 0) // 調整寬度為100,等比縮放(因為高度為0)
	.AlphaConfig(x => x // 透明處理設定
		.TransparentProcess(
			TransparentProcesses.Blend, // 透明部分將底色視為黃色混合
			Color.Yellow
		)
	)
	.CompressionConfig(x => x // 壓縮設定
		.Lossless(y => y.Quality(75)) // 使用無損壓縮且壓縮品質設為75
	) 
	.Build(); // 建立編碼器

using (var outputFile = File.Open("output.webp", FileMode.Create))
using (var inputFile = File.Open("input.png", FileMode.Open)) {
	encoder.Encode(inputFile, outputFile); // 編碼
}

解碼

using WebPWrapper;
using WebPWrapper.Decoder; 

WebPExecuteDownloader.Download();

var builder = new WebPDecoderBuilder();

var encoder = builder
	.Resize(32, 0) // 調整寬度為32,等比縮放(因為高度為0)
	.Build(); // 建立解碼器
 
using (var outputFile = File.Open("output.png", FileMode.Create))
using (var inputFile = File.Open("input.webp", FileMode.Open)) {
	encoder.Decode(inputFile, outputFile); // 解碼
}

webpwrapper's People

Contributors

edward-hsu-1994 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.