View Source Image.Social (image v0.56.0)

Functions to introspect standard image sizes for various social media platforms.

Summary

Types

The social media platform image usage.

The known social media platforms.

Functions

Returns the default image type that an image is resized to for a given platform is no :type parameter is provided.

Returns the image types for the given social platform.

Returns a list of known social platforms.

Return the map of social media image sizes.

Resize an image for a particular social platform and usage.

Resize an image for a particular social platform and usage.

Types

image_usage()

@type image_usage() :: atom()

The social media platform image usage.

platform()

@type platform() ::
  :facebook
  | :twitter
  | :linkedin
  | :pinterest
  | :instagram
  | :tumblr
  | :youtube
  | :snapchat
  | :tiktok

The known social media platforms.

Functions

default_image_usage(platform)

@spec default_image_usage(platform()) :: image_usage()

Returns the default image type that an image is resized to for a given platform is no :type parameter is provided.

Arguments

Returns

  • The default image type for the platform.

Example

image_usages(platform)

@spec image_usages(platform()) :: [image_usage()]

Returns the image types for the given social platform.

Arguments

Returns

  • A list of images uses available for the platform.

Example

known_platforms()

@spec known_platforms() :: [platform()]

Returns a list of known social platforms.

Example

media_sizes()

Return the map of social media image sizes.

The returned map of maps is of a standard form:

  • The first key is the platform name (ie :twitter)
  • The second key is the image type for the platform (ie :profile)
  • The third level is optional. But if it exists it must have three keys: :landscape, :portrait and :square

The values are all of the form "WxH" where W is the width in pixels and H is the height in pixels.

resize(image, platform, options \\ [])

@spec resize(Vix.Vips.Image.t(), platform(), Keyword.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

Resize an image for a particular social platform and usage.

This function:

  • Resizes an image to the correct dimensions, including being image aspect aware
  • Converts to the sRGB color space
  • Minimises metadata (retains only Artist and Copyright)

Arguments

Options

Returns

  • {:ok, resized_image} or

  • {:error, reason}

resize!(image, platform, options \\ [])

Resize an image for a particular social platform and usage.

This function:

  • Resizes an image to the correct dimensions, including being image orientation aware
  • Converts to the sRGB color space
  • Minimises metadata (retains only Artist and Copyright)

Arguments

Options

Returns

  • resized_image or

  • Raises an exception.