LoginSignup
3
3

More than 5 years have passed since last update.

@2xのretina画像から一括で、non retina画像を作成するRuby Script

Posted at

アプリ開発中にRetina画像だけ用意して、Non Retina画像をさぼって用意していない場合に実行すると一括でNon Retina画像を生成します。

non-retina.rb
#/bin/ruby

require 'rubygems'
require 'RMagick'

PATH = "Resource"

def findRetinaImage( directory )
    Dir.foreach( directory ){ | child |
        if( child != "." && child != ".." )
            child = directory + "/" + child
            if( FileTest::directory?( child ) )
                findRetinaImage( child )
            else
                if( child.end_with?("@2x.png") )
                    generate_file = child.sub("@2x" , "" );
                    if( FileTest::exists?( generate_file ) == false )
                        image = Magick::Image.read(child).first
                        image.resize!(0.5);
                        image.write( generate_file );
                        puts generate_file
                    end
                end
            end
        end
    }

end

findRetinaImage( PATH );
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3