View Source Image.Social (image v0.53.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

@type image_usage() :: atom()

The social media platform image usage.

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

The known social media platforms.

Functions

Link to this function

default_image_usage(platform)

View Source
@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

@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

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

Returns a list of known social platforms.

Example

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.

Link to this function

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

View Source
@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}

Link to this function

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

View Source

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.