elm-pages-v3-beta/plugins/Cloudinary.elm
2021-04-10 13:51:39 -07:00

76 lines
1.7 KiB
Elm

module Cloudinary exposing (url, urlSquare)
import MimeType
import Pages.ImagePath as ImagePath exposing (ImagePath)
url :
String
-> Maybe MimeType.MimeImage
-> Int
-> ImagePath
url asset format width =
let
base =
"https://res.cloudinary.com/dillonkearns/image/upload"
fetch_format =
case format of
Just MimeType.Png ->
"png"
Just (MimeType.OtherImage "webp") ->
"webp"
Just _ ->
"auto"
Nothing ->
"auto"
transforms =
[ "c_pad"
, "w_" ++ String.fromInt width
, "q_auto"
, "f_" ++ fetch_format
]
|> String.join ","
in
ImagePath.external (base ++ "/" ++ transforms ++ "/" ++ asset)
urlSquare :
String
-> Maybe MimeType.MimeImage
-> Int
-> ImagePath
urlSquare asset format width =
let
base =
"https://res.cloudinary.com/dillonkearns/image/upload"
fetch_format =
case format of
Just MimeType.Png ->
"png"
Just (MimeType.OtherImage "webp") ->
"webp"
Just _ ->
"auto"
Nothing ->
"auto"
transforms =
[ "c_pad"
, "w_" ++ String.fromInt width
, "h_" ++ String.fromInt width
, "q_auto"
, "f_" ++ fetch_format
]
|> String.join ","
in
ImagePath.external (base ++ "/" ++ transforms ++ "/" ++ asset)