Net Imaging. Developer's guide.


Contents
Location
How to place the applet on a web page. this document
How to implement the saving script this document
 
How to accept images having a predefined size this document
How to create the image's thumbnail this document
How to delete image files automatically this document
How to process large images this document
How to print from the applet this document
How to control NetImaging in JavaScript this document
 
Customizing the GUI and localization this document
 
The list of parameters this document
 
Compatibility notes this document
The product's home pageweb

How to place the applet on a web page.

The minimal HTML code to place the applet on a web page might look as follows:

<applet width="640" height="480" codebase="./applet/" archive="imaging.jar" code="Main.class">
  <param name="load" value="myimage.jpg">
  <param name="save" value="save.php">
</applet>

The attributes width and height might be set according to your page design but you should provide enough room for the applet controls. The attribute codebase should point to the applet's directory specified either as it's absolute URL or relative to the current HTML page, for example: codebase="../applet/"

The applet parameters are specified by the tags <param>. All the parameters are optional but to be useful the applet needs at least the two:

  • load - specifies URL of a JPEG or GIF image on your server. The image is loaded when the applet's HTML page is opened. If the parameter is not specified the applet loads nothing at start-up.
     
  • save - specifies URL of a server-side script that receives the resulting image. If the user presses the button save the applet requests this script to upload the resulting image to the server. You can implement such script in any server-side language like: PHP, ASP, JPS, Perl, etc. If the parameter is not specified the button "save" is disabled.

The section The list of parameters describes others parameters that allow you to customize the applet's GUI, apply different image constraints, etc.


How to implement the saving script

The applet request

When the user presses save button button, the applet uploads the image to the server requesting the script specified by the paramater "save".
The request looks as if it's made by a regular HTML upload form like the following:

<form method="post" action="save.php" enctype="multipart/form-data" >
    <input type="file" name="image">
    <input type="text" name="width">
    <input type="text" name="height">
    <input type="submit">
</form>

The image is passed as the value the field image. Along with the image itself the applet posts the image's width and height.

Response of the saving script ( Please read it carefully! )
The script is requested from the applet and the script's response (output) is returned to the applet as well (not to the browser!). The applet doesn't understand HTML content and has no way to display it, so you mustn't output HTML in your script as usual. Instead you should output special control commands which allow you to redirect the browser to another HTML page or display a popup message. The command(s) should be sent as plain text in the following form:

#COMMAND=parameter
Output example 1:
#SETDOCTAG=_blank
#SHOWDOCUMENT=confirm.html

Upon receiving this command sequence the applet opens the page confirm.html page in a new window.

Output example 2:
#SHOWERROR=Can't save the image file.

Upon receiving this command the applet displays the popup message: Can't save the image file.

The following table lists all the commands that the applet can process:

Command Applet's action
#SHOWDOCUMENT The browser opens a new document. The parameter is the document's URL.
The URL might be either absolute or relative to the saving script.
#SETDOCTAG The parameter is the target frame for the document opened by #SHOWDOCUMENT command.
This command must be sent before #SHOWDOCUMENT to have an effect.
If this command is not specified the document pointed by #SHOWDOCUMENT replaces the current page.
#SHOWMESSAGE The command parameter may be any text which is displayed in a popup dialog.
#SHOWERROR The same as #SHOWMESSAGE but the dialog is error decorated.
#SHOWSTATUS The parameter is displayed in the browser's status line.

You may output any number of the commands but keep in mind that:
  - each command must be placed on a separate line (i.e. separated by CRLF or LF characters)
  - the commands are processed in the order they have been output.

See the example scripts: save.asp, save.aspx, save.php, save.jsp in the directories ASP, ASP.NET , PHP, JSP respectively.


How to accept images having a predefined size

Say you wish all the uploaded images to have a predefined size, for example 80x60. In that case specify the parameters:

    <param name="scaleto" value="80,60">
    <param name="proportion" value="8,6">

The parameter scaleto asks the applet to scale the image to the specified size. The scaling is performed just before the upload, invisibly for the user, and regardless of the current image size.

The parameter proportion constraints the image proportion during the processing. If it's specified the crop box keeps the specified proportion and the user can't upload images if their side ratio differ from the specified one. This constraint allows to avoid proportion distortions at final scaling.

It's also recommended to specify the minimal image size to avoid rough image pixalization while scaling. See the section The list of parameters for more details about the constraint parameters.


How to create the image's thumbnail

The applet can produce the image's thumbnail and upload it along with the master image. To obtain the thumbnail you have to specify a frame the thumbnail should be fitted in. For example:

    <param name="thumbnail" value="40,30">

In that case the applet creates the image's thumbnail. It's width is less then or equal to 40 and height is less then or equal to 30. The upload request to the saving script looks as if it is issued by the following form:

<form method="post" action="save.php" enctype="multipart/form-data" >
    <!-- master image fields -->
    <input type="file" name="image">
    <input type="text" name="width">
    <input type="text" name="height">

    <!-- thumbnail image fields -->
    <input type="file" name="thumbnail">
    <input type="text" name="thumbnail_width">
    <input type="text" name="thumbnail_height">

    <input type="submit">
</form>

How to delete image files automatically

Let's say you need to use an image file only once, for example to load the original use's file to the applet. After that those file is not required. In that case you may do the following:

  1. Create a server side script which reads the image file, outputs the read data it as the response, and erases the file.
  2. Point this script as the value of the applet's parameter "load" instead of the image's URL.


How to process large images.

Net Imaging can't process very big image files because applets are not provided with enough memory resources. Typical image size maximum is about 3M pixels (for example 2048 x 1536). However Net Imaging can scale down big images to a reasonable size while opening them. To allow Net Imaging to scale down big images specify the parameter prescale. The parameter value is the maximum size that is allowed to be opened without scaling. If an image exceeds this size it is scaled down to the specified value. The value should be specified in pixels (or in MEGA pixel with the suffix 'M' after the value).

Example:
    <param name="prescale" value="3M">
Some notes about performance:

How to print from the applet.

The applet allows to print the displayed image. The print button is hidden by default. Use the parameter visible_buttons to specify the print button explicitly.
Example:

<param name="visible_buttons" value="print,save,crop,undo,redo">

Note: The printing functionality is available with Java Plug-in only. Microsoft's Java (the native engine of IE) doesn't allow applets to print.


Customizing the UI and localization

Colors, fonts and buttons

Using the applet parameters you can specify color and font for the labels and messages and the applet's background color. You can also specify what buttons are visible. Please read subsection Applet appearance in the section The list of parameters for details.

Text messages and labels
The applet uses some text resources: labels, messages, hints. You may customize these text strings; for example translate them to another language (or correct my English if you find it not blameless :-). To customize the resources:
  1. Create a copy of the file resources.txt located in the applet directory.
  2. Rewrite messages in this copy. Attention! Each non ASCII character should be performed as \uXXXX, where XXXX is the character's unicode.
  3. Point those new file by the parameter "resources". For example:  <param name="resources" value="german.txt"> 

You can create several resource files and point the appropriate one depending on the current language context.
Several national resource files have been prepared by Net Imaging users: chinese.txt, dutch.txt, french.txt, german.txt, norwegian.txt, russian.txt, spanish.txt.

Custom icons for the buttons

The button icons are kept in the applet's archive imaging.jar. To replace the icons with your own do the following:

  1. Unpack imaging.jar with any ZIP utility (imaging.jar is a regular ZIP archive).
  2. Replace the image files in the subdirectory 'images' with your own.
  3. Pack all the applet files bak to imaging.jar keeping the orginal directory structure.
Some useful notes:

The list of parameters

In addition to the parameters save and load the applet supports the following parameters:

parameter name parameter values and their meaning default
Upload control parameters default
jpeg_quality Specifies quality of the resulting JPEG file. It's value can be any integer from 1 to 100.
If this parameter is specified, the JPEG quality dialog doesn't appear. Thus the user is not able to control the JPEG quality while saving.
defined
by the user
filename File name for the resulting image image.jpg
blockunchanged If the parameter is set the editor prevents the user from saving unchanged image. The parameter's value can be any text which is displayed while the user tries to save an unchaged image. any image
can be saved
scaleto Asks the applet to scale the resulting image to a specific size. Example:
<param name="scaleto" value="90,120">
The scaling is performed just before the upload and is invisible to the user. Since scaling is made regardless to the image proprotion it's recommended to use this parameter in conjunction with the parameter "proportion" which acts at the processing time and allows to avoid proportion distortions at final scaling.
-
scale_method Allows to specify a scaling method which is used for resize operations and thumbnail production. The value can be one of the following: "default", "smooth", "averaging", "replicate".
Example: <param name="scale_method" value="smooth">
the default
(usually fastest)
thumbnail Asks the applet to create image thumbnail and upload it along with the image itself. The parameter's value must be width and height of the frame the thumbnail should fitted in. Example: <param name="thumbnail" value="50,50">
Along with the thumbnail the applet posts two values "thumbnail_width" and "thumbnail_height" which describe the actual size of the created the thumbnail.
-
thumbfilename File name for the image's thumbnail (if the thumbnail parameter is defined) thumbnail.jpg
logo URL of a small image file (GIF or JPEG) that you wish to apply to the users image. The specified image is put at right-bottom corner of the user's image before the upload and print. The URL can be specified as absolute or relative to the current HTML file.
Example: <param name="logo" value="mylogo.gif">
-
Image constraints parameters
If at least one of the following constraint parameters is specified the applet displays a special indicator that shows the user if the current image is proper; and if the user tries to upload an improper image the appropriate error message is displayed and the upload action is blocked.
default
proportion Defines width:height proportion of the resulting image. The value must be two integers separated by comma that specify a width:height ratio, for example: <param name="proportion" value="3,4">
 
if this parameter is specified the user is able to resize the crop tool however it's proportion is kept automatically.
 
Caution: Because of integer-valued rounding it's impossible sometimes to keep the specified proportion strictly, In such cases the applet maintains the constraint approximately. To control degree of this approximation you can specify (optionally) the required proportion precision. For example: <param name="proportion" value=" 3,4, 0.03 ">  
The example specifies that the proprotion 3:4 must be kept no worse then 3%. If no precision is specifyed the default value 0.02 is used.
-
minsize Defines minimum size of the resulting image. The value must contain width and height separated by comma, for example: <param name="minsize" value="60,80">
 
If this parameter is specified the applet doesn't allow to save the resulting image if it's size is less then the specified one.
-
maxsize Defines maximum size of the resulting image. The value must contain width and height separated by comma, for example: <param name="maxsize" value="300,400">
 
If this parameter is specified the applet doesn't allow to save the resulting image if it's size is greater then the specified one.
 
You may also specify the optional parameter value auto after the size, for example:
<param name="maxsize" value="500,500,auto">
In that case the applet doesn't warn the user about big image size but scales down the image automatically before the upload.
-
Applet appearance
bgcolor The applet's backgound color. Should be specified as #RRGGBB #C0C0C0
fgcolor Color for labels, messages and outlines. Should be specified as #RRGGBB #000000
font Font for labels and messages. Should be specified as FONTFACE-STYLE-SIZE.
where:
  FONTFACE must be one of the following: Serif, SansSerif, Monospaced, Dialog.
  STYLE must be one of the following: plain, bold, italic, bolditalic.
  SIZE must be a reasonable integer number.
Example:
  <param name="font" value="Serif-bold-16">
Dialog-plain-12
visible_buttons Allows to specify what buttons are visible on the top panel. The parameter may contain the following comma delimited words: save,print,resize,crop,cclockw,clockw,fliph,flipv,sepia,redeye,vars,undo,redo,zoomwin,zoom100.
For example: <param name="visible_buttons" value="save,resize,crop,undo,redo">
The buttons are displayd in the order they are listed. To make a gap between buttons use two commas typed one after another, for example "save, ,resize, ,undo,redo".
all the buttons
are visible
outline Allows to turn on/off outlines of the buttons, panels, and dialogs. Possible values are: true and false. true
hidestatuspanel Specifies to hide the status panel (containing the image size and constraint indicator). Possible values are: true and false. false
zoom Sets the initial image zoom. You can specify any positive integer value, or "0" to fit the image in the applet's window. Fit in Window
select Allows to display the selection rectangle at startup. The parameter's permits three value formats:
  • x,y,width,height. For example: <param name="select" value="10,15,150,200">
  • width,height. For example: <param name="select" value="150,200">
    In that case the selection box is placed at the image center.
  • You may also use the keyword "best" as the parameter's value. In that case the applet displays the selection box with size and postion the most appropriate to the image size and constraints (if they are defined). Example: <param name="select" value="best">
Note: if the specified size or postion exceeds the image bounds, the selection box is not displayed.
-
prescale Specifies to scale down big image files. The parameter value is image size in pixels that can be opened without prescale. The value can also be specified in Mega pixels. For that set the suffix "M" after the value. Example: <param name="prescale" value="3M">
See additional notes in the section How to process large images.
-
resources URL of the resource file. See Customization and localization for details. resources.txt

 


Compatibility notes

Net Imaging was tested with the following browsers: IE4.x, IE5.x, IE6, Netscape 4.7, 6.2, 7.2, Mozilla 1.6, Firefox 1.0. The tests were made for both native browser's JVM:s (if such exist) and the Sun's Java Plug-in (JRE 1.3, 1.4, 1.5). The following issues have been found:

An issue after a Windows XP security update

After the Windows XP security update published at the April, 2006 the browsers IE6 and IE7 ask users to click twice on any active content on web pages (applets, Active-X objects, etc..) before allowing to interact with them. To resolve the issue please read this article: http://izhuk.com/docs/ie7fix.html

Regardless of the successful tests the Author is not responsible for correct applet operation on any particular hardware, software platform, and their configurations.


Copyright 2003 - 2008. Igor Zhukovsky www.izhuk.com