View Source Image.Social (image v0.33.0)
Functions to introspect standard image sizes for various social media platforms.
Link to this section Summary
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.
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
| :tiktok
The known social media platforms.
Link to this section Functions
@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
Arguments
platform
is any known social platform. SeeImage.Social.known_platforms/0
.
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
platform
is any known social platform. SeeImage.Social.known_platforms/0
.
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.
@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
Arguments
image
is anyVix.Vips.Image.t/0
platform
is the name of a known social media platform. SeeImage.Social.known_platforms/0
.options
is a keyword list of options.
options
Options
:type
is the image type within the social platform for which the image should be resized. SeeImage.Social.image_usages/1
All other options are passed to
Image.thumbnail!/3
.
returns
Returns
{:ok, resized_image}
or{:error, reason}
@spec resize!(Vix.Vips.Image.t(), platform(), Keyword.t()) :: Vix.Vips.Image.t() | no_return()
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
image
is anyVix.Vips.Image.t/0
platform
is the name of a known social media platform. SeeImage.Social.known_platforms/0
.options
is a keyword list of options.
options
Options
:type
is the image type within the social platform for which the image should be resized. SeeImage.Social.image_usages/1
All other options are passed to
Image.thumbnail!/3
.
returns
Returns
resized_image
orRaises an exception.