z_media_preview (zotonic_core v1.0.0-rc.17)

Make still previews of media, using image manipulation functions. Resize, crop, grey, etc. This uses the command line imagemagick tools for all image manipulation.

Summary

Functions

Check if we can generate a preview image of the given mime type

Map filters to commandline options

Convert the Infile to an outfile with a still image using the filters.

Detect the ImageMagick executable using the supplied finder function. The finder has the same signature as os:find_executable/1 and returns either a path string or false. Separating this logic from the caching wrapper makes the v6/v7 detection deterministically testable.

Return the preferred mime type of the image generated by resizing an image of a certain type and size.

Determine the output mime type, after expanding optional mediaclass arguments.

Calculate the size of the resulting image.

Map the list of known filters and known args to atoms. Used when mapping preview urls back to filter args.

Functions

calc_size(S)

can_generate_preview(B)

-spec can_generate_preview(binary() | string()) -> boolean().

Check if we can generate a preview image of the given mime type

cmd_args(FileProps, Filters, OutMime)

Map filters to commandline options

convert(InFile, OutFile, Filters, Context)

-spec convert(InFile, OutFile, Filters, Context) -> ok | {error, Reason}
                 when
                     InFile :: file:filename_all(),
                     OutFile :: file:filename_all(),
                     Filters :: list(),
                     Context :: z:context(),
                     Reason :: will_overwrite_infile | term().

Convert the Infile to an outfile with a still image using the filters.

convert(InFile, MediumFilename, OutFile, Filters, Context)

imagemagick_detect(FindExe)

-spec imagemagick_detect(FindExe) -> #{cmd := string() | false, legacy := boolean()}
                            when FindExe :: fun((string()) -> string() | false).

Detect the ImageMagick executable using the supplied finder function. The finder has the same signature as os:find_executable/1 and returns either a path string or false. Separating this logic from the caching wrapper makes the v6/v7 detection deterministically testable.

is_legacy_imagemagick()

-spec is_legacy_imagemagick() -> boolean().

out_mime(InMime, Options)

-spec out_mime(InMime :: binary(), list()) -> {OutMime :: binary(), Extension :: string()}.

Return the preferred mime type of the image generated by resizing an image of a certain type and size.

out_mime(Mime, Options, Context)

Determine the output mime type, after expanding optional mediaclass arguments.

size(Props, Filters, Context)

-spec size(term(), term(), z:context()) -> {size, term(), term(), term()} | {error, term()}.

Calculate the size of the resulting image.

string2filter(Filter, Where)

-spec string2filter(string(), string()) -> {ok, tuple() | atom()} | {error, term()}.

Map the list of known filters and known args to atoms. Used when mapping preview urls back to filter args.