Ignore:
Timestamp:
2020-02-14T23:03:21+13:00 (4 years ago)
Author:
ak19
Message:

Investigated some other options for screen capturing and Google chrome does the best job of the installed applications so far.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java

    r33925 r33926  
    159159    private final File outputFolder;
    160160
    161 
     161    // Used to create screenshots
     162    private final String MONITOR_RESOLUTION = "1920,1080"; // format: "x,y"
    162163   
    163164    public CountryCodeCountsMapData(String countryCountsJSONFilename) throws Exception {
     
    645646    // https://stackoverflow.com/questions/49606051/how-to-take-a-screenshot-in-firefox-headless-selenium-in-java
    646647   
    647     // https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode
     648   
     649    String mapURL = this.getAsMapURL();
     650          ///String mapURLescapedForBash = .replace("\"", "\\\"");//.replace("[", "\\[").replace("]", "\\]");
     651
     652    // Testing the geojson.io URL with a simpler polygon. Also doesn't work.
     653    //String mapURL = GEOJSON_MAP_TOOL_URL + DATA_STR + URLEncoder.encode("{\"type\":\"Polygon\",\"coordinates\":[[[-77,37],[-77,38],[-76,38],[-76,37],[-77,37]]]}");
     654   
     655   
     656    File outputFile = new File(outputFolder + File.separator + fileNamePrefix+".png");
     657    String outputFilePath = Utility.getFilePath(outputFile);
     658
     659
     660    // https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode   
    648661    // /path/to/firefox -P my-profile --screenshot test.jpg  https://developer.mozilla.org --window-size=800,1000
    649662    // https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash
    650    
    651     String mapURL = this.getAsMapURL();
    652           ///String mapURLescapedForBash = .replace("\"", "\\\"");//.replace("[", "\\[").replace("]", "\\]");
    653 
    654     // Testing the geojson.io URL with a simpler polygon. Also doesn't work.
    655     //String mapURL = GEOJSON_MAP_TOOL_URL + DATA_STR + URLEncoder.encode("{\"type\":\"Polygon\",\"coordinates\":[[[-77,37],[-77,38],[-76,38],[-76,37],[-77,37]]]}");
    656    
    657    
    658     File outputFile = new File(outputFolder + File.separator + fileNamePrefix+".png");
    659     String outputFilePath = Utility.getFilePath(outputFile);
    660 
     663    // FIREFOX doesn't work as expected: screenshot appears to happen too fast, before json completely loaded
     664
     665    /*
    661666    String[] cmdArgs = {
    662667        "firefox",
    663668        "--screenshot",
    664669        outputFilePath,
     670        //"--delay=5", // only in firefox console?
     671        "--window-size="+MONITOR_RESOLUTION,
    665672        mapURL //mapURLescapedForBash //"'" + mapURL + "'"
    666673    };
    667 
     674    */
     675   
     676    // Trying CHROME - background world map is faded at times or else blocky, page not loaded fully?
     677    //https://www.bleepingcomputer.com/news/software/chrome-and-firefox-can-take-screenshots-of-sites-from-the-command-line/
     678    // https://bitsofco.de/using-a-headless-browser-to-capture-page-screenshots/
     679    // https://developers.google.com/web/updates/2017/04/headless-chrome
     680   
     681    String[] cmdArgs = {
     682        "/opt/google/chrome/chrome",
     683        "--headless",
     684        "--screenshot="+outputFilePath, //"--screenshot=\""+outputFilePath+"\"",
     685        "--window-size="+MONITOR_RESOLUTION, //"--window-size=1024,1024",
     686        mapURL
     687    };
     688   
     689   
     690    /*
     691      //WORKS TO RUN FIREFOX TO OPEN A NEW TAB WITH MAPDATA:
     692      // https://askubuntu.com/questions/57163/how-to-open-an-url-from-command-line-to-firefox-and-switch-to-tab
     693    String[] cmdArgs = {
     694        "firefox",
     695        "-new-tab",
     696        mapURL
     697    };
     698    */
     699
     700    /* Can try CutyCapt, http://cutycapt.sourceforge.net/
     701        mentioned at https://bugzilla.mozilla.org/show_bug.cgi?id=1412061
     702     It requires Qt 4.4.0+.
     703     It's installed, https://askubuntu.com/questions/435564/qt5-installation-and-path-configuration
     704     Versions 4 and 5 are installed, seen if I run
     705        qtchooser -list-versions
     706     And when I run: whereis qt5
     707        qt5: /usr/share/qt5
     708     https://unix.stackexchange.com/questions/116254/how-do-i-change-which-version-of-qt-is-used-for-qmake
     709
     710     No, doesn't appear to be installed.
     711    */
    668712   
    669713    System.err.println();
Note: See TracChangeset for help on using the changeset viewer.