Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image cropping in jsp

 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is there a way to crop an image using java server pagesand javascript?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP and Javascript can only control display of images by the browser.

If you are talking about creating a new image by cropping an existing one, Java Media Framework tools can do that, but not in JSP.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are talking about clipping, rather than cropping, then that can be accomplished with CSS.
 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to provide an option where the user can crop from the existing image displayed in a jsp file and save that cropped file
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not something you can do with JSP technology. How are you planning to allow the user to specify the cropping rectangle? You'll need to give us a much more detailed description of your requirements before we can try to point you in the right direction.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[enter picky teacher mode]
the existing image displayed in a jsp file


If you don't state problems correctly, you will always make errors. Images are displayed by the browser based on HTML markup and user interaction. It does not matter whether a .jsp page or a servlet or a static file generated the markup. In fact, with a new and ill-defined requirement, starting with static pages will be easiest.
[exit picky teacher mode]

Bill
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are basically 2 ways I see of doing this. Neither one is particularly JSP oriented.

1) Use a JavaScript vector drawing library to allow the user to draw the clipping area. Submit the relative location and size of the clipping area to the server, and let the server-side application handle the image cropping using JAI and/or ImageIO and save the cropped image. This is probably a fairly tough application to write as you have all kinds of scaling issues to contend with. But if you get it right then it could produce a nice web-based UI for your tool.

2) Use a client-side application such as an Applet or a Web Start application to download the image to the client, allow the client to manipulate the image as they need to, then submit it back to the server. One of the benefits of this approach is that there are probably tools already built for you if you just search for them.
 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i have an idea for this issue. please tell me will this work.

As the user clicks on drags an area on the real image, i am using css to get that position and size and send it to the servlet using ajax where the image cropping is done and the file is saved.

the server return the file name and i am using that value to change the image in the jsp page.

This way when the user drags on the image for almost each pixel i have to send the request to the servlet, do the cropping, save the file and display that file to the user.

Will the server slow down because of so many write operations?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will the server slow down because of so many write operations?


Absolutely! Everything will slow to a crawl - even a windows desktop application has a hard time keeping up with mouse movement on a pixel by pixel basis, adding a request/response cycle would be disasterous.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic