Module: HighFive::ImageHelper

Included in:
Thor::Tasks::Android, Thor::Tasks::Ios
Defined in:
lib/high_five/image_helper.rb

Instance Method Summary collapse

Instance Method Details

#generate_ios_splash_screen_image(type, ios_path, path, color, replace = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/high_five/image_helper.rb', line 34

def generate_ios_splash_screen_image(type, ios_path, path, color, replace=false)
  raise "Requires RMagick gem" unless rmagick?
  case type
  when 'iphone_portrait_8_retina_hd_5_5'
    width = 1242
    height = 2208
  when 'iphone_portrait_8_retina_hd_4_7'
    width = 750
    height = 1334
  when 'iphone_landscape_8_retina_hd_5_5'
    width = 2208
    height = 1242
  when 'iphone_portrait_1x'
    width = 320
    height = 480
  when 'iphone_portrait_2x', 'android'
    width = 640
    height = 960
  when 'iphone_portrait_retina_4'
    width = 640
    height = 1136
  when 'ios-7-iphone_portrait_2x'
    width = 640
    height = 960
  when 'ios-7-iphone_portrait_retina_4'
    width = 640
    height = 1136
  when 'ipad_portrait_1x'
    width = 768
    height = 1024
  when 'ipad_portrait_2x'
    width = 1536
    height = 2048
  when 'ipad_landscape_1x'
    width = 1024
    height = 768
  when 'ipad_landscape_2x'
    width = 2048
    height = 1536
  when 'ipad_portrait_without_status_bar_5_6_1x'
    width = 768
    height = 1004
  when 'ipad_portrait_without_status_bar_5_6_2x'
    width = 1536
    height = 2008
  when 'ipad_landscape_without_status_bar_5_6_1x'
    width = 1024
    height = 748
  when 'ipad_landscape_without_status_bar_5_6_2x'
    width = 2048
    height = 1496
  end

  filename = "#{type}.png"
  splash_path = Dir.glob("#{ios_path}/**/Images.xcassets/LaunchImage.launchimage").first + "/#{filename}"
  puts "Creating #{splash_path}"
  Magick::Image.new(height, width).write(splash_path)
  if replace
    replace_image(splash_path, path)
  else
    generate_splash_screen_image splash_path, path, color
  end
end

#generate_splash_screen_image(image_path, logo_path, background) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/high_five/image_helper.rb', line 18

def generate_splash_screen_image(image_path, logo_path, background)
  raise "Requires RMagick gem" unless rmagick?
  image = ChunkyPNG::Image.from_file(image_path)
  width = image.width
  height = image.height
  source = Magick::Image.new(width, height) { self.background_color = background }

   = Magick::Image.read(logo_path).first
  scale_factor = min_scale_factor(, 0.75*width, 0.3*height)

  .scale!(scale_factor)
  source.composite!(, Magick::CenterGravity, Magick::AtopCompositeOp)

  source.write(image_path)
end

#replace_image(image_path, source_path) ⇒ Object

replace the image at image_path with a resized version of the image at source_path



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/high_five/image_helper.rb', line 5

def replace_image(image_path, source_path)
  image = ChunkyPNG::Image.from_file(image_path)

  if (rmagick?)
    source = Magick::Image.read(source_path).first
    resized = source.scale(image.height, image.width)
    resized.write(image_path)
  else
    source = ChunkyPNG::Image.from_file(source_path)
    source.resize(image.height, image.width).save(image_path)
  end
end