Giter VIP home page Giter VIP logo

unitee.imgproxyclient's Introduction

Nuget

Unitee.ImgProxy

Url generation for ImgProxy


https://www.nuget.org/packages/Unitee.ImgProxyClient/

Quick start

  1. Install the package (dotnet add package Unitee.ImgProxyClient)
  2. Configure your AppSettings:
{
    ...,

    "ImgProxy": {
        "Key": "mysecretkey", // optional
        "Salt": "mysecretsalt", // optional
        "BaseUrl": "https://my-instance-of-img-proxy-or-cdn.com"
    }
}

More info on how to generate salt and key: https://docs.imgproxy.net/configuration?id=url-signature Be sure you have correclty configured IMGPROXY_KEY and IMGPROXY_SALT on the server with the same values.
If Key or Salt is missing, we will generate insecure urls.

Remember, you can sign the url even if IMGPROXY_KEY or IMGPROXY_SALT has been provided. So that, you can first migrate the code, then the server.

  1. Register the service:
builder.Services.AddImgProxyClient(builder.Configuration, "max_bytes:1000000" /* optional */);

You can add global options that will be used for all requests.

  1. Use it from the controller:
public class MyController : Controller
{
    private readonly ImgProxyService _imgProxyService;
    private readonly MyUserManager _myUserManager;

    public MyController(ImgProxyService imgProxyService, MyUserManager myUserManager)
    {
        _imgProxyService = imgProxyService;
        _myUserManager = myUserManager
    }

    public MyAction()
    {
        return View(from user in _myUserManager.GetAll()
                    select new UserViewModel
                    {
                        Avatar = _imgProxyService.GetUrl(user.Avatar, new ImgProcessingOptions
                        {
                            Width = 32,
                            Height = 32,
                        }
                };
        )
    }
}

OR directly from cshtml (prefered)

  1. In _ViewImports.cshtml, add @using Unitee.ImgProxyClient

  2. Use it like:

@inject ImgProxyService _img;

@foreach (var user in Model)
{
   <img src="@_img.GetUrl(user.Avatar, new ImgProcessingOptions { Format = "wepb" })" />
}

Available options

List of the options implemented in the ImageProxyOptions.cs:

./Unitee.ImgProxyClient/ImgProcessingOptions.cs

Extra options

Use options for each request in the project

builder.Services.AddImgProxyClient(builder.Configuration, "max_bytes:10000");

Use the Extra field to add options that are not (yet) implemented in the ImgProcessingOptions:

_imgProxyService.GetUrl(user.Avatar, new ImgProcessingOptions
{
    Width = 32,
    Height = 32,
    Extra = "max_bytes:10000",
}

unitee.imgproxyclient's People

Contributors

titouancreach avatar justinvanier avatar

Watchers

 avatar Kostas Georgiou avatar

Forkers

justinvanier

unitee.imgproxyclient's Issues

Auto rotate

Ajouter l'option AutoRotate dans les options.

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.