Am 14.02.2006 16:20 Uhr schrieb "Kieran Kelleher" unter
<[EMAIL PROTECTED]>:

> Can someone recommend the quickest (free) java api to implement a few
> lines of code to just scale down an uploaded image to low
> resolution/smaller-size. Users upload JPG artwork (about 4MB) for
> postcard designs and I want to display a low-res scaled down version on
> the page after upload to show what they have uploaded. I need something
> quick and dirty and I know that ImageMagick has been talked about a
> lot, but I want something simple in Java that I can use in WebObjects
> and deploy to XServe (Panther).
Thats what i do (it's not simply java but...):

    class Thumber extends Thread
    {
        private String source;
        private String target;
    
        public Thumber ( String aSource, String aTarget )
        {
            source = aSource;
            target = aTarget;
        }
    
        public void run()
        {
            try
            {
                String command = "sips -Z 400 -s format jpeg -s
formatOptions low " + source + " --out " + target;
                if ( NSLog.debugLoggingAllowedForLevel (
NSLog.DebugLevelDetailed  ) )
                {
                    NSLog.out.appendln ( "Thumbing command : " + command );
                }
                Process p = Runtime.getRuntime ().exec ( command );
                if ( NSLog.debugLoggingAllowedForLevel (
NSLog.DebugLevelDetailed  ) )
                {
                    NSLog.out.appendln ( "Thumbing process waiting " );
                }
                new StreamGobbler ( p.getInputStream(), "Thumb-process
INPUT" ).start();
                new StreamGobbler ( p.getErrorStream(), "Thumb-process
ERROR" ).start();
                
                int terminated = p.waitFor ();
                if ( NSLog.debugLoggingAllowedForLevel (
NSLog.DebugLevelDetailed  ) )
                {
                    NSLog.out.appendln ( "Thumbing result: terminated (0=OK)
: " + terminated );
                    BufferedReader in = new BufferedReader( new
InputStreamReader ( p.getErrorStream () ) );
                    NSLog.out.appendln ( "Thumbing error : " + in.readLine
() );
                }
            }
            catch ( Exception e )
            {
                if ( NSLog.debugLoggingAllowedForLevel (
NSLog.DebugLevelDetailed  ) )
                {
                    // quiet error
                    NSLog.err.appendln ( "Error creating thumb file : " + e
);
                    e.printStackTrace();
                }
            }
        }
    }
--------

"sips" is included in mac os x. As a result i have the uploaded file and for
display purpose i use the thumbed file.
As an automatism i try to show thumbed files first, taking the original if
no thumb exists. This will help also for cases where no thumb could be
created... as for Word-Documents :-)
You may set the target resolution and size as you need.

I tried ThumbsUp in the same manner as above with varying results...

HTH

Wolfram


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to