diff --git a/README.md b/README.md index 9291cfe..2256a35 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/lib/fastlane/plugin/appicon/actions/android_appicon_action.rb b/lib/fastlane/plugin/appicon/actions/android_appicon_action.rb index 3c4cbc8..857e43f 100644 --- a/lib/fastlane/plugin/appicon/actions/android_appicon_action.rb +++ b/lib/fastlane/plugin/appicon/actions/android_appicon_action.rb @@ -1,6 +1,9 @@ +require 'mini_magick' + module Fastlane module Actions class AndroidAppiconAction < Action + def self.needed_icons { launcher: { @@ -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 @@ -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') @@ -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