lib/frameit/editor.rb in frameit-2.0.1 vs lib/frameit/editor.rb in frameit-2.1.0
- old
+ new
@@ -90,11 +90,11 @@
if self.frame # we have no frame on le mac
resize_frame!
@image = put_into_frame
# Decrease the size of the framed screenshot to fit into the defined padding + background
- frame_width = background.width - fetch_config['padding'] * 2
+ frame_width = background.width - frame_padding * 2
image.resize "#{frame_width}x"
end
@image = put_device_into_background(background)
@@ -103,10 +103,17 @@
end
image
end
+ # Padding around the frames
+ def frame_padding
+ multi = 1.0
+ multi = 1.7 if self.screenshot.is_triple_density?
+ return fetch_config['padding'] * multi
+ end
+
# Returns a correctly sized background image
def generate_background
background = MiniMagick::Image.open(fetch_config['background'])
if background.height != screenshot.size[1]
@@ -117,10 +124,11 @@
def put_device_into_background(background)
left_space = (background.width / 2.0 - image.width / 2.0).round
bottom_space = -(image.height / 10).round # to be just a bit below the image bottom
bottom_space -= 40 if screenshot.is_portrait? # even more for portrait mode
+ bottom_space -= 50 if (screenshot.is_mini? and screenshot.is_portrait?) # super old devices
self.top_space_above_device = background.height - image.height - bottom_space
@image = background.composite(image, "png") do |c|
c.compose "Over"
@@ -182,14 +190,16 @@
image_height = actual_font_size * 2 # gets trimmed afterwards anyway, and on the iPad the `y` would get cut
title_image.combine_options do |i|
i.resize "#{max_width}x#{image_height}!" # `!` says it should ignore the ratio
end
+ current_font = font(key)
+ Helper.log.debug "Using #{current_font} as font the #{key} of #{screenshot.path}" if $verbose and current_font
+
# Add the actual title
- font = fetch_config[key.to_s]['font']
title_image.combine_options do |i|
- i.font font if font
+ i.font current_font if current_font
i.gravity "Center"
i.pointsize actual_font_size
i.draw "text 0,0 '#{fetch_text(key)}'"
i.fill fetch_config[key.to_s]['color']
end
@@ -224,16 +234,42 @@
return result.last if result
end
# No string files, fallback to Framefile config
result = fetch_config[type.to_s]['text']
+ Helper.log.debug "Falling back to default text as there was nothing specified in the .strings file" if $verbose
if !result and type == :title
# title is mandatory
raise "Could not get title for screenshot #{screenshot.path}. Please provide one in your Framefile.json".red
end
return result
end
+ # The font we want to use
+ def font(key)
+ single_font = fetch_config[key.to_s]['font']
+ return single_font if single_font
+
+ fonts = fetch_config[key.to_s]['fonts']
+ if fonts
+ fonts.each do |font|
+ if font['supported']
+ font['supported'].each do |language|
+ if screenshot.path.include?language
+ return font["font"]
+ end
+ end
+ else
+ # No `supported` array, this will always be true
+ Helper.log.debug "Found a font with no list of supported languages, using this now" if $verbose
+ return font["font"]
+ end
+ end
+ end
+
+ Helper.log.debug "No custom font specified, using the default one" if $verbose
+ return nil
+ end
end
end
\ No newline at end of file