示例#1
0
  static {
    if (graphicsMagickPath == null) {
      String osName = System.getProperty("os.name").toLowerCase();
      if (osName.indexOf("windows") >= 0) {
        String pathVariable = System.getenv("Path");
        if (pathVariable != null) {
          String[] paths = pathVariable.split(";");
          for (String path : paths) {
            File gmFile = new File(path.trim() + "/gm.exe");
            File gmdisplayFile = new File(path.trim() + "/gmdisplay.exe");
            if (gmFile.exists() && gmdisplayFile.exists()) {
              graphicsMagickPath = path.trim();
              break;
            }
          }
        }
      }
    }

    if (imageMagickPath == null) {
      String osName = System.getProperty("os.name").toLowerCase();
      if (osName.indexOf("windows") >= 0) {
        String pathVariable = System.getenv("Path");
        if (pathVariable != null) {
          String[] paths = pathVariable.split(";");
          for (String path : paths) {
            File convertFile = new File(path.trim() + "/convert.exe");
            File compositeFile = new File(path.trim() + "/composite.exe");
            if (convertFile.exists() && compositeFile.exists()) {
              imageMagickPath = path.trim();
              break;
            }
          }
        }
      }
    }

    if (type == Type.auto) {
      try {
        IMOperation operation = new IMOperation();
        operation.version();
        IdentifyCmd identifyCmd = new IdentifyCmd(true);
        if (graphicsMagickPath != null) {
          identifyCmd.setSearchPath(graphicsMagickPath);
        }
        identifyCmd.run(operation);
        type = Type.graphicsMagick;
      } catch (Throwable e1) {
        try {
          IMOperation operation = new IMOperation();
          operation.version();
          IdentifyCmd identifyCmd = new IdentifyCmd(false);
          identifyCmd.run(operation);
          if (imageMagickPath != null) {
            identifyCmd.setSearchPath(imageMagickPath);
          }
          type = Type.imageMagick;
        } catch (Throwable e2) {
          type = Type.jdk;
        }
      }
    }
  }