Last active
January 1, 2016 11:49
-
-
Save joshdholtz/8140463 to your computer and use it in GitHub Desktop.
Quick script to scale retina images down 50% into a new file in current directory I also added a bash script in my /usr/local/bin so that I can run this from anywhere
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
| #!/bin/bash | |
| ruby ~/scripts/unretina_it.rb |
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 'RMagick' | |
| Dir.new('.').each do |file| | |
| # Ignore hidden files | |
| if !file.start_with?(".") | |
| # Finds the file extension and file name without the extension (there is probably be an easier way but whatevs) | |
| start_extension = file.rindex(".") | |
| filename = file.slice(0, start_extension) | |
| extension = file.slice(start_extension, file.length - start_extension) | |
| # Finds only the filenames that are retina (ends with @2x) | |
| if filename.end_with?("@2x") | |
| # Removes the "@2x" from the filename for the unretina filename | |
| scaled_filename = filename.sub("@2x", "") | |
| # A puts you putz | |
| puts "Going to scale #{filename}#{extension} to #{scaled_filename}#{extension}" | |
| # Scales by 50% into new image (this probably overwrites if unretina already exists, I'm not sure though) | |
| img = Magick::Image::read( "#{filename}#{extension}" ).first | |
| thumb = img.scale(0.5) | |
| thumb.write "#{scaled_filename}#{extension}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment