001/* 002 * $Source: /cvsroot2/open/projects/WebARTS/ca/bc/webarts/widgets/ReduceJPEGSize.java,v $ 003 * ReduceJPEGSize.java - A widget to grab URLs through a proxy. 004 * 005 * $Revision: 563 $ 006 * $Date: 2012-11-03 19:28:37 -0700 (Sat, 03 Nov 2012) $ 007 * $Locker: $ 008 * 009 * 010 * Written by Tom Gutwin - WebARTS Design. 011 * Copyright (C) 2003 WebARTS Design, North Vancouver Canada 012 * http://www.webarts.bc.ca 013 * 014 * This program is free software; you can redistribute it and/or modify 015 * it under the terms of the GNU General Public License as published by 016 * the Free Software Foundation; either version 2 of the License, or 017 * (at your option) any later version. 018 * 019 * This program is distributed in the hope that it will be useful, 020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 022 * GNU General Public License for more details. 023 * 024 * You should have received a copy of the GNU General Public License 025 * along with this program; if not, write to the Free Software 026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 027 */ 028package ca.bc.webarts.tools; 029 030import java.io.File; 031import java.io.FileInputStream; 032import java.io.FileOutputStream; 033import java.io.FileNotFoundException; 034import java.io.InputStream; 035import java.io.IOException; 036 037import java.lang.SecurityException; 038 039import java.util.Properties; 040 041import java.net.Authenticator; 042import java.net.HttpURLConnection; 043import java.net.MalformedURLException; 044import java.net.URL; 045import java.net.URLConnection; 046import java.net.PasswordAuthentication; 047 048/** 049 * A tool to downsize/grade all jpg files in a dir and save the results in a 050 * subdir. It does the processing by calling the native ImageMagik 'convert' 051 * command. 052 * 053 * <pre> 054 * Usage: 055 * java ca.bc.webarts.widgets.ReduceJPEGSize [directory] 056 *</pre> 057 * 058 * @author Tom Gutwin P.Eng 059 **/ 060public class ReduceJPEGSize 061{ 062 /** A holder for the NA Clients System File Separator. **/ 063 private static final String SYSTEM_FILE_SEPERATOR = File.separator; 064 065 /** 066 * A holder for the directory location to save downloads. DEFAULT is the 067 * current working dir. 068 **/ 069 private static final String DEFAULT_SAVE_LOCATION = 070 System.getProperty("user.dir") + SYSTEM_FILE_SEPERATOR+"reduced" 071 + SYSTEM_FILE_SEPERATOR; 072 073 /** The default reduduction size percentage. **/ 074 private static final int DEFAULT_REDUCTION_PERCENTAGE = 40; 075 076 /** The reduduction size percentage. **/ 077 private int reduceByPercentage = DEFAULT_REDUCTION_PERCENTAGE; 078 079 /** 080 * The default empty constructor for this class. It initsbut does no grabbing. 081 **/ 082 public ReduceJPEGSize() 083 { 084 this(DEFAULT_SAVE_LOCATION); 085 } 086 087 088 /** 089 * The main constructor for this class. It inits and grabs the spec'd URL 090 * into the current directory. 091 * 092 * @param urlStr the string representation of the URL to grab. 093 * 094 **/ 095 public ReduceJPEGSize(String dirStr) 096 { 097 new File(DEFAULT_SAVE_LOCATION).mkdir(); // ensures the dir exests 098 } 099 100 101 /** 102 * The main entry for this app. It takes url strings on the commandline. 103 * 104 * @param args are the URLs to grab. 105 **/ 106 public static void main(String [] args) 107 { 108 if (args.length > 0) 109 { 110 ReduceJPEGSize instance = new ReduceJPEGSize(args[1]); 111 } 112 else 113 { 114 ReduceJPEGSize instance = 115 new ReduceJPEGSize(System.getProperty("user.dir")); 116 } 117 } 118 119 120 public int convert(String fileName, int reductionSizePercent, int reducedQuality) 121 { 122 int retVal = 0; 123 StringBuffer command = new StringBuffer("/usr/bin/convert"); 124 125 return retVal; 126 } 127 128} 129