Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelligently detect the minimum input size needed #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ lane :ios do
)
end

lane :ios_iphone do
appicon(
appicon_image_file: 'spec/fixtures/ThemojiSmall.png',
appicon_devices: %i[iphone],
appicon_path: 'app'
)
end

lane :ios_splash do
appicon(
appicon_image_file: 'spec/fixtures/ThemojiSplash.png',
appicon_devices: [:universal],
appicon_path: 'app',
appicon_name: 'Splash.imageset'
appicon_name: 'Splash.imageset',
allow_upsampling: true
)
end

Expand All @@ -39,7 +48,8 @@ lane :android do
android_appicon(
appicon_image_file: 'spec/fixtures/Themoji.png',
appicon_path: 'app/res/mipmap',
generate_rounded: true
generate_rounded: true,
allow_upsampling: true
)
end

Expand Down
18 changes: 16 additions & 2 deletions lib/fastlane/plugin/appicon/actions/android_appicon_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ def self.run(params)
custom_sizes = params[:appicon_custom_sizes]

icons = Helper::AppiconHelper.get_needed_icons(params[:appicon_icon_types], self.needed_icons, true, custom_sizes)

allow_upsampling = params[:allow_upsampling]
if !allow_upsampling
input_image = MiniMagick::Image.open(fname)
# Check that the input image is large enough for the needed icons without upsampling
maxWidth = icons.map { |v| v['width'] }.max.to_i
maxHeight = icons.map { |v| v['height'] }.max.to_i
Helper::AppiconHelper.check_input_image_size(input_image, maxWidth, maxHeight)
end

icons.each do |icon|
image = MiniMagick::Image.open(fname)

Helper::AppiconHelper.check_input_image_size(image, 1024, 1024)

# Custom icons will have basepath and filename already defined
if icon.has_key?('basepath') && icon.has_key?('filename')
basepath = Pathname.new(icon['basepath'])
Expand Down Expand Up @@ -173,6 +181,12 @@ def self.available_options
description: "Generate round icons?",
default_value: false,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :allow_upsampling,
env_name: "ALLOW_UPSAMPLING",
default_value: false,
description: "Allow the input image to be upsampled to larger sizes",
optional: true,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :minimagick_cli,
env_name: "APPICON_MINIMAGICK_CLI",
description: "Set MiniMagick CLI (auto picked by default). Values are: graphicsmagick, imagemagick",
Expand Down
23 changes: 16 additions & 7 deletions lib/fastlane/plugin/appicon/actions/appicon_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ def self.run(params)
basepath = Pathname.new(File.join(params[:appicon_path], is_messages_extension ? params[:appicon_messages_name] : params[:appicon_name]))

image = MiniMagick::Image.open(fname)

if is_messages_extension
Helper::AppiconHelper.check_input_image_size(image, 1024, 768)
else
Helper::AppiconHelper.check_input_image_size(image, 1024, 1024)
end


# Convert image to png
image.format 'png'

Expand All @@ -97,6 +91,15 @@ def self.run(params)
images = []

icons = Helper::AppiconHelper.get_needed_icons(params[:appicon_devices], is_messages_extension ? self.needed_icons_messages_extension : self.needed_icons, false)

allow_upsampling = params[:allow_upsampling]
if !allow_upsampling
# Check that the input image is large enough for the needed icons without upsampling
maxWidth = icons.map { |v| v['width'] }.max.to_i
maxHeight = icons.map { |v| v['height'] }.max.to_i
Helper::AppiconHelper.check_input_image_size(image, maxWidth, maxHeight)
end

icons.each do |icon|
width = icon['width']
height = icon['height']
Expand Down Expand Up @@ -208,6 +211,12 @@ def self.available_options
description: "App icon is generated for Messages extension",
optional: true,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :allow_upsampling,
env_name: "ALLOW_UPSAMPLING",
default_value: false,
description: "Allow the input image to be upsampled to larger sizes",
optional: true,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :minimagick_cli,
env_name: "APPICON_MINIMAGICK_CLI",
description: "Set MiniMagick CLI (auto picked by default). Values are: graphicsmagick, imagemagick",
Expand Down
Binary file added spec/fixtures/ThemojiSmall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.