MobDev.IconGenerator (mob_dev v0.3.34)

Copy Markdown View Source

Generates app icons for Android and iOS from either a random robot avatar (using Avatarz) or a provided source image (using Image).

When the image dep is not available, falls back to the bundled Mob logo (pre-built PNGs shipped with mob_dev, no system tools required).

Android sizes (mipmap buckets)

Bucketpx
mdpi48
hdpi72
xhdpi96
xxhdpi144
xxxhdpi192

iOS sizes (AppIcon.appiconset subset)

Usagepx
iPhone Notification 2x40
iPhone Notification 3x60
iPhone Settings 2x58
iPhone Settings 3x87
iPhone Spotlight 2x80
iPhone Spotlight 3x120
iPhone App 2x120
iPhone App 3x180
iPad Notification 1x20
iPad Notification 2x40
iPad Settings 1x29
iPad Settings 2x58
iPad Spotlight 1x40
iPad Spotlight 2x80
iPad App 1x76
iPad App 2x152
iPad Pro App 2x167
App Store1024

Summary

Functions

Returns the XML body for mipmap-anydpi-v26/ic_launcher.xml.

Returns the map of Android mipmap bucket names to pixel dimensions for adaptive-icon foreground layers (108×108 dp scaled per density).

Returns the map of Android mipmap bucket names to pixel dimensions for legacy (single-layer) icons.

Returns the XML body for values/ic_launcher_background.xml defining the adaptive icon background colour.

Generates adaptive Android icons from a source image.

Resizes an existing image at source_path to all platform icon sizes, writing them into output_dir.

Generates a random robot avatar and writes platform icons into output_dir.

Returns the list of iOS icon pixel dimensions.

Copies the bundled Mob logo (pre-built PNGs) to all platform icon directories in output_dir. Used as the default placeholder icon by mix mob.install. No extra dependencies or system tools required.

Functions

adaptive_icon_xml()

@spec adaptive_icon_xml() :: String.t()

Returns the XML body for mipmap-anydpi-v26/ic_launcher.xml.

Uses @mipmap/ic_launcher_foreground for the foreground and @color/ic_launcher_background for the background.

adaptive_sizes()

@spec adaptive_sizes() :: %{required(String.t()) => pos_integer()}

Returns the map of Android mipmap bucket names to pixel dimensions for adaptive-icon foreground layers (108×108 dp scaled per density).

android_sizes()

@spec android_sizes() :: %{required(String.t()) => pos_integer()}

Returns the map of Android mipmap bucket names to pixel dimensions for legacy (single-layer) icons.

background_color_xml(hex)

@spec background_color_xml(String.t()) :: String.t()

Returns the XML body for values/ic_launcher_background.xml defining the adaptive icon background colour.

Accepts hex strings with or without a leading # (case-insensitive). Raises ArgumentError for non-hex input.

generate_adaptive(source_path, output_dir, opts \\ [])

@spec generate_adaptive(
  source_path :: String.t(),
  output_dir :: String.t(),
  keyword()
) :: :ok

Generates adaptive Android icons from a source image.

Writes:

  • mipmap-anydpi-v26/ic_launcher.xml + ic_launcher_round.xml referencing @mipmap/ic_launcher_foreground and @color/ic_launcher_background
  • mipmap-<bucket>/ic_launcher_foreground.png at the adaptive icon canvas size for each density bucket
  • values/ic_launcher_background.xml defining the background color

Options

  • :background_color — hex string like "#E8B53C". If absent, sampled from the source image at top-centre (10% from the top).

Legacy ic_launcher.png/ic_launcher_round.png are written separately by generate_from_source/2 for older Android versions.

generate_from_source(source_path, output_dir)

@spec generate_from_source(source_path :: String.t(), output_dir :: String.t()) :: :ok

Resizes an existing image at source_path to all platform icon sizes, writing them into output_dir.

Returns :ok.

generate_random(output_dir)

@spec generate_random(output_dir :: String.t()) :: :ok

Generates a random robot avatar and writes platform icons into output_dir.

Creates:

  • output_dir/android/app/src/main/res/<bucket>/ic_launcher.png for each Android bucket
  • output_dir/ios/Assets.xcassets/AppIcon.appiconset/icon_<px>.png for each iOS size
  • output_dir/icon_source.png — the 1024×1024 master

Returns :ok on success.

ios_sizes()

@spec ios_sizes() :: [pos_integer()]

Returns the list of iOS icon pixel dimensions.

use_mob_logo(output_dir)

@spec use_mob_logo(output_dir :: String.t()) :: :ok

Copies the bundled Mob logo (pre-built PNGs) to all platform icon directories in output_dir. Used as the default placeholder icon by mix mob.install. No extra dependencies or system tools required.

Returns :ok.