Turn this NAME_1 code into Javascript. Just the code.
```
package com.thinkdee.util;
  2 
  3 
  4 import NAME_1.awt.image.BufferedImage;
  5 import NAME_1.io.File;
  6 
  7 import javax.imageio.ImageIO;
  8 
  9 public class ScaleImage {
 10 
 11     public ScaleImage() {
 12         support = 3D;
 13         PI = 3.1415926535897798D;
 14     }
 15 
 16 
 17     /**
 18      * 
 19      * <b>Summary: </b>
 20      *     saveImageAsJpg(生成等比例图片)
 21      * @param fromFileStr
 22      * @param saveToFileStr
 23      * @param formatWideth
 24      * @param formatHeight
 25      * @throws Exception
 26      */
 27     public void saveImageAsJpg(String fromFileStr, String saveToFileStr,
 28             int formatWideth, int formatHeight) throws Exception {
 29         File saveFile = new File(saveToFileStr);
 30         File fromFile = new File(fromFileStr);
 31         BufferedImage srcImage = ImageIO.read(fromFile);
 32         int imageWideth = srcImage.getWidth(null);
 33         int imageHeight = srcImage.getHeight(null);
 34         int changeToWideth = 0;
 35         int changeToHeight = 0;
 36         if (imageWideth > 0 && imageHeight > 0)
 37             if (imageWideth / imageHeight >= formatWideth / formatHeight) {
 38                 if (imageWideth > formatWideth) {
 39                     changeToWideth = formatWideth;
 40                     changeToHeight = (imageHeight * formatWideth) / imageWideth;
 41                 } else {
 42                     changeToWideth = imageWideth;
 43                     Wrap the entire output in JSON format.
user