2020-10-21 21:31:47 +03:00
|
|
|
module Cloudinary exposing (url, urlSquare)
|
2020-10-21 21:17:10 +03:00
|
|
|
|
|
|
|
import MimeType
|
2021-05-24 01:11:46 +03:00
|
|
|
import Pages.Url
|
2020-10-21 21:17:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
url :
|
|
|
|
String
|
|
|
|
-> Maybe MimeType.MimeImage
|
|
|
|
-> Int
|
2021-05-24 01:11:46 +03:00
|
|
|
-> Pages.Url.Url
|
2020-10-21 21:17:10 +03:00
|
|
|
url asset format width =
|
2020-10-21 21:31:47 +03:00
|
|
|
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
|
2021-05-24 01:11:46 +03:00
|
|
|
Pages.Url.external (base ++ "/" ++ transforms ++ "/" ++ asset)
|
2020-10-21 21:31:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
urlSquare :
|
|
|
|
String
|
|
|
|
-> Maybe MimeType.MimeImage
|
|
|
|
-> Int
|
2021-05-24 01:11:46 +03:00
|
|
|
-> Pages.Url.Url
|
2020-10-21 21:31:47 +03:00
|
|
|
urlSquare asset format width =
|
2020-10-21 21:17:10 +03:00
|
|
|
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
|
2021-05-24 01:11:46 +03:00
|
|
|
Pages.Url.external (base ++ "/" ++ transforms ++ "/" ++ asset)
|