Load, create, and save image as thumbnail

Duke Dollars to earn ... :)
Hi,
I want to create a very simple jsp page where I can upload an image through the filechooser and display the uploaded image on the page. When hitting a save button I want to save the image as a thumbnail on the webserver.
If anyone has suggestions on smooth, clever code that will do this for me, it will be highly appreciated. And answers with code will be awarded.
Regards
Malin

see if this can help you out...
import com.sun.image.codec.jpeg.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
public class Thumbnail {
public static void main(String[] args) throws Exception {
if (args.length != 5) {
System.err.println("Usage: java Thumbnail inputFileName " +
"outputFileName width height quality"); //quality 0-100
System.exit(1);
// load image from INFILE
Image image = Toolkit.getDefaultToolkit().getImage(args[0]);
MediaTracker mediaTracker = new MediaTracker(new Frame());
mediaTracker.addImage(image, 0);
mediaTracker.waitForID(0);
// determine thumbnail size from WIDTH and HEIGHT
int thumbWidth = Integer.parseInt(args[2]);
int thumbHeight = Integer.parseInt(args[3]);
double thumbRatio = (double)thumbWidth / (double)thumbHeight;
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
double imageRatio = (double)imageWidth / (double)imageHeight;
if (thumbRatio < imageRatio) {
thumbHeight = (int)(thumbWidth / imageRatio);
} else {
thumbWidth = (int)(thumbHeight * imageRatio);
// draw original image to thumbnail image object and
// scale it to the new size on-the-fly
BufferedImage thumbImage = new BufferedImage(thumbWidth,
thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
// save thumbnail image to OUTFILE
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(args[1]));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.
getDefaultJPEGEncodeParam(thumbImage);
int quality = Integer.parseInt(args[4]);
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float)quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
System.out.println("Done.");
System.exit(0);

Similar Messages

  • Using Fx as a library to create and save image

    Hi,
    I wrote an FX desktop app to create an vector image and saved as png. I would like to use this FX program like a library.
    For example, to use it in glassfish managed bean to generate image and saved to a directory. Can this be done? I am wondering how to call FX, pass in parameters, generate and safe the graph WITHOUT firing up as a desktop app.
    Just want to use FX to create an image in buffer image, save and return me a link to that image. Java calling javxFX to produced the required image.
    I already wrote a working FX. Hopefully it works without having to write another apps to do the job.
    Appreciate any help or advise.

    This feature is [url http://javafx-jira.kenai.com/browse/RT-14038]planned, but not yet publicly supported. It appears to have been scheduled for Lombard, the version after 2.0. If you need this feature now, there is still a hack available: Image conversion between AWT and FX

  • Part 04 - Creating and Importing Images | Classroom: Basic Site Layout and Navigation in Dreamweaver | Adobe TV

    Learn how to create and prepare images to incorporate into your website design.  Save them in web friendly JPG or PNG formats while maintaining a good balance between quality and small file size. Import them into Dreamweaver and make some initial adjustments to layout and alignment.
    http://adobe.ly/zL64GN

    This third lesson needs to be updated. The "ALIGN" buttons in Properties are now missing in CS6 because it's obsolete in HTML now...

  • How to Create and Save a workbook on Enterprise Portal

    Hi,
    I need to find out how I can create and save a workbook (for a query) in Enterprise portal. Can we save a work book and run it in the same format?
    Thanks

    Hi,
    refer below thread
    Re: How do you save the Workbook as View when the workbook do not have quer
    also see sap help
    http://help.sap.com/saphelp_nw04/helpdata/en/4d/f3fa40badbf36fe10000000a1550b0/frameset.htm
    Thanks

  • How to create and save a file in flex web application ?

    Hi,
          I want to create and save a file form flex web application. Is it possible ?
    I have done some googling and found that its only possible through file referece, which needs some serverside implementation be called.
    Is it not possible with file reference to create and save file directly ?
    Can any one suggest how to over come this.
    Thanks in advance.

    Alex,
    code written with the Flex Builder 3 libraries will certainly run in Flash Player 10. However, what you need is not so much the capabilities of FP10 but the library functionalities of the Flex 4 package. And I think that Flex 4 code will only run in FP10 and not 9 (but haven't tested this as at work we have not yet been permitted to upgrade, so there is not a lot of point going for Flex 4!).
    Richard

  • SAP Query (SQ01) - create and save queryies

    Hi Expert;
    We wanted to implement SAP query reporting (SQ01) tool, and already developed custom HR infoset and user groups and transported to QAS.  We experienced the problem that we can not directly "save" any queries in SQ01. We pretty much have the client opened up and set at "Changes without automatic recording".  But keep getting a "transport object create" dialog upon "save" query.  But in Adhoc (PQAH), we don't encounter same problem.    We wanted our users be able to create and save any queries directly without creating any local objects. Is there another setting that needs to be set? 
    Thanks for any information that you can provide.  Points will be awarded.
    Helen

    Hello Helen,
    in SQ01 you can save queries like in HR Ad Hoc Query (or Infoset query as it is called outside HR).
    However this is only possible in the "Standard Area" not in the "Global Area". However as Ad Hoc Query is based on the SQ0x basics it only hides this effect.
    If you are doing HR specifics you should consider the documetnation on the special HR switches:
    http://service.sap.com/~form/sapnet?_SHORTKEY=01200252310000076208&
    In general if you are new to the topic you should consider the courses BC407 for Query Basics and HR580 for reporting in HR.
    Also to get a feeling for the different types of reporting with the InfoSet Query you can look at the following documentation:
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/a8/2e7237a323427ee10000009b38f8cf/frameset.htm
    HR Reporting Tools -> Sap Query -> InfoSet Query -> Calling InfoSet Query.
    Or you can book a special training if you need a contact let me know your email adress
    Best regards,
    Michael

  • Is it possible to create and save a .PDF without any compression to the resulting .PDF?

    I need an uncompressed file so I can use the resulting PDF to do a find/replace. Can't do it with compression.
    Thanks
    JDRHC1115

    Dave,
    Thanks for the reply. Of all the suggestions I've received this seemed to
    be most promising. I gave it a try and the problem is that when I attempt
    to save as optimized a message box pops up and says I have to save my
    document first. Low and behold when I save it, compression occurs. Even
    when I select the options you suggest I'm left with a compressed document.
    I'm using Acrobat Pro X
    Jeff
    From:   Dave Merchant <[email protected]>
    To:     Jeff Ross <[email protected]>
    Date:   01/06/2011 09:35 AM
    Subject:        Is it possible to create and save a .PDF
    without any compression to the resulting .PDF?
    You don't want the UncompressPDF plugin - that's designed to split out the
    COS objects but doesn't remove the Flate encoding (plus if you've never
    compiled a plugin before, it's not really the time to learn).
    Instead, simply save your PDF file using the PDF (Optimized) file type,
    click the Settings button and under "Clean Up" - "Object compression
    options", choose "Remove compression". Turn everything else off if you
    want to retain the PDF content exactly as it was before.
    Your document-level scripts will then be in the file as plain text.

  • Create and save a .pdf file

    Afternoon!  I am creating a pdf utilizing the cfdocument tag and it works great.  It opens and displays well.  My question is, is there a way to automatically save that generated pdf on the server without opening it?  My end goal is to run a scheduled task every week that creates and saves a pdf automatically.

    <cfdocument format="pdf" orientation="landscape" filename="YourPDFName.pdf" overwrite="yes">
    it will save a copy of the pdf in the same folder as the <cfdocument> is run from, the problem I got is it wond display the pdf at creation time, all that is returned to my screen is the letter "z"
    so may be best to fun the code in a loop and one time add in the filename and overwrite paramaters, if you dont need it displayed, then your gold.
    Craig Wiseman

  • Create and save custom transition

    Hi, I made a custom transition in FCP using video filters and keyframes and would like to save it to be able to use it again. Is there any way in FCP to create and save transitions? What files actually are the transitions included in FCP?

    I did a search and now I know, that the filters and transitions are written in FXScript languge. For those who're interested, there's an official Apple Using FX Script pdf ( http://developer.apple.com/documentation/AppleApplications/Conceptual/Using_FXSc ript/UsingFXScript.pdf ) and a really nice website with FX Script reference - http://www.fxscriptreference.org/ ...

  • Since I refreshed Firefox 36.0.4, "Save page as" and "save image as" are not working (even in Safe mode)

    I refreshed FF 36.0.4 on invite. Since then "save page as " and "save image as" are not working -- no response when clicked.
    In Safe Mode, same problem.
    I serached past forum discussions and found several occurrences, but no convincing response.

    ''afew2 [[#question-1054433|said]]''
    <blockquote>
    I refreshed FF 36.0.4 on invite. Since then "save page as " and "save image as" are not working -- no response when clicked.
    In Safe Mode, same problem.
    I serached past forum discussions and found several occurrences, but no convincing response.
    </blockquote>
    I tried troubleshooting plugins, none appeared to be causing the problem.
    I installed 36.0.1, but no difference. Went back to 36.0.4, still no change.
    I ran a malware check with Malwarebytes, no change.
    A past thread here suggested deleting localstore.rdf, which I tried, no result.
    People have had this problem in the past. No one has any idea of how to fix it?

  • How to create and save playlist using JMF?

    Hello i m new to JMF. Can anyone tell me how to create and save a playlist of media files using JMF.
    also how can i play .DAT files using JMF?
    Does JMF supports AVI,Asf files?

    Hello i m new to JMF. Can anyone tell me how to create and save a playlist of media files using JMF.
    also how can i play .DAT files using JMF?
    Does JMF supports AVI,Asf files?

  • How do you create and save icc profiles using photoshop?

    How do you create and save icc profiles using photoshop?

    You don't. Color profiles require specific measurement hardware and software.
    Mylenium

  • How does APEX create and save new files. What extension does it save in?

    Hi can someone help me with this question?
    How does APEX create and save new files. What extension does it save in?
    Cheers!
    VJ

    It's really too bad we can't see VJ's face when the concept sinks in. This is one of my favorite moments when teaching APEX classes. Most people love it, some people don't. If nothing else it really proves the power and performance of the Oracle database. Each page view can generate 40+ queries, yet on the average system this takes less than .04 seconds.
    Keep in mind there are no undocumented features or "Oracle Internals" that the APEX team uses to achieve this performance, just sound database design. With every feature they add they evaluate how it will be used and design the tables and indexes to most efficiently answer the query. Sometimes this means going against "purist" normalized principals.

  • Acquire and save images at high frame rates

    I am attempting to acquire and save images at a rate of 3000 fps for approximately 100 ms using a JAI 6740GE GigE camera, LabView 2011, and IMAQdx.  I can acquire the images at the necessary rates, but am dropping images when I try to save them.  The current test program I am working with contains a producer loop for acquiring the images, converting them into an array, and putting them into a queue, and a consumer loop to write the arrays to a TDMS file.  Currently I can acquire and save the images at a rate of approximately 1200 fps before I begin losing a few frames.  The code is attached below.  I would appreciate any ideas to be able to save the images without dropping frames.
    Attachments:
    Trigger Image to AVI faster.vi ‏38 KB

    Hi Rox,
    How are you verifying that you are loosing the frames during the saving and not during the acquisition? Are you able to determine where you are dropping frames? Is it at the beginning, the end or randomly? Thank you!
    Regards,
    Kira T

  • My boss cannot create a new subfolder by pressing "new folder" until he's already saved the file to his desktop. A "read only" error appears the first time. Is there a way to create and save to subfolder directly? It's Mavericks/Macbook Pro

    Hi, when my boss wants to save a new file in a new subfolder, he presses "new folder" but cannot create a new one because a “read only” error box appears. Once he saves the file to his Desktop he clicks on “save as” again and then he can create a new subfolder by pressing “new folder.” Is there a way to create and save to a subfolder directly without having to first save somewhere else?

    Your server file handling has nothing, and really nothing to do with Adobe software. If files don't get locked for (over-)writing and/or lose connection to the program opening them, then your server is misconfigured. It's as plain and simple and that. Anything from "known file types"/ file associations not being set correctly, MIME types being botched, crooked user privileges and file permissions, missing Mac server extensions, delayed file writing on the server, generic network timeout issues and what have you. Either way, you have written a longwinded post with no real value since you haven't bothered to provide any proper technical info, most notably about the alleged server. Either way, the only way you can "fix" it is by straightening out your server and network configuration, not some magic switch in Adobe's software.
    Mylenium

Maybe you are looking for

  • ICal Events snap to top of days in Month view?

    When I enter an "Event" in to a calander in the "Month" view,  it always "snaps" to the top of the day's box, irrespective of the *time* of the event. I can drag it, to another position in the day's box, but it always snaps back to the top? i.e., if

  • Dv gray squares blank screen Kona LH final cut pro iTunes

    KONA/AJA conflict with FCP If anyone outputs their system's sound through a KONA LH card and AJA KL breakout box, it causes gray squares and then the video output goes fully blank when outputing via FireWire / DV to a deck. I noticed that this proble

  • JTable, how to highlight cells with tooltips?

    Hello all! Mine problem is descriped in the topic - I though about custom cell renderer but I dont have an Idea how to change background for many other cells in other rows and don't change background in whole columns. Any of You could help?

  • Import a policy file in java 1.5

    Hi: The quesiton I am about to ask might not really relate to java programming...but I have no idea where else I can get help. I am an university student and my school use a online java submission system. In order to hand in my java programs, I need

  • Adobe Creative Suite 6 Design and Web Premium and Adobe CC.

    Hey y'all i have a list of questions that i wanna ask about adobe. I planned to buy Adobe CS6 but not sure yet because of there is an Adobe CC now. 1. Do i need to have Adobe CS6 version first to get Adobe CC? 2. Btw what is Adobe CC? Is that only us