aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Beginner at Image manipulation... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Beginner at Image manipulation..." Watch "Beginner at Image manipulation..." New topic
Author

Beginner at Image manipulation...

mike smith-croteau
Greenhorn

Joined: Sep 10, 2009
Posts: 4

Hi all..

I wanted to see if I could get some direction on Image manipulation. I have experience in handling uploading of files and even saving to disk but have no experience in manipulating an image besides using Grails plugin called ImageTools (uses JAI) which basically does all the work for me. I am really weak in this area and hope to get some direction on a few questions..

1. Is it better to save the file to file system on the webserver and the url to the database or is it better to save the image as a byte array in the database? Industry standard? Performance benefits when served?

2. What is the Java standard for handing Images and manipulating them without affecting their quality. For instance if I wanted to be able to upload an image, then resize and crop it to be used as a thumbnail... where do I need to go to learn the BEST way of doing this? Like I mentioned, I play around with Grails, its awesome... the plugin I used is basic and I want to have complete control over this process without affecting quality.

Thanks in advance for any direction.

Mike

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8910
    
    8

mike smith-croteau wrote:1. Is it better to save the file to file system on the webserver and the url to the database or is it better to save the image as a byte array in the database? Industry standard? Performance benefits when served?


I don't know about "industry standard", but in my mind, storing large amounts of binary data in a database intended for relational data doesn't make sense. The file system offers features which allow one to duplicate some database features, for example, creating a directory for a user's uploaded images with his user id. The user id is then the "foreign key" which you can use to look up the data at a later time. One can also store metadata about the image in property files (i.e. a title or caption for the image).
As for your other questions, let's move the conversation over to the GUI forum.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
mike smith-croteau
Greenhorn

Joined: Sep 10, 2009
Posts: 4
Thanks! I have saved to file system in previous applications and seems to be a good way to do it. I was able to create directories specific to users or other defining characteristics which made managing manually easy as well too. I wasnt sure about saving to database but every now and then I come across a development article which shows saving image as byte array... so always left me wondering if there was a performance advantage or something. Do you know of any advantages to saving to database?

Thanks again. BTW, I was google searching for wrong terms as far as image resizing etc.... found some good articles already.

http://www.componenthouse.com/article-20/page2

which led me here:

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

if anyone has any others.. would love to see.

Viva!
Mike
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8910
    
    8

mike smith-croteau wrote: I wasnt sure about saving to database but every now and then I come across a development article which shows saving image as byte array...


Development articles are often demonstrating useful functionality (storing binary data in a database) at the expense of Best Practices (do we REALLY want to do that?).

mike smith-croteau wrote:
so always left me wondering if there was a performance advantage or something. Do you know of any advantages to saving to database?


I have not done any benchmarking, so take my opinion for what you paid for it: if one loads a file from the file system, the overhead is finding where the file is opening it and reading it. If one loads from the database, there is the overhead of making or getting a database connection, creating and executing a query, locating the image in a table (which is usually stored on disk), reading it into memory if necessary and transferring it across the database connection. In my mind, file system wins.
There would have to be some very important requirement to get me to store an image in a database (associating metadata with the image that would be too complex for a property file, for example). And even then, I'd probably store the metadata in the database and the image on the filesystem.
mike smith-croteau
Greenhorn

Joined: Sep 10, 2009
Posts: 4

Joe Ess wrote:
I have not done any benchmarking, so take my opinion for what you paid for it: if one loads a file from the file system, the overhead is finding where the file is opening it and reading it. If one loads from the database, there is the overhead of making or getting a database connection, creating and executing a query, locating the image in a table (which is usually stored on disk), reading it into memory if necessary and transferring it across the database connection. In my mind, file system wins.
There would have to be some very important requirement to get me to store an image in a database (associating metadata with the image that would be too complex for a property file, for example). And even then, I'd probably store the metadata in the database and the image on the filesystem.


Awesome explanation! Thanks Joe! Thinking about it this way makes so much sense.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8910
    
    8

 
 
subject: Beginner at Image manipulation...