/* * [RightSize.java] * * Summary: Checks that all images in a directory are of the correct size. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2009-03-19 initial release * 1.1 2014-06-23 add support for *.webp images. */ package com.mindprod.rightsize; import com.mindprod.commandline.CommandLine; import com.mindprod.common18.EIO; import com.mindprod.common18.ImageInfo; import com.mindprod.fastcat.FastCat; import com.mindprod.filter.AllButSVNDirectoriesFilter; import com.mindprod.filter.ExtensionListFilter; import java.io.File; import static java.lang.System.*; /** * Checks that all images in a directory are of the correct size. *

* For ASP PAD screenshots might use: * rightisize.jar 200 200 600 800 screenshotdir * or * rightsize.jar 100 100 600 800 screenshotdir for bare minium * * @author Roedy Green, Canadian Mind Products * @version 1.1 2014-06-23 add support for *.webp images. * @since 2009-03-19 */ public class RightSize { private static final int FIRST_COPYRIGHT_YEAR = 2009; /** * undisplayed copyright notice */ private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; private static final String RELEASE_DATE = "2014-06-23"; /** * how to use the command line */ private static final String USAGE = "\nRightsize needs min-width min-height max-width max-height files and dirs of " + "png/jpg/jpeg/gif/webp images to check using the -s switch."; /** * embedded version string. */ private static final String VERSION_STRING = "1.1"; /** * Check that all images in a directory are of the correct size. * * @param args min-width min-height max-width max-height directories/files to check */ public static void main( String[] args ) { if ( args.length < 5 ) { err.println( USAGE ); System.exit( 1 ); } final int minWidth = Integer.parseInt( args[ 0 ] ); final int minHeight = Integer.parseInt( args[ 1 ] ); final int maxWidth = Integer.parseInt( args[ 2 ] ); final int maxHeight = Integer.parseInt( args[ 3 ] ); // avoid reprocessing first 4 parms. args[ 0 ] = null; args[ 1 ] = null; args[ 2 ] = null; args[ 3 ] = null; // Java does not support webp but ImageInfo does. We can find size, but no more. CommandLine commandLine = new CommandLine( args, new AllButSVNDirectoriesFilter(), new ExtensionListFilter( "png", "jpg", "jpeg", "gif", "webp" ) ); if ( commandLine.size() == 0 ) { throw new IllegalArgumentException( "No files found to process" + USAGE ); } for ( File file : commandLine ) { int[] dim; final String fn = EIO.getCanOrAbsPath( file ); try { dim = ImageInfo.getImageDimensions( fn ); } catch ( Exception e ) { out.println( "Problems with " + fn + ". It if may be corrupt or locked. " + e.getMessage() ); continue; } final int width = dim[ 0 ]; final int height = dim[ 1 ]; final FastCat sb = new FastCat( 15 ); if ( width == 0 ) { sb.append( " has zero size." ); } if ( width < minWidth ) { sb.append( " is less than ", minWidth, " pixels wide." ); } if ( width > maxWidth ) { sb.append( " is greater than ", maxWidth, " pixels wide." ); } if ( height < minHeight ) { sb.append( " is less than ", minHeight, " pixels tall." ); } if ( height > maxHeight ) { sb.append( " is greater than ", maxHeight, " pixels tall." ); } if ( sb.length() > 0 ) { out.println( "At " + width + " x " + height + ", " + fn + " " + sb.toString() ); } } } }