简体   繁体   English

我可以使用Basil.js从URL获取图像吗?

[英]Can I use Basil.js to get images from a URL?

I am a novice user at ExtendScript, Basil.js & Javascript. 我是ExtendScript,Basil.js和Javascript的新手用户。

After seeing the project http://basiljs.ch/gallery/ending-the-depression-through-amazon/ I wondered if it is possible to simply get the Basil.js Script/ Extendscript/Indesign to grab images from a webpage and insert it directly into a indesign document. 看完项目http://basiljs.ch/gallery/ending-the-depression-through-amazon/之后,我想知道是否有可能简单地获取Basil.js脚本/ Extendscript / Indesign来从网页中获取图像并插入将其直接转换为indesign文档。

I am a beginner so if someone had a complete script, from directory, functions... with example url, import, save, place.... ? 我是一个初学者,所以如果有人有一个完整的脚本,可以从目录,功能...中获取示例脚本,URL,导入,保存,放置...。

This is in the hope that I could simply put an address into the script and it would harvest all images on the webpage and put them into a indesign document? 希望我可以简单地在脚本中添加一个地址,然后将网页上的所有图像收集到一个indesign文档中?

I tried their example http://basiljs.ch/tutorials/getting-images-from-urls/ but when I copy that and run it in extend script it is just searching my computer... 我尝试了他们的示例http://basiljs.ch/tutorials/getting-images-from-urls/,但是当我复制并在扩展脚本中运行它时,它只是在搜索我的计算机...

UPDATE* 更新*

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basil/basil.js";

function draw() {
  var url = "https://raw.github.com/basiljs/basil.js/master/lib/basil.png";

  // download the url to a default location, filename according to url:
  // -> "the project folder" + data/download/basil.png
  //b.download(url);

  // download url to a specific location in the project folder:
  // -> "the project folder" + data/download_images_files/basil_logo.png
 // b.download(url, "download_images_files/basil_logo.png");

  // download url to a specific location e.g. to your desktop
  // -> ~/Desktop/basil_logo.png
  var newFile = new File("~/Desktop/basil_logo.png");
  b.download(url, newFile);
}

b.go();

... It finds in Error in Basil's Core.js @ ...它在Basil的Core.js @中发现错误

var runDrawOnce = function() {
  app.doScript(function() {
    if (typeof glob.draw === 'function') {
      glob.draw();
    }
  }, ScriptLanguage.javascript, undef, UndoModes.ENTIRE_SCRIPT);
};

Console says... Using basil.js 1.08 ... sh ~/Documents/basiljs/bundle/lib/download.sh /Users/jamestk/Desktop (Address here, I don't have the sufficient reputation on stack overflow) 控制台说...使用basil.js 1.08 ... sh〜/ Documents / basiljs / bundle / lib / download.sh / Users / jamestk / Desktop(地址,在堆栈溢出时我没有足够的声誉)

Basil.js Error -> b.shellExecute(): Error: sh: /Users/jamestk/Documents/basiljs/bundle/lib/download.sh: No such file or directory Basil.js错误-> b.shellExecute():错误:sh:/Users/jamestk/Documents/basiljs/bundle/lib/download.sh:没有此类文件或目录

The easiest way would probably be to us the b.shellExecute(cmd) command to run a shell script that downloads your images. 最简单的方法可能是让我们执行b.shellExecute(cmd)命令来运行可下载映像的Shell脚本。

You could use wget from shell to download all images from an url, see this question: How do I use Wget to download all Images into a single Folder 您可以使用wget from shell从URL下载所有图像,请参见以下问题: 如何使用Wget将所有图像下载到单个文件夹中

You should make sure then to save the images in the documents data directory. 然后,您应确保将图像保存在文档数据目录中。 After that, you could get all images by using the Folder object's getFiles() method: 之后,您可以使用Folder对象的getFiles()方法获取所有图像:

var myImagesArray = Folder('~/path/to/my/folder').getFiles();

Finally you could use that array in a loop to place all the images into your document. 最后,您可以循环使用该数组将所有图像放入文档中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM