Skip to content

Commit

Permalink
Added getBytes method
Browse files Browse the repository at this point in the history
- Added code to return the result image as a byte array, sent in by
  Paul Bowler.
- Updated documentation.
- Updated version number.
  • Loading branch information
Ricardo J. Mendez committed Mar 7, 2009
1 parent 3442cbe commit 711627e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ImageTools documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
imageTool.writeResult("smaller.640.jpg", "JPEG")
{code}

Starting on 1.0.4, it can also be saved as a byte array, courtesy of code sent in by Paul Bowler:

{code}
var arr = imageTool.getBytes("JPEG")
{code}


An important note is that the loaded image is never explicitly replaced after an operation - instead, a resulting image is created in the object. If you wish to apply more operations to the result, you should swap it with the originally loaded image.

Expand Down
2 changes: 1 addition & 1 deletion ImageToolsGrailsPlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ImageToolsGrailsPlugin {
def version = "1.0.3";
def version = "1.0.4";
def dependsOn = [:]

def author = "Ricardo J. Mendez"
Expand Down
12 changes: 12 additions & 0 deletions src/groovy/ImageTool.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ class ImageTool {
JAI.create("encode", result, os, type, null);
os.close()
}

/**
* Returns the resulting image as a byte array.
*
* @param type file type for the image
* @see <a href="http://java.sun.com/products/java-media/jai/iio.html">Possible JAI encodings</a>
*/
public byte[] getBytes(String type) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JAI.create("encode", result, bos, type, null);
return bos.toByteArray()
}


/**
Expand Down

0 comments on commit 711627e

Please sign in to comment.