Skip to content

Instantly share code, notes, and snippets.

@denvazh
Created June 6, 2018 06:49
Show Gist options
  • Save denvazh/50821e62b8e4d9e18d7a65b91c960a9c to your computer and use it in GitHub Desktop.
Save denvazh/50821e62b8e4d9e18d7a65b91c960a9c to your computer and use it in GitHub Desktop.
Convert screenshots for iPad to iPhone X size
#!/usr/bin/env ruby
require 'bundler/setup'
require 'pry'
require 'pathname'
module Intermediate
XAXIS = 1826
YAXIS = 2436
end
module Target
XAXIS = 1125
end
def read_values(klass)
klass.constants.map { |c| klass.const_get(c) }
end
def convert(source, target)
newsize = '%sx%s\!' % read_values(Intermediate)
crop_area = '%sx%s+0+0' % [Target::XAXIS, Intermediate::YAXIS]
cmdstr = 'convert %s -resize %s -gravity center -crop %s %s' % [source, newsize, crop_area, target]
`#{cmdstr}`
end
%w(en-US ja).map { |d| Pathname.new(d) }.each do |dir|
dir.children.select { |f| f.to_s.include?('iPadPro') }.each do |file|
basename, extname = file.basename, file.extname
newname = File.basename(basename, extname).sub('iPadPro', 'iPhoneX')
res = convert(file, dir.join('%s%s' % [newname, extname]))
puts res
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment