GithubHelp home page GithubHelp logo

artkay / imgproxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bmuller/imgproxy

0.0 0.0 0.0 15 KB

Elixir module to generate imgproxy URLs

Home Page: https://hexdocs.pm/imgproxy

License: MIT License

Elixir 100.00%

imgproxy's Introduction

Imgproxy

Build Status Hex pm API Docs

Imgproxy is an Elixir library that helps generate imgproxy URLs. Before using this library, you should have a running imgproxy server.

Installation

To install Imgproxy, just add an entry to your mix.exs:

def deps do
  [
    # ...
    {:imgproxy, "~> 1.0"}
  ]
end

(Check Hex to make sure you're using an up-to-date version number.)

Configuration

In your config/config.exs you can set a few options:

config :imgproxy,
  prefix: "https://imgcdn.example.com",
  key: "cdf104fc78b7d7f6f0158c253612f5dsecretsecret...",
  salt: "aad7034f611b7fc28c6d344f72ea19secretsecret..."

The prefix should be the location of the imgproxy server. key and salt are only necessary if you are using URL signatures. To generate the key a key and salt, you can use:

$> mix imgproxy.gen.secret

You can use the output as your key or salt (ideally, just run the command twice, use the first output for your key and the second output for your salt).

Usage

Usage is basically constrained to the url function, which accepts the original URL for an image and optional parameters for image conversion.

Example:

# Generate URL for an image, using defaults
Imgproxy.url("https://placekitten.com/200/300")

# Set all parameters
Imgproxy.url("https://placekitten.com/200/300",
  resize: "fill",
  width: 123,
  height: 321,
  gravity: "sm",
  enlarge: "1",
  extension: "jpg")

# Generate URL for an image with set width of 150 and
# height of 200, and all other defaults.  This signature
# is useful if you just want to set width/height.
Imgproxy.url("https://placekitten.com/200/300", 150, 200)

The optional parameters are:

  • resize: default, "fill"
  • width and height: default, 300x300
  • gravity: default, "sm" for smart. libvips detects the most "interesting" section of the image and considers it as the center of the resulting image.
  • enlarge: default, "1"
  • extension: default, attempts to preserve the original image type

The imgproxy docs have more details on what each of these options indicate.

Running Tests

To run tests:

$> mix test

Reporting Issues

Please report all issues on github.

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.