Posts

Showing posts from June, 2017

Sample Code For Generating Thumb in java

This is simple way of creating a 100 X 100 thumbnail without any stretch or skew in image. private void createThumbOfImage ( String filePath , String outputFile ){ try { BufferedImage sourceImage = ImageIO . read ( new File ( filePath )); int width = sourceImage . getWidth (); int height = sourceImage . getHeight (); if ( width > height ){ float extraSize = height - 100 ; float percentHight = ( extraSize / height )* 100 ; float percentWidth = width - (( width / 100 )* percentHight ); BufferedImage img = new BufferedImage (( int ) percentWidth , 100 , BufferedImage . TYPE_INT_RGB ); Image scaledImage = sourceImage . getScaledInstance (( int ) percentWidth , 100 , Image . SCALE_SMOOTH ); img . createGraphics (). drawImage ( scaledImage , 0 , 0 , null ); BufferedImage img2 = new BufferedImage ( 100 , 100 , Buffe