File r = null; long start = System.currentTimeMillis();  if (!GalleryFileFilter.canManipulateJpeg(filename)) { return new File(filename); }  if (useIM) {  ArrayList cmd = new ArrayList(); cmd.add(imPath);      if (filterName[UPLOAD] != null && filterName[UPLOAD].length() > 0) {  cmd.add("-filter"); cmd.add(filterName[UPLOAD]); }   cmd.add(filename);   cmd.add("-resize"); cmd.add(d.width + "x" + d.height + ">");     cmd.add("-quality"); cmd.add("" + jpegQuality);  r = deterministicTempFile("res" , "." + GalleryFileFilter.getExtension(filename), tmpDir, filename + d); toDelete.add(r);   cmd.add(r.getPath());  int exitValue = exec((String[]) cmd.toArray(new String[0]));  if ((exitValue != 0 && !imIgnoreErrorCode) || ! r.exists()) { if (exitValue != -1 || ! r.exists()) {  Log.log(Log.LEVEL_CRITICAL, MODULE, "ImageMagick doesn't seem to be working. Disabling"); stopUsingIM(); } r = null; } }  if (!useIM && r == null) { r = resizeJava(filename, d);  }  long time = System.currentTimeMillis() - start; totalTime += time; totalIter++; Log.log(Log.LEVEL_TRACE, MODULE, "Time: " + time + " - Avg: " + (totalTime / totalIter));  return r;
return resize(filename, d, null);
	public static File resize(String filename, Dimension d) {		File r = null;		long start = System.currentTimeMillis();		if (!GalleryFileFilter.canManipulateJpeg(filename)) {			return new File(filename);		}		if (useIM) {			//StringBuffer cmdline = new StringBuffer(imPath);			ArrayList cmd = new ArrayList();			cmd.add(imPath);			//cmdline.append(" -size ").append(d.width).append("x").append(d.height);			//cmd.add("-size");			//cmd.add(d.width + "x" + d.height);			if (filterName[UPLOAD] != null && filterName[UPLOAD].length() > 0) {				//cmdline.append(" -filter ").append(filterName[UPLOAD]);				cmd.add("-filter");				cmd.add(filterName[UPLOAD]);			}			//cmdline.append(" \"").append(filename).append("\"");			cmd.add(filename);			//cmdline.append(" -resize \"").append(d.width).append("x").append(d.height).append(">\"");			cmd.add("-resize");			cmd.add(d.width + "x" + d.height + ">");			//cmdline.append("-gravity SouthEast -draw \"image Over 200,200 0,0 G:\\Projects\\Dev\\gallery_remote10\\2ni.png\" ");			//cmdline.append(" -quality ").append(jpegQuality);			cmd.add("-quality");			cmd.add("" + jpegQuality);			r = deterministicTempFile("res"					, "." + GalleryFileFilter.getExtension(filename), tmpDir, filename + d);			toDelete.add(r);			//cmdline.append(" \"").append(r.getPath()).append("\"");			cmd.add(r.getPath());			int exitValue = exec((String[]) cmd.toArray(new String[0]));			if ((exitValue != 0 && !imIgnoreErrorCode) || ! r.exists()) {				if (exitValue != -1 || ! r.exists()) {					// don't kill IM if it's just an InterruptedException					Log.log(Log.LEVEL_CRITICAL, MODULE, "ImageMagick doesn't seem to be working. Disabling");					stopUsingIM();				}				r = null;			}		}		if (!useIM && r == null) {			r = resizeJava(filename, d);			//throw new UnsupportedOperationException("IM must be installed for this operation");		}		long time = System.currentTimeMillis() - start;		totalTime += time;		totalIter++;		Log.log(Log.LEVEL_TRACE, MODULE, "Time: " + time + " - Avg: " + (totalTime / totalIter));		return r;	}