import java.awt.image.BufferedImage;

import loci.formats.MetadataTools;
import loci.formats.gui.AWTImageTools;
import loci.formats.gui.BufferedImageReader;
import loci.formats.gui.BufferedImageWriter;
import loci.formats.meta.IMetadata;
import ome.xml.model.primitives.PositiveInteger;

/**
 * This file is used in the 'publish' cron job. Takes a given tiff file and
 * creates a thumbnail. Used to create thumbnails for Forward website.
 * 
 * @author Eric Alexander
 */
public class CreateThumbnail {

	public static void main(final String[] args) throws Exception {
		// Usage: java CreateThumbnail /current/path/to/tiff
		// /desired/path/to/thumbnail
		if (args.length == 2) {
			final String tiffFile = args[0];
			final String thumbnailPath = args[1];

			if (!tiffFile.endsWith(".ome.tiff")) {
				System.err.println("Error: " + tiffFile +
					" does not have the proper extension for OME-TIFF.");
				return;
			}

			readThumbnail(tiffFile, thumbnailPath);
		}
		else {
			System.err.println("Error: Improper arguments.");
			System.err.println("Usage: java CreateThumbnail "
				+ "/current/path/to/tiff /desired/path/to/thumbnail");
		}
	}

	/**
	 * Creates a thumbnail for a given tiff file.
	 * 
	 * @param filePath path to the tiff file
	 * @param thumbnailPath intended path to thumbnail
	 */
	public static void readThumbnail(final String filePath,
		final String thumbnailPath) throws Exception
	{
		final BufferedImageReader reader = new BufferedImageReader();
		final IMetadata metadata = MetadataTools.createOMEXMLMetadata();
		reader.setMetadataStore(metadata);
		reader.setId(filePath);
		final int sizeZ = reader.getSizeZ();
		// int sizeC = reader.getSizeC();
		// int sizeT = reader.getSizeT();

		// Middle z-slice, laser channel, first timepoint
		final int index = reader.getIndex(sizeZ / 2, 1, 0);

		final BufferedImage image = reader.openImage(index);
		reader.close();

		// Change these lines if we decide to scale the image somehow.
		final int w = image.getWidth();
		final int h = image.getHeight();
		metadata.setPixelsSizeX(new PositiveInteger(w), 0);
		metadata.setPixelsSizeY(new PositiveInteger(h), 0);

		final BufferedImage thumbnail = AWTImageTools.scale(image, w, h, false);

		final BufferedImageWriter writer = new BufferedImageWriter();
		writer.setMetadataRetrieve(metadata);
		writer.setId(thumbnailPath);
		writer.saveImage(0, thumbnail);
		writer.close();
	}
}

@@ -343,28 +343,29 @@
 kes a given 
-tiff
+image
  file and%0A *
@@ -568,95 +568,8 @@
 n %7B%0A
-%09%09// Usage: java CreateThumbnail /current/path/to/tiff%0A%09%09// /desired/path/to/thumbnail%0A
 %09%09if
@@ -606,20 +606,21 @@
  String 
-tiff
+image
 File = a
@@ -673,173 +673,8 @@
 %5D;%0A%0A
-%09%09%09if (!tiffFile.endsWith(%22.ome.tiff%22)) %7B%0A%09%09%09%09System.err.println(%22Error: %22 + tiffFile +%0A%09%09%09%09%09%22 does not have the proper extension for OME-TIFF.%22);%0A%09%09%09%09return;%0A%09%09%09%7D%0A%0A
 %09%09%09r
@@ -686,20 +686,21 @@
 umbnail(
-tiff
+image
 File, th
@@ -856,20 +856,26 @@
 path/to/
-tiff
+image_data
  /desire
@@ -946,20 +946,21 @@
 a given 
-tiff
+image
  file.%0A%09
@@ -999,12 +999,13 @@
 the 
-tiff
+image
  fil

Remove restriction that image must be an OME-TIFF