forked from huginn/huginn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Declare the site icons in various sizes
These are auto-generated from the SVG icon by running `bin/rake icons`.
- Loading branch information
Showing
20 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
ICONS_DIR = 'public' | ||
ORIGINAL_IMAGE = 'media/huginn-icon-square.svg' | ||
|
||
desc "Generate site icons from #{ORIGINAL_IMAGE}" | ||
task :icons => 'icon:all' | ||
|
||
namespace :icon do | ||
# iOS | ||
task :all => :ios | ||
|
||
[ | ||
57, 114, | ||
60, 120, 180, | ||
72, 144, | ||
76, 152, | ||
].each do |width| | ||
sizes = '%1$dx%1$d' % width | ||
filename = "apple-touch-icon-#{sizes}.png" | ||
icon = File.join(ICONS_DIR, filename) | ||
|
||
file icon => ORIGINAL_IMAGE do |t| | ||
puts "Generating #{t.name}" | ||
convert_image t.source, t.name, width: width | ||
end | ||
|
||
task :ios => icon | ||
end | ||
|
||
# Android | ||
task :all => :android | ||
|
||
android_icons = [ | ||
36, 72, 144, | ||
48, 96, 192, | ||
].map do |width| | ||
sizes = '%1$dx%1$d' % width | ||
filename = "android-chrome-#{sizes}.png" % width | ||
icon = File.join(ICONS_DIR, filename) | ||
|
||
file icon => ORIGINAL_IMAGE do |t| | ||
puts "Generating #{t.name}" | ||
convert_image t.source, t.name, width: width, round: true | ||
end | ||
|
||
task :android => icon | ||
|
||
{ | ||
src: "/#{filename}", | ||
sizes: sizes, | ||
type: 'image/png', | ||
density: (width / 48.0).to_s, | ||
} | ||
end | ||
|
||
manifest = File.join(ICONS_DIR, 'manifest.json') | ||
|
||
file manifest => __FILE__ do |t| | ||
puts "Generating #{t.name}" | ||
require 'json' | ||
json = { | ||
name: 'Huginn', | ||
icons: android_icons | ||
} | ||
File.write(t.name, JSON.pretty_generate(json)) | ||
end | ||
|
||
task :android => manifest | ||
end | ||
|
||
require 'mini_magick' | ||
|
||
def convert_image(source, target, width: nil, round: false) | ||
ext = target[/(?<=\.)[^.]+\z/] || 'png' | ||
original = MiniMagick::Image.open(source) | ||
|
||
result = original | ||
result.format ext | ||
|
||
if width | ||
result.thumbnail '%1$dx%1$d>' % width | ||
else | ||
width = result[:width] | ||
end | ||
|
||
if round | ||
radius = (Rational(80, 512) * width).round | ||
|
||
mask = MiniMagick::Image.create(ext) { |tmp| result.write(tmp) } | ||
|
||
mask.mogrify do |image| | ||
image.alpha 'transparent' | ||
image.background 'none' | ||
image.fill 'white' | ||
image.draw 'roundrectangle 0,0,%1$d,%1$d,%2$d,%2$d' % [width, radius] | ||
end | ||
|
||
result = result.composite(mask) do |image| | ||
image.alpha 'set' | ||
image.compose 'DstIn' | ||
end | ||
end | ||
|
||
result.write(target) | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "Huginn", | ||
"icons": [ | ||
{ | ||
"src": "/android-chrome-36x36.png", | ||
"sizes": "36x36", | ||
"type": "image/png", | ||
"density": "0.75" | ||
}, | ||
{ | ||
"src": "/android-chrome-48x48.png", | ||
"sizes": "48x48", | ||
"type": "image/png", | ||
"density": "1.0" | ||
}, | ||
{ | ||
"src": "/android-chrome-72x72.png", | ||
"sizes": "72x72", | ||
"type": "image/png", | ||
"density": "1.5" | ||
}, | ||
{ | ||
"src": "/android-chrome-96x96.png", | ||
"sizes": "96x96", | ||
"type": "image/png", | ||
"density": "2.0" | ||
}, | ||
{ | ||
"src": "/android-chrome-144x144.png", | ||
"sizes": "144x144", | ||
"type": "image/png", | ||
"density": "3.0" | ||
}, | ||
{ | ||
"src": "/android-chrome-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png", | ||
"density": "4.0" | ||
} | ||
] | ||
} |