z_media_preview (zotonic_core v1.0.0-rc.12)

Make still previews of media, using image manipulation functions. Resize, crop, grey, etc. This uses the command line imagemagick tools for all image manipulation. This code is adapted from PHP GD2 code, so the resize/crop could've been done more efficiently, but it works :-)

Link to this section 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.
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.

Link to this section Functions

Link to this function

can_generate_preview(B)

-spec can_generate_preview(binary() | string()) -> boolean().
Check if we can generate a preview image of the given mime type
Link to this function

cmd_args(FileProps, Filters, OutMime)

Map filters to commandline options
Link to this function

convert(InFile, OutFile, Filters, Context)

-spec convert(file:filename_all(), file:filename_all(), list(), #context{}) -> ok | {error, term()}.
Convert the Infile to an outfile with a still image using the filters.
Link to this function

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

Link to this function

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.
Link to this function

out_mime(Mime, Options, Context)

Determine the output mime type, after expanding optional mediaclass arguments.
Link to this function

size(Props, Filters, Context)

Calculate the size of the resulting image.
Link to this function

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.