Skip to content

Commit

Permalink
added support for launch images for android
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-m-sharpe committed Sep 8, 2019
1 parent 06497e9 commit 4e77b48
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
lane :test3 do
# `appicon_image_file` defaults to "fastlane/metadata/app_icon.png"
appicon(
appicon_devices: [:iphone],
appicon_devices: [:iphone],
appicon_path: 'wwdcfamily/Images.xcassets' # output path
)
end
Expand All @@ -73,6 +73,12 @@ lane :android do
appicon_path: 'app/res/drawable',
appicon_filename: 'ic_notification'
)
android_appicon(
appicon_image_file: 'spec/fixtures/splash_base_image.png',
appicon_icon_types: [:splash_port, :splash_land],
appicon_path: 'app/res/drawable',
appicon_filename: 'splash'
)
end
```

Expand Down
72 changes: 44 additions & 28 deletions lib/fastlane/plugin/appicon/actions/android_appicon_action.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'mini_magick'

module Fastlane
module Actions
class AndroidAppiconAction < Action

def self.needed_icons
{
launcher: {
Expand All @@ -19,13 +22,21 @@ def self.needed_icons
:xxhdpi => ['72x72'],
:xxxhdpi => ['96x96'],
},
launch_image: {
:ldpi => ['200x320'],
:mdpi => ['320x480'],
:hdpi => ['480x800'],
:xhdpi => ['720x1280'],
:xxhdpi => ['960x1600'],
:xxxhdpi => ['1280x1920'],
splash_land: {
'land-ldpi' => ['320x200'],
'land-mdpi' => ['480x320'],
'land-hdpi' => ['800x480'],
'land-xhdpi' => ['1280x720'],
'land-xxhdpi' => ['1600x960'],
'land-xxxhdpi' => ['1920x1280']
},
splash_port: {
'port-ldpi' => ['200x320'],
'port-mdpi' => ['320x480'],
'port-hdpi' => ['480x800'],
'port-xhdpi' => ['720x1280'],
'port-xxhdpi' => ['960x1600'],
'port-xxxhdpi' => ['1280x1920']
}
}
end
Expand All @@ -34,22 +45,11 @@ def self.run(params)
fname = params[:appicon_image_file]
custom_sizes = params[:appicon_custom_sizes]

require 'mini_magick'
image = MiniMagick::Image.open(fname)

params[:appicon_icon_types].each do |type|
if type.to_s != 'launch_image'
Helper::AppiconHelper.check_input_image_size(image, 512)
end
end

# Convert image to png
image.format 'png'

icons = Helper::AppiconHelper.get_needed_icons(params[:appicon_icon_types], self.needed_icons, true, custom_sizes)
icons.each do |icon|
width = icon['width']
height = icon['height']
image = MiniMagick::Image.open(fname)

Helper::AppiconHelper.check_input_image_size(image, 1024)

# Custom icons will have basepath and filename already defined
if icon.has_key?('basepath') && icon.has_key?('filename')
Expand All @@ -59,16 +59,32 @@ def self.run(params)
basepath = Pathname.new("#{params[:appicon_path]}-#{icon['scale']}")
filename = "#{params[:appicon_filename]}.png"
end
FileUtils.mkdir_p(basepath)

image.resize "#{width}x#{height}"
width_height = [icon['width'], icon['height']].map(&:to_i)
width, height = width_height
max = width_height.max

image.format 'png'
image.resize "#{max}x#{max}"

unless width == height
offset =
if width > height
"+0+#{(width - height) / 2}"
elsif height > width
"+#{(height - width) / 2}+0"
end

image.crop "#{icon['size']}#{offset}"
end

FileUtils.mkdir_p(basepath)
image.write basepath + filename

if icon['device'] == 'launcher'
foreground_size = ((width * 2.25) - width) / 2
# https://github.com/dlemstra/Magick.NET/issues/57
system "convert #{basepath + filename} -bordercolor none -border #{foreground_size}x#{foreground_size} #{basepath}/#{params[:appicon_filename]}_foreground.png"
system "convert #{fname} -alpha set \\( +clone -distort DePolar 0 -virtual-pixel HorizontalTile -background None -distort Polar 0 \\) -compose Dst_In -composite -trim +repage -resize #{width}x#{height} #{basepath}/#{params[:appicon_filename]}_round.png"
if basepath.to_s.match("port-")
default_portrait_path = basepath.to_s.gsub("port-","")
FileUtils.mkdir_p(default_portrait_path)
image.write default_portrait_path + '/' + filename
end
end

Expand Down

0 comments on commit 4e77b48

Please sign in to comment.