javascript - Saving remote image with PhantomJS -


i'm using phantomjs 2.1.1 on ubuntu without node or casper.

fs.write('images/products/image.jpg', 'http://example.com/folder/someimage.jpg', 'w'); 

.. although creates 1xx byte jpeg files aren't images. there way download type of (jpeg, jpg, png) file phantomjs?

a simpler way this, in phantomjs saves image itself:

var page = require('webpage').create();  page.viewportsize = { width: 1280, height: 800 }; page.settings.useragent = 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/51.0.2704.106 safari/537.36';  var url = "http://stackoverflow.com"; var selector = "#hlogo a";  page.open(url, function(){      settimeout(function(){          var cliprect = page.evaluate(function (selector) {              return document.queryselector(selector).getboundingclientrect();          }, selector);          page.cliprect = {             top:    cliprect.top,             left:   cliprect.left,             width:  cliprect.width,             height: cliprect.height         };          page.render('image.jpg');          phantom.exit();      }, 1000);  }); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -