You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jeff LaMarche <je...@mac.com> on 2005/02/09 14:47:05 UTC
Thumbnailing...
In a tapestry app I'm working on, I allow users to upload images. I
then create a thumbnail of the image using a utility class I've
written. I've searched online for other pure Java thumbnail solutions,
and they all seem to use the same approach that I use.
The problem with these approaches is that the default Toolkit can
create an Image from a file, but not (seemingly) a BufferedImage.
Therefore, I need to create an Image then create a Buffered Image from
that Image. I then need to draw the image to a second (smaller)
BufferedImage. The final step is to JPEG encode the image, which
requires a second conversion from the BufferedImage to a Graphics2D.
The end-result is that this process has a memory footprint (I'm
estimating from watching it run) of over three times the uncompressed
image size.
Is there any way to cut out one or all of these image format
conversions? I had considered using a System.exec call to ImageMagick's
identify and convert, which I assumed would be more resource efficient,
and at very least, would take the memory hit out of the JVM, but it's
not clear if I'm going to be able to get ImageMagick installed on the
production box, so I've tabled that idea for now, and would prefer a
more resource-efficient pure Java solution.
If anyone can help, it would be greatly appreciated.
Thanks,
Jeff
Re: Help Needed: Can't find Adaptor
Posted by sales <sa...@digiatlas.net>.
Thanks - that was exactly the problem. How one can fall for the simplest
things sometimes...
cheers,
dd
Jonathan Millett wrote:
> Does your ObjectStructureName class implement Serializable?
>
> Jon
>
> sales wrote:
>
>> Could not find an adaptor for class
>> dae.web.wentities.ObjectStructureName.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Help Needed: Can't find Adaptor
Posted by Jonathan Millett <jo...@millett.net>.
Does your ObjectStructureName class implement Serializable?
Jon
sales wrote:
> Could not find an adaptor for class
> dae.web.wentities.ObjectStructureName.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Help Needed: Can't find Adaptor
Posted by sales <sa...@digiatlas.net>.
Hello,
I'm a bit stumped on this one:
Could not find an adaptor for class dae.web.wentities.ObjectStructureName.
Stack Trace:
org.apache.tapestry.util.AdaptorRegistry.searchForAdaptor(AdaptorRegistry.java:263)
org.apache.tapestry.util.AdaptorRegistry.getAdaptor(AdaptorRegistry.java:152)
org.apache.tapestry.util.io.DataSqueezer.squeeze(DataSqueezer.java:170)
org.apache.tapestry.util.io.DataSqueezer.squeeze(DataSqueezer.java:192)
org.apache.tapestry.engine.AbstractService.constructLink(AbstractService.java:72)
...
----------------
The code causing the problem:
<h2>Contents</h2>
<table jwcid="table@contrib:Table" width="100%"
source="ognl:objectResults"
rowsClass="ognl:beans.evenOdd.next"
columns="!shortDesc, !objectID"
pageSize=200>
<span jwcid="objectIDColumnHeader@Block"> </span>
<span jwcid="objectIDColumnValue@Block">
<a href="#" jwcid="@DirectLink"
parameters="ognl:components.table.tableRow" <<<<<<<< problem
listener="ognl:listeners.viewObject">Details</a>
</span>
</table>
Yet if I put:
parameters="ognl:components.table.tableRow.objectID"
(getObjectID() being one of the methods of ObjectStructureName) it works
fine. However, I want to pass the whole object as I need several of its
attributes.
What have I done wrong?
dd (stumped)
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by phillip rhodes <rh...@yahoo.com>.
check out poor man's image library.
It's opensource simple library that allows one to do
many image related tasks.
apache license
http://www.mullassery.com/downloads/
--- Jean-Yves Sironneau <jy...@fr.st> wrote:
> I'am using this to create my thumbnails, don't know
> if that can help :
>
> public void makeSmallContent(IContent content) {
> if
> (IContent.MIME_JPEG.equals(content.getMimeType())) {
> try {
> BufferedImage imageSource =
> ImageIO.read(new
> ByteArrayInputStream(content
> .getPrimaryContent()));
> BufferedImage thumbnail =
> thumbnailnize(imageSource,
> thumbnailSize);
> ByteArrayOutputStream out = new
> ByteArrayOutputStream();
> ImageIO.write(thumbnail,
> content.getMimeType(), out);
>
> content.setSmallContent(out.toByteArray());
> } catch (ImageFormatException e) {
> _log.error(e);
> } catch (IOException e) {
> _log.error(e);
> }
> }
> }
>
>
> /**
> * Scale a given image.
> *
> * @param source
> * the source image
> * @param scaleValue
> * the scale factor.
> * @return the transformed image.
> *
> */
> public static BufferedImage scale(BufferedImage
> source, double scaleValue)
> {
> AffineTransform tx = new AffineTransform();
> tx.scale(scaleValue, scaleValue);
> AffineTransformOp op = new
> AffineTransformOp(tx,
> AffineTransformOp.TYPE_BILINEAR);
> BufferedImage biNew = new
> BufferedImage((int) (source.getWidth() *
> scaleValue),
> (int) (source.getHeight() *
> scaleValue), source.getType());
> return op.filter(source, biNew);
> }
>
> /**
> * Thumbnail creation
> *
> * @param source
> * the source image
> * @param thumbnailMaxSize
> * the maximum size of the thumbnail
> either horizontally or
> vertically
> * @return the thumbnailized image
> *
> */
> public static BufferedImage
> thumbnailnize(BufferedImage source, int
> thumbnailMaxSize) {
> double maxDimension =
> Math.max(source.getWidth(), source.getHeight());
> double scaleValue = thumbnailMaxSize /
> maxDimension;
> return scale(source, scaleValue);
> }
>
>
> On Wednesday 09 February 2005 14:47, Jeff LaMarche
> wrote:
> > In a tapestry app I'm working on, I allow users to
> upload images. I
> > then create a thumbnail of the image using a
> utility class I've
> > written. I've searched online for other pure Java
> thumbnail solutions,
> > and they all seem to use the same approach that I
> use.
> >
> > The problem with these approaches is that the
> default Toolkit can
> > create an Image from a file, but not (seemingly) a
> BufferedImage.
> > Therefore, I need to create an Image then create a
> Buffered Image from
> > that Image. I then need to draw the image to a
> second (smaller)
> > BufferedImage. The final step is to JPEG encode
> the image, which
> > requires a second conversion from the
> BufferedImage to a Graphics2D.
> > The end-result is that this process has a memory
> footprint (I'm
> > estimating from watching it run) of over three
> times the uncompressed
> > image size.
> >
> > Is there any way to cut out one or all of these
> image format
> > conversions? I had considered using a System.exec
> call to ImageMagick's
> > identify and convert, which I assumed would be
> more resource efficient,
> > and at very least, would take the memory hit out
> of the JVM, but it's
> > not clear if I'm going to be able to get
> ImageMagick installed on the
> > production box, so I've tabled that idea for now,
> and would prefer a
> > more resource-efficient pure Java solution.
> >
> > If anyone can help, it would be greatly
> appreciated.
> >
> > Thanks,
> > Jeff
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Jean-Yves Sironneau <jy...@fr.st>.
I'am using this to create my thumbnails, don't know if that can help :
public void makeSmallContent(IContent content) {
if (IContent.MIME_JPEG.equals(content.getMimeType())) {
try {
BufferedImage imageSource = ImageIO.read(new
ByteArrayInputStream(content
.getPrimaryContent()));
BufferedImage thumbnail = thumbnailnize(imageSource,
thumbnailSize);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(thumbnail, content.getMimeType(), out);
content.setSmallContent(out.toByteArray());
} catch (ImageFormatException e) {
_log.error(e);
} catch (IOException e) {
_log.error(e);
}
}
}
/**
* Scale a given image.
*
* @param source
* the source image
* @param scaleValue
* the scale factor.
* @return the transformed image.
*
*/
public static BufferedImage scale(BufferedImage source, double scaleValue)
{
AffineTransform tx = new AffineTransform();
tx.scale(scaleValue, scaleValue);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_BILINEAR);
BufferedImage biNew = new BufferedImage((int) (source.getWidth() *
scaleValue),
(int) (source.getHeight() * scaleValue), source.getType());
return op.filter(source, biNew);
}
/**
* Thumbnail creation
*
* @param source
* the source image
* @param thumbnailMaxSize
* the maximum size of the thumbnail either horizontally or
vertically
* @return the thumbnailized image
*
*/
public static BufferedImage thumbnailnize(BufferedImage source, int
thumbnailMaxSize) {
double maxDimension = Math.max(source.getWidth(), source.getHeight());
double scaleValue = thumbnailMaxSize / maxDimension;
return scale(source, scaleValue);
}
On Wednesday 09 February 2005 14:47, Jeff LaMarche wrote:
> In a tapestry app I'm working on, I allow users to upload images. I
> then create a thumbnail of the image using a utility class I've
> written. I've searched online for other pure Java thumbnail solutions,
> and they all seem to use the same approach that I use.
>
> The problem with these approaches is that the default Toolkit can
> create an Image from a file, but not (seemingly) a BufferedImage.
> Therefore, I need to create an Image then create a Buffered Image from
> that Image. I then need to draw the image to a second (smaller)
> BufferedImage. The final step is to JPEG encode the image, which
> requires a second conversion from the BufferedImage to a Graphics2D.
> The end-result is that this process has a memory footprint (I'm
> estimating from watching it run) of over three times the uncompressed
> image size.
>
> Is there any way to cut out one or all of these image format
> conversions? I had considered using a System.exec call to ImageMagick's
> identify and convert, which I assumed would be more resource efficient,
> and at very least, would take the memory hit out of the JVM, but it's
> not clear if I'm going to be able to get ImageMagick installed on the
> production box, so I've tabled that idea for now, and would prefer a
> more resource-efficient pure Java solution.
>
> If anyone can help, it would be greatly appreciated.
>
> Thanks,
> Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Barry Books <bf...@mac.com>.
I've done this several ways and I don't think System is the right way to do this, but you don't want this in the main webserver either. The problem is if your JVM is very large fork/exec can be expensive (or not possible) and lots of requests equals lots of processes. Putting this function in the main webserver JVM will make your site crash from time to time. I finally settled on running a separate Tomcat with a servlet just for this purpose. That way you can write all the code in Java using the imaging library. The main application just passes the images along to the image server via http.
You can have multiple backend image servers if needed, you can restart them when they fail and you can control how much memory and cpu they are allowed to have or even have dedicated boxes. Instead of creating the thumbnails on upload I created them when requested and cached the result. Either way would work but I also had a process that deleted any thumbnails over 1 month old. That way I did not waste storage on images no one looked at.
I had over 500 gig of images and this way worked for me. None of the other ways did.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Holger Hoffstaette <ho...@wizards.de>.
On Wed, 09 Feb 2005 08:47:05 -0500, Jeff LaMarche wrote:
> In a tapestry app I'm working on, I allow users to upload images. I then
That way lies madness.
> a memory footprint (I'm estimating from watching it run) of over three
> times the uncompressed image size.
Not to mention the nice DenialOfService attacks that I can drive against
your VM by uploading a teeny-weeny 10000*10000 pixel image compressed to
seemingly nothing.
You really, really want to take that out of the VM and have an async job
waiting (meta-refresh..please wait..).
> I had considered using a System.exec call to ImageMagick's identify and
> convert, which I assumed would be more resource efficient, and at very
> least, would take the memory hit out of the JVM, but it's not clear if I'm
Exactly, right thinking there. The performance hit by I/O and System.exec
is totally irrelevant unless you have ten thousand users all starting
their conversion job at the same time - in which case you lose anyway.
With the external process you can at least ssh into that SMP cluster.. :-)
> going to be able to get ImageMagick installed on the production box, so
> I've tabled that idea for now, and would prefer a more resource-efficient
> pure Java solution.
There are some imaging libraries around but some of them are GPL and might
therefore not be suitable for you (e.g. jiu.sourceforge.net which looks
great, API-wise but is GPL). Cyril suggested JAI which will make you kill
all your neighbors and then yourself, API-wise. It's fast but AFAIK only
if you use the native helper dll/shared library.
The JMagick ImageMagick JNI interface is just plain evil as well. I
thought about writing a good one but have no project for that.
What I do have is a "typesafe" wrapper for ImageMagick execution jobs
(i.e. no Strings in your sourcecode) but it's not ready for general
consumption or even widely tested; it kind of works but might need
tweaking. Scaling/thumbnailing is the most obvious use case and does work
reliably on Unix and Windows. :)
If you want to have a look (it's an eclipse project ready-to-run) send me
a private email.
-h
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Jeff LaMarche <je...@mac.com>.
On Feb 9, 2005, at 8:55 AM, Cyril Godefroy wrote:
> Have a look at the JAI (java advanced imaging) extension. It should be
> possible to do such thing with it. With native libs on windows,
> solaris, linux and mac.
I haven't.. this might be a good option, however I'll have to
double-check that the linux version of JAI can be used on FreeBSD,
which the production box is running. Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Cyril Godefroy <cy...@ecomposite.fr>.
I advise you not to use Image Magick in a javamagick away as there is a
memory leak. We used it before and had to restart the app every 100
tratments or so...
JAI is fine in that regard: once you've maxed out on the memory
footprint, you don't leak anymmore ;-)
I don't know about a system exec way, but it surely would be better.
Have a look at the JAI (java advanced imaging) extension. It should be
possible to do such thing with it. With native libs on windows,
solaris, linux and mac.
Cyril
On Feb 9, 2005, at 2:47 PM, Jeff LaMarche wrote:
> In a tapestry app I'm working on, I allow users to upload images. I
> then create a thumbnail of the image using a utility class I've
> written. I've searched online for other pure Java thumbnail solutions,
> and they all seem to use the same approach that I use.
>
> The problem with these approaches is that the default Toolkit can
> create an Image from a file, but not (seemingly) a BufferedImage.
> Therefore, I need to create an Image then create a Buffered Image from
> that Image. I then need to draw the image to a second (smaller)
> BufferedImage. The final step is to JPEG encode the image, which
> requires a second conversion from the BufferedImage to a Graphics2D.
> The end-result is that this process has a memory footprint (I'm
> estimating from watching it run) of over three times the uncompressed
> image size.
>
> Is there any way to cut out one or all of these image format
> conversions? I had considered using a System.exec call to
> ImageMagick's identify and convert, which I assumed would be more
> resource efficient, and at very least, would take the memory hit out
> of the JVM, but it's not clear if I'm going to be able to get
> ImageMagick installed on the production box, so I've tabled that idea
> for now, and would prefer a more resource-efficient pure Java
> solution.
>
> If anyone can help, it would be greatly appreciated.
>
> Thanks,
> Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Jeff LaMarche <je...@mac.com>.
On Feb 9, 2005, at 9:18 AM, Gus Heck wrote:
> Have you checked that the Image you get isn't already a BufferedImage?
> In some cases Image must be returned for backwards compatability
> reasons, but the object returned is actually a BufferedImage... I know
> this is the case for some of the methods in the Graphics class. Try
> casting it, see what happens, if it works that saves you one step.
Unfortunately, I tried this, and got ClassCastExceptions. I could add
code to determine whether the Image is a BufferedImage, but it doesn't
seem like it would help things in most cases. It might be worth trying
though, to buy me a little bit of memory back. Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Gus Heck <gu...@gmail.com>.
Have you checked that the Image you get isn't already a BufferedImage?
In some cases Image must be returned for backwards compatability
reasons, but the object returned is actually a BufferedImage... I know
this is the case for some of the methods in the Graphics class. Try
casting it, see what happens, if it works that saves you one step.
-Gus
On Wed, 9 Feb 2005 08:47:05 -0500, Jeff LaMarche <je...@mac.com> wrote:
> In a tapestry app I'm working on, I allow users to upload images. I
> then create a thumbnail of the image using a utility class I've
> written. I've searched online for other pure Java thumbnail solutions,
> and they all seem to use the same approach that I use.
>
> The problem with these approaches is that the default Toolkit can
> create an Image from a file, but not (seemingly) a BufferedImage.
> Therefore, I need to create an Image then create a Buffered Image from
> that Image. I then need to draw the image to a second (smaller)
> BufferedImage. The final step is to JPEG encode the image, which
> requires a second conversion from the BufferedImage to a Graphics2D.
> The end-result is that this process has a memory footprint (I'm
> estimating from watching it run) of over three times the uncompressed
> image size.
>
> Is there any way to cut out one or all of these image format
> conversions? I had considered using a System.exec call to ImageMagick's
> identify and convert, which I assumed would be more resource efficient,
> and at very least, would take the memory hit out of the JVM, but it's
> not clear if I'm going to be able to get ImageMagick installed on the
> production box, so I've tabled that idea for now, and would prefer a
> more resource-efficient pure Java solution.
>
> If anyone can help, it would be greatly appreciated.
>
> Thanks,
> Jeff
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Jeff LaMarche <je...@mac.com>.
On Feb 9, 2005, at 8:22 PM, Kent Tong wrote:
> There is working sample code for exactly this purpose at
> http://www.geocities.com/marcoschmidt.geo/java-save-jpeg-thumbnail.html
Yeah, if you look at it, though, the author does exactly the same
process I described: Image -> BufferedImage -> Graphic2D -> JPEG file,
so it won't perform any better than what I've got now. =-(
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Jeff LaMarche <je...@mac.com>.
On Feb 9, 2005, at 8:39 PM, Brett Randall wrote:
> AffineTransformOp op = new AffineTransformOp(
> AffineTransform.getScaleInstance(factor, factor), null);
>
> return op.filter(image, null);
Hmmm... using Buffered image = ImageIO.read() seems to have helped, or
at least didn't hurt. On the other hand, using AffineTransformOp to
scale the image actually had a considerably larger memory footprint
than what I had been doing. Odd.
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Jeff LaMarche <je...@mac.com>.
On Feb 9, 2005, at 8:39 PM, Brett Randall wrote:
> AffineTransformOp op = new AffineTransformOp(
> AffineTransform.getScaleInstance(factor, factor), null);
>
> return op.filter(image, null);
That, combined with javax.imageio, appears to be just what I'm looking
for. Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Brett Randall <ja...@gmail.com>.
Andreas Andreou wrote:
> take a look at
> javax.imageio.ImageIO
> and try
> BufferedImage image = ImageIO.read(fileName);
and then, if you don't require anything special, how about:
.....
AffineTransformOp op = new AffineTransformOp(
AffineTransform.getScaleInstance(factor, factor), null);
return op.filter(image, null);
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Kent Tong <ke...@cpttm.org.mo>.
Jeff LaMarche <jeff_lamarche <at> mac.com> writes:
>
> In a tapestry app I'm working on, I allow users to upload images. I
> then create a thumbnail of the image using a utility class I've
> written. I've searched online for other pure Java thumbnail solutions,
> and they all seem to use the same approach that I use.
There is working sample code for exactly this purpose at
http://www.geocities.com/marcoschmidt.geo/java-save-jpeg-thumbnail.html
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Thumbnailing...
Posted by Andreas Andreou <an...@di.uoa.gr>.
take a look at
javax.imageio.ImageIO
and try
BufferedImage image = ImageIO.read(fileName);
Jeff LaMarche wrote:
> In a tapestry app I'm working on, I allow users to upload images. I
> then create a thumbnail of the image using a utility class I've
> written. I've searched online for other pure Java thumbnail solutions,
> and they all seem to use the same approach that I use.
>
> The problem with these approaches is that the default Toolkit can
> create an Image from a file, but not (seemingly) a BufferedImage.
> Therefore, I need to create an Image then create a Buffered Image from
> that Image. I then need to draw the image to a second (smaller)
> BufferedImage. The final step is to JPEG encode the image, which
> requires a second conversion from the BufferedImage to a Graphics2D.
> The end-result is that this process has a memory footprint (I'm
> estimating from watching it run) of over three times the uncompressed
> image size.
>
> Is there any way to cut out one or all of these image format
> conversions? I had considered using a System.exec call to
> ImageMagick's identify and convert, which I assumed would be more
> resource efficient, and at very least, would take the memory hit out
> of the JVM, but it's not clear if I'm going to be able to get
> ImageMagick installed on the production box, so I've tabled that idea
> for now, and would prefer a more resource-efficient pure Java solution.
>
> If anyone can help, it would be greatly appreciated.
>
> Thanks,
> Jeff
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org