Image Convertor, converts all images in folder of one format (gif) to another (jpg).   #


import java.awt.image.BufferedImage; import java.io.File; import java.io.FilenameFilter; import java.util.Date; import javax.imageio.ImageIO; /** * This tool Image Convertor, converts all images in folder of one format (gif) to another (jpg). * * @author mvohra * */ public class ImageConverter { public static void main(String args[]) { // root directory where gif images are stored String rootDir = "c:\gif-image-dir"; File dir = new File(rootDir); // It is also possible to filter the list of returned files. // This example does not return any files that start with `.'. FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith("gif"); } }; // get a of files with that have extension of gif String[] children = dir.list(filter); // loop through for (int i = 0; i < children.length; i++) { // Get filename of file or directory String filename = children[i]; log("Converting " + filename); // create file handles File myGifFile = new File(rootDir + "" + filename); File outFile = new File(rootDir + "" + filename.replace("gif", "jpg")); try { // Using Image IO BufferedImage bufi = ImageIO.read(myGifFile); ImageIO.write(bufi, "JPEG", outFile); } catch (Exception e) { log(e.getMessage()); } } } public static void log(String msg) { System.out.println(new Date() + " - " + msg); } }

Loading Please Wait...