Skip to content

Instantly share code, notes, and snippets.

@squarefrog
Created October 12, 2015 11:15
Show Gist options
  • Save squarefrog/324d3e114f2c63135bc0 to your computer and use it in GitHub Desktop.
Save squarefrog/324d3e114f2c63135bc0 to your computer and use it in GitHub Desktop.
module Fastlane
module Actions
class AddIconOverlayAction < Action
def self.run(params)
#Helper.log.info "Image to overlay on icons: #{params[:overlay_image_path]}"
require 'mini_magick'
appiconset = params[:appiconset_path]
#overlay_image = MiniMagick::Image.new(params[:overlay_image_path])
Dir.glob(File.join(appiconset, '*.png')) do |icon|
original_icon = MiniMagick::Image.new(icon)
#result = original_icon.composite(overlay_image) do |c|
#c.compose "Over"
#c.resize "#{original_icon.width}x#{original_icon.height}"
#c.quality 100
#end
width = original_icon.width
height = original_icon.height
rect_height = 10
x = width / 1.5
text_size = width / 8
padding = text_size / 2
result = original_icon.combine_options do |c|
#c.fill('#FF00FF')
#c.draw "rotate -45 rectangle #{x},#{x},1,1"
c.fill('#FFFFFF')
c.gravity 'Northeast'
c.draw "rotate 45 text #{text_size + padding},#{text_size + padding} 'BETA'"
c.pointsize "#{text_size}"
#c.font 'Helvetica' # must be in font list `convert -list font`
end
result.write icon
end
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Overlays an image over all icons."
end
def self.details
"Overlays an image over all icons, using ImageMagick and replacing the old icons."
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :appiconset_path,
env_name: "FL_ADD_ICON_OVERLAY_APPICONSET_PATH",
description: "Path for .appiconset containing the icons",
is_string: true,
default_value: '**/AppIcon.appiconset'
),
FastlaneCore::ConfigItem.new(key: :overlay_text,
env_name: "FL_ADD_ICON_OVERLAY_TEXT",
description: "Text to overlay over the icons",
is_string: true,
default_value: 'BETA'
)
]
end
def self.output
end
def self.return_value
# If you method provides a return value, you can describe here what it does
end
def self.authors
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
["marcelofabri", "squarefrog"]
end
def self.is_supported?(platform)
platform == :ios
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment