www.element4solution.com

e4s.util
Class E4ImageResizer

java.lang.Object
  extended by e4s.util.E4Object
      extended by e4s.util.E4ImageResizer

public class E4ImageResizer
extends E4Object

Resizes an image specified by a relative filename based on the client's root path by a specified width and height in pixels. The image will be cached in a temporary directory (TEMP_PATH under the client's path and an tag for width and height.

Example_ImageResizer.java


Nested Class Summary
static class E4ImageResizer.E4ImageResizerSize
          Image width and height
static class E4ImageResizer.PostProcessingInformation
           
 
Field Summary
 
Fields inherited from class e4s.util.E4Object
CRLF, E4S_CORE_SYSTEM_LANGUAGE, NBSP, NULLSTR, URL_ENCODING_CHARSET
 
Constructor Summary
E4ImageResizer(E4ApplObj_Intf applobj, E4String filename)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.
E4ImageResizer(E4ApplObj_Intf applobj, IMG image)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.
E4ImageResizer(E4ApplObj_Intf applobj, java.lang.String filename)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.
E4ImageResizer(E4Client client, E4String filename)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.
E4ImageResizer(E4Client client, IMG image)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.
E4ImageResizer(E4Client client, java.lang.String filename)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.
E4ImageResizer(E4String filename)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the application (equal for all clients !).
E4ImageResizer(IMG image)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the application (equal for all clients !).
E4ImageResizer(java.lang.String filename)
          Make an instance of this E4ImageResizer class with a relative filename under the root directory of the application (equal for all clients !).
 
Method Summary
static java.lang.String _getSVNVersionString()
           
 E4Color getBackgroundColor()
          Return the background color which is required for any offset-filling in the case that image width/length are is different from target width/length.
 E4Color getBorderColor()
          Get the border color.
 E4Client getClient()
           
 java.lang.String getLastError()
           
 E4ImageResizer.PostProcessingInformation getLastProcessingInformation(int width, int height)
          Either, this information is from the last conversion - or - if the image was not scaled because it exists in the cache, or width/height is different, values are recalculated here.
 java.lang.String getResizedPath(int width, int height)
          Deprecated.  
 java.lang.String getResizedPathAbs(int width, int height)
           
static IMG getScaledImage(E4Client client, IMG img, int width, int height)
           
static IMG getScaledImage(E4Client client, IMG img, int width, int height, E4Color bgColor, E4Color borderColor)
           
static IMG getScaledImage(E4Client client, java.lang.String filename, int width, int height)
           
static IMG getScaledImage(E4Client client, java.lang.String filename, int width, int height, E4Color bgColor, E4Color borderColor)
           
static IMG getScaledImage(IMG img, int width, int height)
           
static IMG getScaledImage(IMG img, int width, int height, E4Color bgColor, E4Color borderColor)
           
 IMG getScaledImage(int width, int height)
          Get the scaled image which will be created and stored under the TEMP_PATH directory structure, containing one sub directory for each pair of width/height values.
 IMG getScaledImage(int width, int height, boolean use_cache)
          Get the scaled image which will be created and stored under the TEMP_PATH directory structure, containing one sub directory for each pair of width/height values.
static IMG getScaledImage(java.lang.String filename, int width, int height)
           
static IMG getScaledImage(java.lang.String filename, int width, int height, E4Color bgColor, E4Color borderColor)
           
 E4ImageResizer.E4ImageResizerSize getSize()
          Get Information (width, height) about the image
 java.lang.String getTempPath(int width, int height)
           
static void removeTemporaryFiles(E4Client client)
          Removes all temporary files for the specified client, or if the client is null for the application.
 boolean requiresRendering(int width, int height)
          Check, if an image requires rendering (non existant in that size, changed file)
 void setBackgroundColor(java.awt.Color color)
          Define a background color which is required for any offset-filling in the case that image width/length are is different from target width/length.
 void setBackgroundColor(E4Color color)
          Define a background color which is required for any offset-filling in the case that image width/length are is different from target width/length.
 void setBorderColor(java.awt.Color color)
          Define a border color which is optional.
 void setBorderColor(E4Color color)
          Define a border color which is optional.
 void setDestinationPathRelative(java.lang.String path_relative)
          A value of null (= default) uses a generic path based on the #TEMP directory, followed by the image dimensions (something like "temp/0100x0200").
static java.lang.String storeScaledImage(java.net.URL remote_path, java.lang.String filename_local)
          Read a file from a remote server and store it on a specified local path.
static java.lang.String storeScaledImage(java.net.URL remote_path, java.lang.String filename_local, int target_width, int target_height)
          Read and rescale a file from a remote server and store it on a specified local path.
 
Methods inherited from class e4s.util.E4Object
Calendar, CName, CName, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelNone, E4LabelNone, E4LabelNone, E4LabelNone, E4LabelSys, E4LabelSys, e4sCopyright, e4sVersion, encode, encode, encode, encodeHtml, encodeHtml, encodeHtml, encodeURL, encodeURL, encodeURL, finalize, getLINE, getTRACE, getTRACE, getTRACE, getTRACE, getTRACE, getTRACE, getTraceMemory, HtmlEncode, HtmlEncode, HtmlEncode, isdecimal, isdigit, isnotok, isnotok, isnumeric, isok, isok, isok, isok, lastCallingFunction, lastCallingFunction, lastCallingFunction, lastCallingFunction, lastCallingStack, mkdirs, null2nbsp, null2nbsp, null2nbsp, ok, ok, ok, ok, outPrintln, setLogFile4Trace, setTraceMemory, STACKTRACE, toDebug, toDouble, toFloat, toFloat, toString, TRACE_CALLS, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, wait
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

E4ImageResizer

public E4ImageResizer(java.lang.String filename)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the application (equal for all clients !).

Parameters:
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(IMG image)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the application (equal for all clients !).

Parameters:
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4String filename)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the application (equal for all clients !).

Parameters:
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4ApplObj_Intf applobj,
                      java.lang.String filename)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.

Parameters:
applobj - the current application object containing the actual client
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4ApplObj_Intf applobj,
                      IMG image)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.

Parameters:
applobj - the current application object containing the actual client
image - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4ApplObj_Intf applobj,
                      E4String filename)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.

Parameters:
applobj - the current application object containing the actual client
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4Client client,
                      java.lang.String filename)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.

Parameters:
client - the actual client
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4Client client,
                      IMG image)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.

Parameters:
client - the actual client
image - a relative filename (only .jpg, .jpeg, .png or .gif supported)

E4ImageResizer

public E4ImageResizer(E4Client client,
                      E4String filename)
Make an instance of this E4ImageResizer class with a relative filename under the root directory of the specified client.

Parameters:
client - the actual client
filename - a relative filename (only .jpg, .jpeg, .png or .gif supported)
Method Detail

getSize

public E4ImageResizer.E4ImageResizerSize getSize()
Get Information (width, height) about the image

Returns:
an object that contains width or height

requiresRendering

public boolean requiresRendering(int width,
                                 int height)
                          throws java.lang.Exception
Check, if an image requires rendering (non existant in that size, changed file)

Throws:
java.lang.Exception

getScaledImage

public IMG getScaledImage(int width,
                          int height)
                   throws java.lang.Exception
Get the scaled image which will be created and stored under the TEMP_PATH directory structure, containing one sub directory for each pair of width/height values. The file will be stored in .png format, whatever format it has been before. Does not use cache.

Parameters:
width - the width in pixels
height - the height in pixels
Returns:
null in the case of an error or the image object
Throws:
java.lang.Exception

getScaledImage

public IMG getScaledImage(int width,
                          int height,
                          boolean use_cache)
                   throws java.lang.Exception
Get the scaled image which will be created and stored under the TEMP_PATH directory structure, containing one sub directory for each pair of width/height values. The file will be stored in .png format, whatever format it has been before.

Parameters:
width - the width in pixels
height - the height in pixels
use_cache - uses a cache for some seconds, can result in out of memory exceptions when many images are beeing rendered in short time
Returns:
null in the case of an error or the image object
Throws:
java.lang.Exception

getTempPath

public java.lang.String getTempPath(int width,
                                    int height)

getResizedPath

public java.lang.String getResizedPath(int width,
                                       int height)
Deprecated. 

See Also:
getResizedPathAbs(int,int)

getResizedPathAbs

public java.lang.String getResizedPathAbs(int width,
                                          int height)

getBackgroundColor

public E4Color getBackgroundColor()
Return the background color which is required for any offset-filling in the case that image width/length are is different from target width/length. return the background color

See Also:
getBackgroundColor()

setBackgroundColor

public void setBackgroundColor(java.awt.Color color)
Define a background color which is required for any offset-filling in the case that image width/length are is different from target width/length.

Parameters:
color - a AWT color
See Also:
getBackgroundColor()

setBackgroundColor

public void setBackgroundColor(E4Color color)
Define a background color which is required for any offset-filling in the case that image width/length are is different from target width/length.

Parameters:
color - an AWT color, the default is white
See Also:
getBackgroundColor(), setBackgroundColor(e4s.html.E4Color)

getBorderColor

public E4Color getBorderColor()
Get the border color.

Returns:
the border color, null means no border color which is the default
See Also:
getBackgroundColor(), setBackgroundColor(e4s.html.E4Color)

setBorderColor

public void setBorderColor(java.awt.Color color)
Define a border color which is optional.

Parameters:
color - an AWT color or null if no border shall be drawn (default)
See Also:
getBackgroundColor(), setBackgroundColor(e4s.html.E4Color)

setBorderColor

public void setBorderColor(E4Color color)
Define a border color which is optional.

Parameters:
color - a color or null if no border shall be drawn (default)
See Also:
getBackgroundColor(), setBackgroundColor(e4s.html.E4Color)

removeTemporaryFiles

public static void removeTemporaryFiles(E4Client client)
Removes all temporary files for the specified client, or if the client is null for the application.


getScaledImage

public static IMG getScaledImage(IMG img,
                                 int width,
                                 int height)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(java.lang.String filename,
                                 int width,
                                 int height)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(IMG img,
                                 int width,
                                 int height,
                                 E4Color bgColor,
                                 E4Color borderColor)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(java.lang.String filename,
                                 int width,
                                 int height,
                                 E4Color bgColor,
                                 E4Color borderColor)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(E4Client client,
                                 IMG img,
                                 int width,
                                 int height)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(E4Client client,
                                 java.lang.String filename,
                                 int width,
                                 int height)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(E4Client client,
                                 IMG img,
                                 int width,
                                 int height,
                                 E4Color bgColor,
                                 E4Color borderColor)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getScaledImage

public static IMG getScaledImage(E4Client client,
                                 java.lang.String filename,
                                 int width,
                                 int height,
                                 E4Color bgColor,
                                 E4Color borderColor)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getClient

public E4Client getClient()

storeScaledImage

public static java.lang.String storeScaledImage(java.net.URL remote_path,
                                                java.lang.String filename_local)
                                         throws java.lang.Exception
Read a file from a remote server and store it on a specified local path.

Parameters:
remote_path - the URL of the image to be read
filename_local - a local filename (absolute path and filename)
Returns:
the filename (extension might be changed to ".png")
Throws:
java.lang.Exception

storeScaledImage

public static java.lang.String storeScaledImage(java.net.URL remote_path,
                                                java.lang.String filename_local,
                                                int target_width,
                                                int target_height)
                                         throws java.lang.Exception
Read and rescale a file from a remote server and store it on a specified local path.

Parameters:
remote_path - the URL of the image to be read
filename_local - a local filename (absolute path and filename)
target_width - -1 means no resizing or the target width in picel
target_height - -1 means no resizing or the target height in pixel
Returns:
the filename (extension might be changed to ".png")
Throws:
java.lang.Exception

getLastError

public java.lang.String getLastError()

getLastProcessingInformation

public E4ImageResizer.PostProcessingInformation getLastProcessingInformation(int width,
                                                                             int height)
Either, this information is from the last conversion - or - if the image was not scaled because it exists in the cache, or width/height is different, values are recalculated here.


setDestinationPathRelative

public void setDestinationPathRelative(java.lang.String path_relative)
A value of null (= default) uses a generic path based on the #TEMP directory, followed by the image dimensions (something like "temp/0100x0200"). A call to this function is not necessary, unless you want to change file location away from the temp directory.

Parameters:
path_relative - a path, relative to and within the client directory

_getSVNVersionString

public static java.lang.String _getSVNVersionString()

www.element4solution.com