Add svg-to-ios-pngs.rb, generate-xcode-imageset, find-unused-images, and PlistExlporer
This commit is contained in:
parent
d8b275edc6
commit
1d4583b306
4 changed files with 81 additions and 0 deletions
BIN
PlistExplorer
Executable file
BIN
PlistExplorer
Executable file
Binary file not shown.
9
find-unused-images
Executable file
9
find-unused-images
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
for i in `find . -name "*.png" -o -name "*.jpg"`; do
|
||||
file=`basename -s .jpg "$i" | xargs basename -s .png | xargs basename -s @2x | xargs basename -s @3x`
|
||||
result=`ack -i "$file"`
|
||||
if [ -z "$result" ]; then
|
||||
echo "$i"
|
||||
fi
|
||||
done
|
||||
48
generate-xcode-imageset
Executable file
48
generate-xcode-imageset
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env ruby -w
|
||||
|
||||
require 'json'
|
||||
|
||||
def main
|
||||
while dir = ARGV.shift
|
||||
unless File.directory? dir
|
||||
puts "[warn] Skipping non-directory: #{dir}"
|
||||
next
|
||||
end
|
||||
|
||||
all_images = Dir[File.join(dir, '*@[23]x.png')].map { |f| File.basename f }
|
||||
image3x = File.basename Dir[File.join(dir, '*@3x.png')].first
|
||||
image2x = File.basename Dir[File.join(dir, '*@2x.png')].first
|
||||
image1x = (all_images - [image2x, image3x]).first
|
||||
unless [2, 3].include?(all_images.size) && image2x && image3x
|
||||
puts "[warn] Skipping #{dir} because 2x and 3x images are required. 1x image is optional. Max 3 images."
|
||||
next
|
||||
end
|
||||
|
||||
images = [image1x, image2x, image3x]
|
||||
scale = 0
|
||||
imageset_images = images
|
||||
.map { |filename|
|
||||
scale += 1
|
||||
filename && {
|
||||
idiom: 'universal',
|
||||
filename: filename,
|
||||
scale: "#{scale}x"
|
||||
}
|
||||
}
|
||||
.compact
|
||||
imageset = {
|
||||
images: imageset_images,
|
||||
info: {
|
||||
version: 1,
|
||||
author: 'generate-xcode-imageset'
|
||||
}
|
||||
}
|
||||
json = JSON.pretty_generate(imageset)
|
||||
path = File.join(dir, 'Contents.json')
|
||||
File.write(path, json)
|
||||
images_written = images.compact
|
||||
puts "* Wrote #{images_written.size} images to #{path}: #{images_written.join(', ')}"
|
||||
end
|
||||
end
|
||||
|
||||
main if $0 == __FILE__
|
||||
24
svg-to-ios-pngs.rb
Executable file
24
svg-to-ios-pngs.rb
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env ruby -w
|
||||
|
||||
svg_path = ARGV.shift
|
||||
png_path = ARGV.shift
|
||||
|
||||
png_test_path = "/tmp/identify.png"
|
||||
File.unlink(png_test_path) if File.exist?(png_test_path)
|
||||
puts `inkscape -z -e '#{png_test_path}' -d 72 '#{svg_path}'`
|
||||
info = `identify '#{png_test_path}'`
|
||||
File.unlink(png_test_path) if File.exist?(png_test_path)
|
||||
dimensions = info.split[2]
|
||||
width, height = dimensions.split('x').map(&:to_i)
|
||||
if width == 0 || height == 0
|
||||
$stderr.puts "Failed to get SVG dimensions"
|
||||
exit 1
|
||||
end
|
||||
|
||||
name = File.basename(svg_path).sub /\.svg$/, ''
|
||||
|
||||
png_2x_path = File.join(png_path, "#{name}@2x.png")
|
||||
puts `inkscape -z -e '#{png_2x_path}' -w #{2 * width} -h #{2 * height} -d 72 '#{svg_path}'`
|
||||
|
||||
png_3x_path = File.join(png_path, "#{name}@3x.png")
|
||||
puts `inkscape -z -e '#{png_3x_path}' -w #{3 * width} -h #{3 * height} -d 27 '#{svg_path}'`
|
||||
Loading…
Reference in a new issue