This is the first in a series of questions and answers about PXN8. This question is from a Java team lead who wants to use PXN8 in their J2EE environment.
Because it is a J2EE project, the source image to be edited is sent from a Servlet in the form of an IO stream, and the finished image should stream up to a Servlet. Can PXN8 support this ?
This is actually 2 questions…
- Can PXN8 edit images returned by a servlet or other CGI ?
- Can the edited image be saved via a servlet ?
To answer the first question – Yes, PXN8 can edit either dynamic or static images. Assuming you have a servlet which streams an image from a database blob, the normal way to dislpay the image would be…
<img src="/imageServlet?imageId=493432" />
Where “/imageServlet” is the path to the servlet that streams the image, and “imageId” is the name of the parameter used by the servlet to uniquely identify the image (let’s assume the image is stored as a BLOB in a database). Well, PXN8 doesn’t treat dynamically created images any differently to static images. To begin editing the above image, use the following …
To answer the second question: Can the edited image be saved via a servlet ? – Yes the edited image can be saved via a servlet and here’s how…
First let’s assume the servlet is called ‘saveImageServlet’ and it takes a parameter named ‘imagePath’ which is a relative path to the modified image.
Add a form to the edit page …
<form action="/saveImageServlet" onsubmit="return insertImagePath();"> <input id="imagePath" name="imagePath" type="hidden" value=""/> <input type="submit" value="Save Image"/> </form>
The form’s “onsubmit” attribute refers to a script called “insertImagePath()”. This function (which has not yet been defined) will insert the modified image path into the form prior to submitting the form (since we can’t know in advance what the modified image’s path will be).
Next add the following script to your edit page.
What the above function does is get the hidden ‘imagePath’ field, set it’s value to that returned by PXN8.getUncompressedImage() (a function I will talk about in more detail) and returns true. The function must return true or the form won’t be submitted.
PXN8.getUncompressedImage() function returns the relative path of the current modified image (at 100% quality – this is a higher quality, uncompressed version of the image displayed in the browser – Images displayed in the browser are at 85% quality to save on bandwidth). PXN8 stores all modified images in the
cache/ folder, so the
PXN8.getUncompressedImage() function might return something like the following…
This path is relative to the folder where you installed PXN8.
If you are writing a servlet or CGI script to save the image to a server gallery or database, remember that the image you want to save is already on the server. If saving to a permanent gallery, just copy the image from the temporary cache folder to the permanent gallery folder. If saving the image to a database using Java, then open a FileInputStream object and a Connection object and store the bytes into a
As you can probably guess, the
script elements described above will work equally well for a PHP implementation – just change the form’s