mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 14:34:18 +03:00
76 lines
1.7 KiB
Elm
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)
|