Posts

Showing posts from August, 2011

Image resizing in Java

Image resizing to a ration of standard size (For Ex: 1024x800   to 800x600) public void  resizeFile(File original,  int width, int height){                 int newWidth=0;                 int newHeight=0;                 BufferedImage bufferedImage = ImageIO.read(original);                       int orginalWidth=bufferedImage.getWidth();                 int orginalHeight=bufferedImage.getHeight();                 float ratioWidth= (float)orginalWidth/(float)width;                 float ratioHeight=(float)orginalHeight/(float)height;                 if(ratioWidth>ratioHeight){                     newWidth=width;                     newHeight= Math.round(orginalHeight/ratioWidth);                 }else{                     newWidth= Math.round(orginalWidth/ratioHeight);                     newHeight=height;                 } // Now use these new newWidth and newHeight to write resized file........ -------- ------- }

trim() function Java Script

Use these function in Java Script body : ---------------------------------------------------------------------------------------------------- function trim(stringToTrim) {     return stringToTrim.replace(/^\s+|\s+$/g,""); } function TestTrimString(){      var testString="  Hello!  "     document.write("String before  triming:" + testString );       document.write("String after     triming:" + trim(testString) ); } ------------------------------------------------------------------------------------------------------