z_media_identify (zotonic_core v1.0.0-rc.10)

Identify files, fetch metadata about an image

Link to this section Summary

Functions

Return the extension for a known mime type (eg. ".mov").
Return the extension for a known mime type (eg. ".mov"). When multiple extensions are found for the given mime type, returns the one that is given as the preferred extension. Otherwise, it returns the first extension.
Guess the mime type of a file by the extension of its filename.
Caching version of identify/3. Fetches information about an image, returns width, height, type, etc.
Fetch information about a file, returns mime, width, height, type, etc. First checks if a module has a specific identification methods.
Fetch information about a file, returns mime, width, height, type, etc.
Given a mime type, return whether its file contents is already compressed or not.

Link to this section Types

Link to this type

filename_extension/0

-type filename_extension() :: binary().
Link to this type

media_info/0

-type media_info() :: map().
-type mime_type() :: binary().
Link to this type

optional_filename/0

-type optional_filename() :: undefined | file:filename_all().
-type os_family() :: win32 | unix.

Link to this section Functions

Link to this function

extension(Mime)

-spec extension(Mime) -> filename_extension()
             when Mime :: string() | binary() | {binary(), binary(), list()}.
Return the extension for a known mime type (eg. ".mov").
Link to this function

extension(Mime, PreferExtension)

-spec extension(Mime, PreferExtension) -> filename_extension()
             when
                 Mime :: string() | binary() | {binary(), binary(), list()},
                 PreferExtension :: string() | binary() | undefined.
Link to this function

extension(Mime, PreferExtension, Context)

-spec extension(Mime, PreferExtension, z:context()) -> filename_extension()
             when
                 Mime :: string() | binary() | {binary(), binary(), list()},
                 PreferExtension :: string() | binary() | undefined.
Return the extension for a known mime type (eg. ".mov"). When multiple extensions are found for the given mime type, returns the one that is given as the preferred extension. Otherwise, it returns the first extension.
Link to this function

guess_mime(File)

-spec guess_mime(file:filename_all()) -> mime_type().
Guess the mime type of a file by the extension of its filename.
Link to this function

identify(Upload, Context)

-spec identify(#upload{} | file:filename_all(), z:context()) -> {ok, media_info()} | {error, term()}.
Caching version of identify/3. Fetches information about an image, returns width, height, type, etc.
Link to this function

identify(File, OriginalFilename, Context)

-spec identify(#upload{} | file:filename_all(), optional_filename(), z:context()) ->
            {ok, media_info()} | {error, term()}.
Link to this function

identify(File, MediumFilename, OriginalFilename, Context)

Link to this function

identify_file(File, Context)

-spec identify_file(file:filename_all(), z:context()) -> {ok, media_info()} | {error, term()}.
Fetch information about a file, returns mime, width, height, type, etc. First checks if a module has a specific identification methods.
Link to this function

identify_file(File, OriginalFilename, Context)

-spec identify_file(file:filename_all(), optional_filename(), z:context()) ->
                 {ok, media_info()} | {error, term()}.
Link to this function

identify_file_direct(File, OriginalFilename)

-spec identify_file_direct(file:filename_all(), optional_filename()) ->
                        {ok, media_info()} | {error, term()}.
Fetch information about a file, returns mime, width, height, type, etc.
Link to this function

is_mime_compressed(_)

-spec is_mime_compressed(binary()) -> boolean().
Given a mime type, return whether its file contents is already compressed or not.
Link to this function

is_mime_vector(Mime)

-spec is_mime_vector(string() | mime_type()) -> boolean().