我想看看我的公司是否可以使用Azure功能将TIFF文件自动转换为许多JPG和PNG格式和大小。我正在使用Node.js函数,但可以使用其他语言。
我的问题是,我不能得到GraphicsMagick或ImageMagick工作的功能。我使用正常的安装程序,使用npm install。
它似乎安装ok,模块似乎也加载,但当我尝试处理文件时什么也没发生。没有,也没有错误。
var fs = require('fs');Var gm = require('gm');
模块。Exports = function (context, req) {context.log("开始…");
try { context.log('Looking for GM...'); context.log(require.resolve("gm")); } catch(e) { console.log("GM is not found"); process.exit(e.code); } gm('D:/home/site/wwwroot/HttpTriggerJS1/input/870003-02070-main-nfh.jpg') .resize(240, 240) .noProfile() .write('D:/home/site/wwwroot/HttpTriggerJS1/output/resize.jpg', function (err) { context.log('TEST'); if (!err) { context.log('done'); } } ); context.done(null, res); };
我不确定这是否可能,但我没有发现任何信息表明它不能。
所以,我可以使用ImageMagick, GraphicsMagick或第三图像转换器在功能?如果是,在安装时是否需要注意一些特别的事情?
是否也有一个c#的解决方案?
Azure中的Web Apps是SaaS(软件即服务)。您将数据部署到Azure IIS容器中,Azure会完成其余的工作。我们没有太多的控制权。因此,我们将没有特权安装任何第三方可执行文件Azure功能应用程序(如ImageMagick或GraphicsMagick)。如果您需要这样做,请查看虚拟机。另一个选择是使用云服务的Web或Worker角色。
或者,有一个很好的用于Node的图像处理库,完全用JavaScript编写,没有外部或本机依赖,Jimp。https://github.com/oliver-moran/jimp
使用例子:
var Jimp = require("jimp");
Jimp.read("lenna.png").then(function (lenna) {
lenna.resize(256, 256) // resize
.quality(60) // set JPEG quality
.greyscale() // set greyscale
.write("lena-small-bw.jpg"); // save
}).catch(function (err) {
console.error(err);
});
有另一个叫做sharp的node.js库来满足你的需求。你可以这样试试:
首先,在本地环境中安装sharp,然后使用包含编译模块的node_modules
文件夹将应用程序部署到Azure。最后,将Azure应用程序服务上的节点可执行文件升级到64位。
类似的线程你可以在这里参考。
使用例子:
var sharp = require("sharp");
sharp(inputBuffer)
.resize(320, 240)
.toFile('output.webp', (err, info) => {
//...
});
Azure函数也可以运行自定义docker映像
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image不确定你对哪种语言感兴趣,但你可以有一个python图像与以下样式Dockerfile
FROM mcr.microsoft.com/azure-functions/python:2.0
RUN apt-get update &&
apt-get install -y --no-install-recommends apt-utils &&
apt-get install -y imagemagick
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot &&
pip install -r requirements.txt
然后使用PythonMagick来处理相同的
您可以使用站点扩展使imagemagick为azure web应用程序工作。
您可以查看存储库获取更多信息:https://github.com/fatihturgut/azure-imagemagick-nodejs