0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Groovy】iOS・Androidの各種サイズの一時的なアイコンを作る【小人さんスクリプト】

Posted at

Unityを始めとするマルチプラットフォームの開発環境で、本番のアイコンはまだできていないけれど仮の画像でやり過ごさないといけない時ってありますよね。(ありませんか?ないですかそうですか。)

とりあえず一枚だけ画像はもらったけれど、本番リリースまでは各種プラットフォーム・各種サイズはもらえなそうなそんな時、このGroovyスクリプトを使えば必要なサイズの画像を生成することができます!

import java.awt.Image
import java.awt.image.BufferedImage
import javax.imageio.ImageIO

def iconSizes = [
    // iOS
    57,
    72,
    76,
    114,
    120,
    144,
    152,
    180,

    // Android
    36,
    48,
    72,
    96,
    144,
    192,
]

if (args.size() != 1) {
    println("usage : groovy create_icons.groovy YOUR_ICON_IMAGE_NAME")
    return
}

def imagePath = args[0]
def inputImage = ImageIO.read(new File(imagePath))

iconSizes.each { iconSize ->
    def iconName = "icon${iconSize}x${iconSize}.png"
    createResizedIcon (inputImage, iconName, iconSize, iconSize)
}

def createResizedIcon (def inputImage, def outputFilename, def width, def height) {
    def outputFile = new File(outputFilename)
    def scaledImage = inputImage.getScaledInstance(width,height,Image.SCALE_SMOOTH)

    def bufferedImage = new BufferedImage((int)scaledImage.width,(int)scaledImage.height,BufferedImage.TYPE_4BYTE_ABGR)
    def graphics = bufferedImage.getGraphics();
    graphics.drawImage(scaledImage,0,0,null)
    graphics.dispose()

    ImageIO.write(bufferedImage,'PNG',outputFile)
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?