View Source Image.Social (image v0.2.0)

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

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

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.

Link to this section Types

@type image_usage() :: atom()

The social media platform image usage.

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

The known social media platforms.

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

arguments

Arguments

returns

Returns

  • The default image type for the platform.

example

Example

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

Returns the image types for the given social platform.

arguments

Arguments

returns

Returns

  • A list of images uses available for the platform.

example

Example

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

Returns a list of known social platforms.

example

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

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

Arguments

options

Options

returns

Returns

  • resized_image or

  • Raises an exception.

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 orientation aware
  • Converts to the sRGB color space
  • Minimises metadata (retains only Artist and Copyright)

arguments

Arguments

options

Options

returns

Returns

  • {:ok, resized_image} or

  • {:error, reason}