将画布上的绘图转换为icns

时间:2014-08-26 09:29:54

标签: javascript canvas firefox-addon

是否可以将画布上的绘图转换为Mac的.icns

任何人都知道linux使用什么图标格式?

1 个答案:

答案 0 :(得分:0)

回答我关于linux使用的图标类型的问题

我认为linux使用png图像作为图标。有人可以在评论中进行验证。

关于如何转换为.icns

的问题的解决方案

如果有人有任何其他方式请分享,我喜欢看到多种方法来做同样的事情,看看他们之间的差异/怪癖。

要在mac中转换为.icns,请在mxr上完成:http://mxr.mozilla.org/mozilla-release/source/toolkit/webapps/MacNativeApp.js#291

这是编辑的代码,因此它在上面的mxr范围之外工作。

/**
* @param aIcon         nsIFile :: of icon
* @param aPath         String :: where you want to save the image and with what name
*/
_processIcon: function(aIcon, aPath) {
  let deferred = Promise.defer();

  //let tmpIconPath = OS.Path.join(aDir, this.iconFile);

  function conversionDone(aSubject, aTopic) {
    if (aTopic != "process-finished") {
      deferred.reject("Failure converting icon, exit code: " + aSubject.exitValue);
      return;
    }

    // SIPS silently fails to convert the icon, so we need to verify if the
    // icon was successfully converted.
    OS.File.exists(aPath).then((aExists) => {
      if (aExists) {
        deferred.resolve();
      } else {
        deferred.reject("Failure converting icon, unrecognized image format");
      }
    });
  }

  let process = Cc["@mozilla.org/process/util;1"].
                createInstance(Ci.nsIProcess);
  let sipsFile = FileUtils.getFile("/usr/bin/sips");

  process.init(sipsFile);
  process.runAsync(["-s", "format", "icns",
                    aIcon.path,
                    "--out", aPath,
                    "-z", "128", "128"],
                    9, conversionDone);

  return deferred.promise;
}

我还没有能够测试它,因为我还没有mac vm,但希望它没有像我在Windows上那样的质量问题。