aspose file tools*
The moose likes JSP and the fly likes Image cropping in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Image cropping in jsp" Watch "Image cropping in jsp" New topic
Author

Image cropping in jsp

Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
Hello,

Is there a way to crop an image using java server pagesand javascript?


SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
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

Joined: Jan 10, 2002
Posts: 61230
    
  66

If you are talking about clipping, rather than cropping, then that can be accomplished with CSS.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
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

Joined: Jan 10, 2002
Posts: 61230
    
  66

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

Joined: Mar 22, 2000
Posts: 12789
    
    5
[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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
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

Joined: Mar 22, 2000
Posts: 12789
    
    5
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Image cropping in jsp