• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Quick Image scale down
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quick Image scale down


  • Subject: Re: Quick Image scale down
  • From: Wolfram Stebel <email@hidden>
  • Date: Tue, 14 Feb 2006 17:42:53 +0100
  • Thread-topic: Quick Image scale down

Am 14.02.2006 16:20 Uhr schrieb "Kieran Kelleher" unter
<email@hidden>:

> 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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Quick Image scale down
      • From: Kieran Kelleher <email@hidden>
References: 
 >Quick Image scale down (From: Kieran Kelleher <email@hidden>)

  • Prev by Date: Re: EOQualifier on a toMany attribute
  • Next by Date: Javascript focus on text field in repetition
  • Previous by thread: Quick Image scale down
  • Next by thread: Re: Quick Image scale down
  • Index(es):
    • Date
    • Thread