Re: Quick Image scale down
Re: Quick Image scale down
- Subject: Re: Quick Image scale down
- From: Kieran Kelleher <email@hidden>
- Date: Tue, 14 Feb 2006 13:15:57 -0500
Good suggestion Wolfram ..... I had forgotten completely about sips, I
had wanted to avoid doing Runtime exec and keep it all in java vm,
however, if it works fast and reliably, I'll try it. Is this fast to
execute and reliable? I am guessing that since it is native, it might
be a lot faster than working with awt or whatever .... is that correct?
On Feb 14, 2006, at 11:42 AM, Wolfram Stebel wrote:
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