本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Azure:Image Magick 提供 0kb 输出?

发布于2023-03-25 09:03     阅读(1211)     评论(0)     点赞(22)     收藏(2)


我已将 Image magick 与 Java WebApp 集成,并将其部署在 Azure App Service 上。在 azure 上,我得到 0kb 作为图像的输出图像,而同一图像在我的本地机器上得到了很好的转换。我正在使用 im4java 与 Image Magick 集成。下面是代码:

public void compressImage(String imageSource, String destinationPath) throws IOException, InterruptedException,
        IM4JavaException {
    ConvertCmd cmd = getCommand();
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.strip();
    op.interlace();
    op.addRawArgs(compressionRawArguments);
    op.gaussianBlur(compressionGaussianBlur);
    op.quality(compressedImageQuality);
    op.addImage(imageSource); // source file
    op.addImage(destinationPath); // destination file
    // execute the operation

    cmd.run(op);
}

imageSource 和 destination 都是使用 java 创建的临时文件。我检查过 imageSource 文件的大小是否正确,但在运行此代码后,目标文件始终为 0 Kb。

请告知我做错了什么?


解决方案


回答我自己的问题,以便对可能遇到此问题的开发人员有所帮助。

Azure 应用服务通常具有 Windows Server VM。您可以在 Web 容器日志中检查服务器的操作系统。

Windows 的 Image Magick 不允许转换远程 http 图像 url,而对于 Unix 系统,它允许。我的本地机器是 MAC 所以它在我的本地系统上工作正常。

2 我发现的这个问题的解决方案:

  1. 您可以在 Azure 上使用 Linux VM

  2. 在您的应用程序中,将图像 URL 下载到临时文件并将该临时文件的绝对路径提供给图像 magick 以进行转换。

我都尝试过并且都在工作。



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/660452/037e1d9a1ba65af3479e/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

22 0
收藏该文
已收藏

评论内容:(最多支持255个字符)