IHP Api Reference
Copyright(c) digitally induced GmbH 2021
Safe HaskellNone

IHP.FileStorage.Preprocessor.ImageMagick

Description

 
Synopsis

Documentation

applyImageMagick :: Text -> [String] -> FileInfo LByteString -> IO (FileInfo LByteString) Source #

Converts the image to the specified output format and applies specified image magick transforms

Example: Transform an uploaded image to a PNG file, resize it to 512x512 and strip meta data

let uploadLogo = uploadToStorageWithOptions $ def
        { preprocess = applyImageMagick "png" ["-resize", "512x512^", "-gravity", "north", "-extent" , "512x512", "-quality", "100%", "-strip"] }

company <- fetch companyId
company
    |> fill @'["name"]
    |> uploadLogo #logoUrl
    >>= ifValid \case
        Left company -> render EditView { .. }
        Right company -> do
            company <- company |> updateRecord
            redirectTo EditCompanyAction { .. }

Example: Transform an uploaded image to a JPEG file and strip meta data

let uploadLogo = uploadToStorageWithOptions $ def
        { preprocess = applyImageMagick "jpg" ["-strip"] }

company <- fetch companyId
company
    |> fill @'["name"]
    |> uploadLogo #logoUrl
    >>= ifValid \case
        Left company -> render EditView { .. }
        Right company -> do
            company <- company |> updateRecord
            redirectTo EditCompanyAction { .. }