~widelands-media-dev/widelands-media/cleanup-world

« back to all changes in this revision

Viewing changes to graphics/tools/Graphics Tools (Java)/MenuIcons.java

  • Committer: Benedikt Straub
  • Date: 2018-07-23 07:29:09 UTC
  • mfrom: (209.1.11 widelands-media)
  • Revision ID: benedikt-straub@web.de-20180723072909-90dkwk0pmktk5kzm
Included new frisian graphics

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import java.awt.*;
 
2
import java.awt.image.*;
 
3
import java.io.*;
 
4
import java.util.regex.*;
 
5
import javax.imageio.*;
 
6
 
 
7
public class MenuIcons {
 
8
    public static void main ( String ... args ) throws Exception {
 
9
        if ( args.length < 4 ) {
 
10
            System.out.println ( "USAGE: java MenuIcons DIRECTORY ANIMATION_NAME ANIMATION_FRAME ICON_SIZE" );
 
11
            return;
 
12
        }
 
13
        File path = new File ( args [0] );
 
14
        String anim = args [1];
 
15
        int id = Integer.valueOf ( args [2] );
 
16
        int size = Integer.valueOf ( args [3] );
 
17
        
 
18
        Pattern pattern = Pattern.compile ( anim + "_0*" + id + ".png" );
 
19
        for ( File f : path.listFiles ())
 
20
            if ( pattern.matcher ( f.getName ()).matches ()) {
 
21
                System.out.println ( "[" + path.getName () + "] Using image " + f.getName ());
 
22
                BufferedImage img = ImageIO.read ( f );
 
23
                int w = img.getWidth ();
 
24
                int h = img.getHeight ();
 
25
                double scale = Math.min ((double)size / w, (double)size / h );
 
26
                int nw = (int)( scale * w );
 
27
                int nh = (int)( scale * h );
 
28
                
 
29
                BufferedImage write = new BufferedImage ( size, size, BufferedImage.TYPE_INT_ARGB );
 
30
                Graphics2D g = write.createGraphics ();
 
31
                g.drawImage ( img.getScaledInstance ( nw, nh, BufferedImage.SCALE_SMOOTH ),
 
32
                        size / 2 - nw / 2, size / 2 - nh / 2, nw, nh, null );
 
33
                
 
34
                ImageIO.write ( write, "png", new File ( path, "menu.png" ));
 
35
                return;
 
36
            }
 
37
        System.out.println ( "[" + path.getName () + "] Frame " + id + " of animation " + anim + " not found at " + path );
 
38
    }
 
39
}