z_media_identify (zotonic_core v1.0.0-rc.17)

Identify files, fetch metadata about an image

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.

Types

filename_extension/0

-type filename_extension() :: binary().

media_info/0

-type media_info() :: map().

mime_type/0

-type mime_type() :: binary().

optional_filename/0

-type optional_filename() :: undefined | file:filename_all().

os_family/0

-type os_family() :: win32 | unix.

Functions

extension(Mime)

-spec extension(Mime) -> filename_extension()
                   when Mime :: string() | binary() | cow_http_hd:media_type().

Return the extension for a known mime type (eg. ".mov").

extension(Mime, PreferExtension)

-spec extension(Mime, PreferExtension) -> filename_extension()
                   when
                       Mime :: string() | binary() | cow_http_hd:media_type(),
                       PreferExtension :: string() | binary() | undefined.

extension(Mime, PreferExtension, Context)

-spec extension(Mime, PreferExtension, z:context()) -> filename_extension()
                   when
                       Mime :: string() | binary() | cow_http_hd:media_type(),
                       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.

guess_mime(File)

-spec guess_mime(file:filename_all()) -> mime_type().

Guess the mime type of a file by the extension of its filename.

identify(Upload, Context)

-spec identify(#upload{filename :: binary() | undefined,
                       tmpfile :: file:filename_all() | undefined,
                       tmpmonitor :: undefined | pid(),
                       data :: binary() | undefined,
                       mime :: binary() | undefined} |
               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.

identify(File, OriginalFilename, Context)

-spec identify(#upload{filename :: binary() | undefined,
                       tmpfile :: file:filename_all() | undefined,
                       tmpmonitor :: undefined | pid(),
                       data :: binary() | undefined,
                       mime :: binary() | undefined} |
               file:filename_all(),
               optional_filename(),
               z:context()) ->
                  {ok, media_info()} | {error, term()}.

identify(File, MediumFilename, OriginalFilename, Context)

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.

identify_file(File, OriginalFilename, Context)

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

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.

is_mime_compressed(_)

-spec is_mime_compressed(binary()) -> boolean().

Given a mime type, return whether its file contents is already compressed or not.

is_mime_vector(Mime)

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