Last active
October 8, 2015 16:06
-
-
Save lacostej/40d6c23ee1002ac8ec8c to your computer and use it in GitHub Desktop.
Deliver ScreenshotGenerator
This file contains hidden or 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
| require 'fileutils' | |
| class ScreenshotGenerator | |
| attr_accessor :dimensions | |
| def initialize(dimensions) | |
| @dimensions = dimensions | |
| end | |
| def generate_screenshots(path, prefix, locales, device_types, colors) | |
| puts "Generating screenshots under #{path}" | |
| locales.each { |locale| | |
| dir="#{path}/#{locale}" | |
| FileUtils.mkdir_p(dir) | |
| device_types.each { |type| | |
| index = 0 | |
| resolution = @dimensions[type] | |
| colors.each {|color| | |
| r="#{resolution[0]}x#{resolution[1]}" | |
| image_path = "#{dir}/#{prefix}_#{type}_#{r}_#{index+1}.jpg" | |
| puts "PATH #{image_path}" | |
| self.generate_image(image_path, resolution, colors[index]) | |
| self.add_image_caption(image_path, "#{type} #{locale} ##{index + 1}") | |
| index += 1 | |
| } | |
| } | |
| } | |
| end | |
| def generate_image(path, resolution, color) | |
| r="#{resolution[0]}x#{resolution[1]}" | |
| `convert -size #{r} xc:##{color} #{path}` | |
| end | |
| def add_image_caption(path, text) | |
| width=`identify -format %w #{path}` | |
| height=`identify -format %h #{path}`.to_i | |
| h=[30, (0.2*height)].max | |
| `convert -background '#0008' -fill white -gravity center -size #{width}x#{h} caption:\"#{text}\" #{path} +swap -gravity south -composite #{path}` | |
| #`convert #{path} -pointsize #{pointsize} label:'#{text}' +swap -gravity Center -annotate #{path}` | |
| end | |
| end | |
| class Helper | |
| class << self; attr_accessor :locales, :colors, :dimensions, :SG; end | |
| @@locales = ['en-US', 'fr-FR', 'es-ES', 'no'] | |
| @@colors = [ | |
| 'FCFEE8', | |
| '6D6905', | |
| 'C8B769', | |
| '36B1C0', | |
| 'ADF4D6' | |
| ] | |
| @@dimensions = { | |
| 'ipad' => [1536, 2048], | |
| 'iphone35' => [640, 960], | |
| 'iphone4' => [640, 1136], | |
| 'iphone6' => [750, 1334], | |
| 'iphone6Plus' => [1242, 2208] | |
| } | |
| @@SG = ScreenshotGenerator.new(@@dimensions) | |
| class << self | |
| def generate(n_locales, n_types, n_screenshots) | |
| @@SG.generate_screenshots("screenshots_#{n_locales}_#{n_types}_#{n_screenshots}", 'screenshot', | |
| @@locales[0, n_locales], | |
| @@dimensions.keys[0, n_types], | |
| @@colors[0, n_screenshots]) | |
| end | |
| end | |
| end | |
| SG=ScreenshotGenerator.new(Helper.dimensions) | |
| path='whatever.png' | |
| SG.generate_image(path, [100, 120], 'FCFEE8') | |
| SG.add_image_caption(path, 'iPad en-US') | |
| Helper.generate(1, 1, 1) | |
| Helper.generate(5, 5, 5) |
This file contains hidden or 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
| > du -sk ../screenshots_5_5_5 | |
| 5688 ../screenshots_5_5_5 | |
| > find ../screenshots_5_5_5 | |
| ../screenshots_5_5_5 | |
| ../screenshots_5_5_5/en-US | |
| ../screenshots_5_5_5/en-US/screenshot_ipad_1536x2048_1.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_ipad_1536x2048_2.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_ipad_1536x2048_3.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_ipad_1536x2048_4.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_ipad_1536x2048_5.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone35_640x960_1.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone35_640x960_2.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone35_640x960_3.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone35_640x960_4.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone35_640x960_5.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone4_640x1136_1.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone4_640x1136_2.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone4_640x1136_3.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone4_640x1136_4.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone4_640x1136_5.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6_750x1334_1.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6_750x1334_2.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6_750x1334_3.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6_750x1334_4.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6_750x1334_5.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6Plus_1242x2208_1.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6Plus_1242x2208_2.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6Plus_1242x2208_3.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6Plus_1242x2208_4.jpg | |
| ../screenshots_5_5_5/en-US/screenshot_iphone6Plus_1242x2208_5.jpg | |
| ../screenshots_5_5_5/es-ES | |
| ../screenshots_5_5_5/es-ES/screenshot_ipad_1536x2048_1.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_ipad_1536x2048_2.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_ipad_1536x2048_3.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_ipad_1536x2048_4.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_ipad_1536x2048_5.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone35_640x960_1.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone35_640x960_2.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone35_640x960_3.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone35_640x960_4.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone35_640x960_5.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone4_640x1136_1.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone4_640x1136_2.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone4_640x1136_3.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone4_640x1136_4.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone4_640x1136_5.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6_750x1334_1.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6_750x1334_2.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6_750x1334_3.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6_750x1334_4.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6_750x1334_5.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6Plus_1242x2208_1.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6Plus_1242x2208_2.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6Plus_1242x2208_3.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6Plus_1242x2208_4.jpg | |
| ../screenshots_5_5_5/es-ES/screenshot_iphone6Plus_1242x2208_5.jpg | |
| ../screenshots_5_5_5/fr-FR | |
| ../screenshots_5_5_5/fr-FR/screenshot_ipad_1536x2048_1.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_ipad_1536x2048_2.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_ipad_1536x2048_3.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_ipad_1536x2048_4.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_ipad_1536x2048_5.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone35_640x960_1.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone35_640x960_2.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone35_640x960_3.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone35_640x960_4.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone35_640x960_5.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone4_640x1136_1.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone4_640x1136_2.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone4_640x1136_3.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone4_640x1136_4.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone4_640x1136_5.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6_750x1334_1.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6_750x1334_2.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6_750x1334_3.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6_750x1334_4.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6_750x1334_5.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6Plus_1242x2208_1.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6Plus_1242x2208_2.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6Plus_1242x2208_3.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6Plus_1242x2208_4.jpg | |
| ../screenshots_5_5_5/fr-FR/screenshot_iphone6Plus_1242x2208_5.jpg | |
| ../screenshots_5_5_5/no | |
| ../screenshots_5_5_5/no/screenshot_ipad_1536x2048_1.jpg | |
| ../screenshots_5_5_5/no/screenshot_ipad_1536x2048_2.jpg | |
| ../screenshots_5_5_5/no/screenshot_ipad_1536x2048_3.jpg | |
| ../screenshots_5_5_5/no/screenshot_ipad_1536x2048_4.jpg | |
| ../screenshots_5_5_5/no/screenshot_ipad_1536x2048_5.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone35_640x960_1.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone35_640x960_2.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone35_640x960_3.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone35_640x960_4.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone35_640x960_5.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone4_640x1136_1.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone4_640x1136_2.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone4_640x1136_3.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone4_640x1136_4.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone4_640x1136_5.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6_750x1334_1.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6_750x1334_2.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6_750x1334_3.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6_750x1334_4.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6_750x1334_5.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6Plus_1242x2208_1.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6Plus_1242x2208_2.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6Plus_1242x2208_3.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6Plus_1242x2208_4.jpg | |
| ../screenshots_5_5_5/no/screenshot_iphone6Plus_1242x2208_5.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment