Resizing images

35 views
Skip to first unread message

Charles F. Munat

unread,
Apr 16, 2009, 1:36:58 AM4/16/09
to Lift
Has anyone here done anything with Lift in which uploaded images are
resized (or otherwise manipulated) before saving? If so, how did you do
it? Any recommendations for libraries?

Thanks!

Chas.

Viktor Klang

unread,
Apr 16, 2009, 3:46:01 AM4/16/09
to lif...@googlegroups.com

GAE offers that kind of functionality.
 


Thanks!

Chas.





--
Viktor Klang
Senior Systems Analyst

Charles F. Munat

unread,
Apr 16, 2009, 4:20:54 AM4/16/09
to lif...@googlegroups.com
The Georgia Association of Editors? That's good to know.

(Unfortunately, the app is already built and running on my own server
and I have no time to play with GAE right now. But I'm getting more and
more curious about it.)

It's funny. I would think that lots of people would be resizing uploaded
images in Java, but I've asked this question before and got nothing.
Ruby/Rails folks do this sort of thing all the time with RMagick (and
half a dozen other tools). What the heck do Java developers do?

Thanks, Viktor!

Chas.

Jean-Luc

unread,
Apr 16, 2009, 5:10:45 AM4/16/09
to lif...@googlegroups.com
Imagemagick is said to be very efficient for image processing.
http://www.imagemagick.org/script/api.php#java

If you develop with MacOSX, some people had some compile issues with JMagick and have prefered a more direct solution using "exec" : http://www.darcynorman.net/2005/03/15/jai-vs-imagemagick-image-resizing/

Jean-Luc


2009/4/16 Charles F. Munat <ch...@munat.com>



--
Jean-Luc Canela
jlca...@gmail.com

Alexander Kellett

unread,
Apr 16, 2009, 6:59:43 AM4/16/09
to lif...@googlegroups.com

Derek Chen-Becker

unread,
Apr 16, 2009, 12:46:10 PM4/16/09
to lif...@googlegroups.com
Jai or just Java2D would work. I use JAI a lot at work (wrote a large-scale image rendering and compositing application), so if you run into issues there just ask.  JAI can be somewhat heavy if you have simple requirements, so you could also just use the Image.getScaledInstance method, which is far simpler. For example:

import java.awt.{Image,Tookit}

val imageData : Array[Byte] = ...

val scaled = Toolkit.getDefaultToolkit.createImage(imageData).getScaledUInstace(width, height, Image.SCALE_SMOOTH)

The final param controls which algorithm to use for scaling, so you can use several as defined on the java.awt.Image class.

Derek

Charles F. Munat

unread,
Apr 16, 2009, 2:30:19 PM4/16/09
to lif...@googlegroups.com
I develop on a Mac, but deploy to Linux. I didn't know there was a
JMagick. Thanks! I'll look into it.

Chas.

Jean-Luc wrote:
> Imagemagick is said to be very efficient for image processing.
> http://www.imagemagick.org/script/api.php#java
>
> If you develop with MacOSX, some people had some compile issues with
> JMagick and have prefered a more direct solution using "exec" :
> http://www.darcynorman.net/2005/03/15/jai-vs-imagemagick-image-resizing/
>
> Jean-Luc
>
>
> 2009/4/16 Charles F. Munat <ch...@munat.com <mailto:ch...@munat.com>>
>
>
> The Georgia Association of Editors? That's good to know.
>
> (Unfortunately, the app is already built and running on my own server
> and I have no time to play with GAE right now. But I'm getting more and
> more curious about it.)
>
> It's funny. I would think that lots of people would be resizing uploaded
> images in Java, but I've asked this question before and got nothing.
> Ruby/Rails folks do this sort of thing all the time with RMagick (and
> half a dozen other tools). What the heck do Java developers do?
>
> Thanks, Viktor!
>
> Chas.
>
> Viktor Klang wrote:
> >
> >
> > On Thu, Apr 16, 2009 at 7:36 AM, Charles F. Munat <ch...@munat.com
> <mailto:ch...@munat.com>
> > <mailto:ch...@munat.com <mailto:ch...@munat.com>>> wrote:
> >
> >
> > Has anyone here done anything with Lift in which uploaded
> images are
> > resized (or otherwise manipulated) before saving? If so, how
> did you do
> > it? Any recommendations for libraries?
> >
> >
> > GAE offers that kind of functionality.
> >
> >
> >
> >
> > Thanks!
> >
> > Chas.
> >
> >
> >
> >
> >
> > --
> > Viktor Klang
> > Senior Systems Analyst
> >
> > >
>
>
>
>
>
> --
> Jean-Luc Canela
> jlca...@gmail.com <mailto:jlca...@gmail.com>
>
> >

Charles F. Munat

unread,
Apr 16, 2009, 2:32:24 PM4/16/09
to lif...@googlegroups.com
Thanks! I tried JAI before but couldn't get it to work in Scala. I'm a
much better Scala programmer now, though, so maybe I'll give it another
look. Do you think it has any advantages of the other methods mentioned
(imageio and jmagick)?

Have you actually made it work in Lift?

Chas.

Charles F. Munat

unread,
Apr 16, 2009, 2:43:55 PM4/16/09
to lif...@googlegroups.com
This is very helpful. I'm glad to hear that others are doing this. I
read, however, that getScaledInstance is slow. Probably not a huge issue
since uploaded images will be infrequent...

Thanks for the help!

Chas.
> > 2009/4/16 Charles F. Munat <ch...@munat.com <mailto:ch...@munat.com>>
> >>
> >> The Georgia Association of Editors? That's good to know.
> >>
> >> (Unfortunately, the app is already built and running on my own
> server
> >> and I have no time to play with GAE right now. But I'm getting
> more and
> >> more curious about it.)
> >>
> >> It's funny. I would think that lots of people would be resizing
> uploaded
> >> images in Java, but I've asked this question before and got nothing.
> >> Ruby/Rails folks do this sort of thing all the time with RMagick
> (and
> >> half a dozen other tools). What the heck do Java developers do?
> >>
> >> Thanks, Viktor!
> >>
> >> Chas.
> >>
> >> Viktor Klang wrote:
> >> >
> >> >
> >> > On Thu, Apr 16, 2009 at 7:36 AM, Charles F. Munat
> <ch...@munat.com <mailto:ch...@munat.com>
> >> > <mailto:ch...@munat.com <mailto:ch...@munat.com>>> wrote:
> >> >
> >> >
> >> > Has anyone here done anything with Lift in which uploaded
> images are
> >> > resized (or otherwise manipulated) before saving? If so,
> how did you
> >> > do
> >> > it? Any recommendations for libraries?
> >> >
> >> >
> >> > GAE offers that kind of functionality.
> >> >
> >> >
> >> >
> >> >
> >> > Thanks!
> >> >
> >> > Chas.
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > Viktor Klang
> >> > Senior Systems Analyst
> >> >
> >> > >
> >>
> >>
> >
> >
> >
> > --
> > Jean-Luc Canela
> > jlca...@gmail.com <mailto:jlca...@gmail.com>
> >
> > >
> >
>
>
>
>
> >

Derek Chen-Becker

unread,
Apr 16, 2009, 3:10:38 PM4/16/09
to lif...@googlegroups.com
Yes, I take back my recommendation for it. I didn't realize just how bad it was, but here's a good article on it:

http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html

JAI works well, but adds a dependency. One note on performance: We have found in our testing that the pure java impl of JAI actually outperforms the "optimized" native code by quite a bit for most common operations like scaling, transforms, crops, etc.

Derek

Charles F. Munat

unread,
Apr 16, 2009, 4:08:40 PM4/16/09
to lif...@googlegroups.com
What do you mean by "pure java implementation" vs. "optimized native code"?

Chas.
> > <mailto:lyp...@gmail.com <mailto:lyp...@gmail.com>>> wrote:
> >
> >
> > i used jai in the past, a quick google let me to
> >
> http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html
> >
> > On Thu, Apr 16, 2009 at 11:10 AM, Jean-Luc
> <jlca...@gmail.com <mailto:jlca...@gmail.com>
> > <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>>> wrote:
> > > Imagemagick is said to be very efficient for image processing.
> > > http://www.imagemagick.org/script/api.php#java
> > >
> > > If you develop with MacOSX, some people had some compile
> issues
> > with JMagick
> > > and have prefered a more direct solution using "exec" :
> > >
> >
> http://www.darcynorman.net/2005/03/15/jai-vs-imagemagick-image-resizing/
> > >
> > > Jean-Luc
> > >
> > >
> > > 2009/4/16 Charles F. Munat <ch...@munat.com
> <mailto:ch...@munat.com> <mailto:ch...@munat.com <mailto:ch...@munat.com>>>
> <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>>
> > >
> > > >
> > >
> >
> >
> >
> >
> > >
>
>
>
>
> >

Derek Chen-Becker

unread,
Apr 16, 2009, 4:47:21 PM4/16/09
to lif...@googlegroups.com
If you use JAI there are three implementations: one is pure java code and will run anywhere. There are two more versions that use JNI to provide "optimized" versions of some of the ops. We found that using the native (MMX, I think) code under Linux and Windows was significantly slower (order of magnitude or more) than just using the impl without native libraries. I can dig up timing results if you want, but for something as simple as scaling I think it would be better to just use the pure java version.

Derek

David Pollak

unread,
Apr 16, 2009, 4:48:28 PM4/16/09
to lif...@googlegroups.com
On Thu, Apr 16, 2009 at 1:08 PM, Charles F. Munat <ch...@munat.com> wrote:

What do you mean by "pure java implementation"

My understanding is that the pure java stuff calls the local window system so it uses the graphics accelerator.
 



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Derek Chen-Becker

unread,
Apr 16, 2009, 4:53:47 PM4/16/09
to lif...@googlegroups.com
I hadn't thought of that, but that could be part of it. Also, it seemed like JIT was doing a very good job of optimizing hotspots, and there appeared to be a peformance hit for shuttling the data back and forth via JNI.

Derek

Charles F. Munat

unread,
Apr 16, 2009, 5:54:16 PM4/16/09
to lif...@googlegroups.com
I'm down with that. I tried adding this to my pom:

<dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>1.1.2_01</version>
</dependency>

But I got this:

Failed to resolve artifact.

Missing:
----------
1) javax.media:jai_core:jar:1.1.2_01

Anyone know how to pull this in via Maven?

Chas.
> > <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>
> <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>>>
> > > >
> > > > >
> > > >
> > >
> > >
> > >
> > >
> > > >
> >
> >
> >
> >
> > >
>
>
>
>
> >

Derek Chen-Becker

unread,
Apr 16, 2009, 5:59:57 PM4/16/09
to lif...@googlegroups.com
I don't know that it's in maven. A lot of sun libraries aren't distributable via Maven due to licensing.

Derek

Timothy Perrett

unread,
Apr 16, 2009, 6:59:25 PM4/16/09
to lif...@googlegroups.com

Charles,

One google finds me a repo here:

http://maven.geotools.fr/repository/

Add that to your pom.xml and away you go.

Tim

Charles F. Munat

unread,
Apr 16, 2009, 7:46:13 PM4/16/09
to lif...@googlegroups.com
Yeah, I'm pretty sure it's not. Weirdly, it's listed, but when you drill
down, there's no jar there. But it's not clear whether it's already
available on the system. And finding the damn jar is provide (as always)
to be nearly impossible. I'll post if I find it.

Chas.
> > <mailto:ch...@munat.com <mailto:ch...@munat.com>>> wrote:
> >
> >
> > What do you mean by "pure java implementation" vs. "optimized
> native
> > code"?
> >
> > Chas.
> >
> > Derek Chen-Becker wrote:
> > > Yes, I take back my recommendation for it. I didn't
> realize just
> > how bad
> > > it was, but here's a good article on it:
> > >
> > >
> >
> http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
> > >
> > > JAI works well, but adds a dependency. One note on
> performance:
> > We have
> > > found in our testing that the pure java impl of JAI actually
> > outperforms
> > > the "optimized" native code by quite a bit for most common
> operations
> > > like scaling, transforms, crops, etc.
> > >
> > > Derek
> > >
> > > On Thu, Apr 16, 2009 at 1:43 PM, Charles F. Munat
> <ch...@munat.com <mailto:ch...@munat.com>
> > <mailto:ch...@munat.com <mailto:ch...@munat.com>>
> > <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>>>>>
> wrote:
> > > > > Imagemagick is said to be very efficient for
> image
> > processing.
> > > > > http://www.imagemagick.org/script/api.php#java
> > > > >
> > > > > If you develop with MacOSX, some people had some
> > compile
> > > issues
> > > > with JMagick
> > > > > and have prefered a more direct solution
> using "exec" :
> > > > >
> > > >
> > >
> >
> http://www.darcynorman.net/2005/03/15/jai-vs-imagemagick-image-resizing/
> > > > >
> > > > > Jean-Luc
> > > > >
> > > > >
> > > > > 2009/4/16 Charles F. Munat <ch...@munat.com
> <mailto:ch...@munat.com>
> > <mailto:ch...@munat.com <mailto:ch...@munat.com>>
> > > <mailto:ch...@munat.com <mailto:ch...@munat.com>
> <mailto:ch...@munat.com <mailto:ch...@munat.com>>>
> > > <mailto:jlca...@gmail.com
> <mailto:jlca...@gmail.com> <mailto:jlca...@gmail.com
> <mailto:jlca...@gmail.com>>
> > <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>
> <mailto:jlca...@gmail.com <mailto:jlca...@gmail.com>>>>
> > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > > >
> > >
> > >
> > >
> > >
> > > >
> >
> >
> >
> >
> > >
>
>
>
>
> >

Charles F. Munat

unread,
Apr 16, 2009, 8:05:39 PM4/16/09
to lif...@googlegroups.com
Dang. Right after I just downloaded and installed the jars... which I
found here:

https://jai.dev.java.net/binary-builds.html#Release_builds

Will check out the geotools repository.

Chas.
Reply all
Reply to author
Forward
0 new messages