public BufferedImage loadImage(File file){

		int w=PaintPanel.w;
		int h=PaintPanel.h;
		String check=file.getName();

		//if user tries to upload another kind of file ( jpeg,png,jpg ) 
		if(!check.contains(".jpeg") ||  !check.contains(".png") || !check.contains(".jpg") ){
			return null;
		}

		else{
			BufferedImage in=null;
			try {
				in = ImageIO.read(file); //read image from given file

			} catch (IOException e) {
				System.out.println("could not read the image");
			}
			BufferedImage newImage = new BufferedImage(PaintPanel.w,PaintPanel.h, BufferedImage.TYPE_INT_ARGB);

			Graphics2D g = newImage.createGraphics();

			//if image is bigger than canvas fit it into canvas 
			if(newImage.getWidth()>w|| newImage.getHeight()>h){  
				w=newImage.getWidth();
				h=newImage.getHeight(); 
			}

			g.drawImage(in,0,0,w,h,null); //make image smaller
			g.dispose();
			update();
			return newImage;
		}
	}