Giter Club home page Giter Club logo

elm-thumbor's Introduction

elm-thumbor

Build Status

Generate Thumbor URLs with Elm.

This package implements all documented Thumbor options and filters for easy use within your Elm applications. It implements the, as of writing, current Tumbor version of 6.7.0.

This package takes some liberties in API design to make it type-safe, but tries to stay close to the original Thumbor API naming and usage to make mapping between the official documentation as easy as possible.

Example

view : Model -> Html msg
view model =
    model.teaserImages
        |> List.map (\imageUrl -> img [ src (scaleTeaserImage imageUrl) ] [])
        |> div []


scaleTeaserImage : String -> String
scaleTeaserImage =
    thumbor
        [ Thumbor.sizeFixed 500 500
        , Thumbor.fitIn Thumbor.NormalFitIn
        , Thumbor.filters
            [ Thumbor.Filter.noUpscale
            , Thumbor.Filter.format Thumbor.Filter.Jpeg
            , Thumbor.Filter.quality 80
            , Thumbor.Filter.watermark
                { imageUrl = "https://example.com/images/watermark.png"
                , horizontalPosition = Thumbor.Filter.LeftPixels 10
                , verticalPosition = Thumbor.Filter.BottomPixels 10
                , alphaPercentage = 50
                , widthRatio = Nothing
                , heightRatio = Nothing
                }
            ]
        ]


thumbor : List Thumbor.Attribute -> String -> String
thumbor =
    Thumbor.url { baseUrl = "https://example.com", key = Just "secret" }

Security Considerations

Since Elm applications mostly run in client's browsers directly, the key for URL signing is available in clear-text. This nullifies the whole purpose of URL signing to make tampering impossible. This might be okay for your use-case but you usually have to think about a better way to protect yourself from malicious Thumbor requests when you use this package.

For details about Thumbors URL signing, see: https://thumbor.readthedocs.io/en/latest/security.html

elm-thumbor's People

Watchers

 avatar  avatar  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.