<cfscript>


	// Full path to image files.
	path = expandPath( "./images/monkey.png" );
	//path = expandPath( "./images/wrong-extension.jpg" );
	//path = expandPath( "./images/cmyk.jpg" );


	// ------------------------------------------------------ //
	// ------------------------------------------------------ //


	try {

		image = imageRead( path );

		writeOutput( "PASS: imageRead()<br />" );

	} catch ( any error ) {

		writeOutput( "FAIL: imageRead()<br />" );
		writeOutput( "--- #error.message#<br />" );

	}


	// ------------------------------------------------------ //
	// ------------------------------------------------------ //


	try {

		image = imageNew( path );

		writeOutput( "PASS: imageNew( path )<br />" );

	} catch ( any error ) {

		writeOutput( "FAIL: imageNew( path )<br />" );
		writeOutput( "--- #error.message#<br />" );

	}


	// ------------------------------------------------------ //
	// ------------------------------------------------------ //


	try {

		image = imageNew( fileReadBinary( path ) );

		writeOutput( "PASS: imageNew( binary )<br />" );

	} catch ( any error ) {

		writeOutput( "FAIL: imageNew( binary )<br />" );
		writeOutput( "--- #error.message#<br />" );

	}


	// ------------------------------------------------------ //
	// ------------------------------------------------------ //


	try {

		imageFile = createObject( "java", "java.io.File" ).init(
			javaCast( "string", path )
		);

		fileSeekableStream = createObject( "java", "com.sun.media.jai.codec.FileSeekableStream" ).init( imageFile );

		parameterBlock = createObject( "java", "java.awt.image.renderable.ParameterBlock" ).init();

		parameterBlock.add( fileSeekableStream );

		// Use the Java Advanced Imaging library to read in the JPEG
		// file (will throw error if NOT jpeg) as a buffered image.
		// This will properly handle the different EXIF data types.
		bufferedImage = createObject( "java", "javax.media.jai.JAI" )
			.create(
				javaCast( "string", "jpeg" ),
				parameterBlock
			)
			.getAsBufferedImage()
		;

		image = imageNew( bufferedImage );

		// imageNegative( image ); // CAN HELP A LITTLE BIT.

		writeOutput( "PASS: Java Advanced Imaging.<br />" );

	} catch ( any error ) {

		writeOutput( "FAIL: Java Advanced Imaging.<br />" );
		writeOutput( "--- #error.message#<br />" );

	} finally {

		// Clean up the file stream, pass OR fail.
		fileSeekableStream.close();

	}


</cfscript>


<!--- If the file managed to be processed, then output it. --->
<cfif ! isNull( image )>

	<p>

		<cfimage
			action="writeToBrowser"
			source="#image#"
			/>

	</p>

</cfif>