【问题标题】:ImageMagick COM+: Trying to convert SVG-file to PNG via Classic ASPImageMagick COM+:尝试通过经典 ASP 将 SVG 文件转换为 PNG
【发布时间】:2011-11-11 20:16:23
【问题描述】:

我在 Classic ASP 中使用 ImageMagickObject COM+。我正在尝试将 SVG 文件转换为 PNG 文件。我试过here看到的例子:

convert rose.jpg rose.png

这在命令行中执行时效果很好。此示例在使用经典 ASP 执行时也有效。所以,一切似乎都奏效了。然后我通过 ASP 尝试相同的命令,只使用 SVG 文件而不是 JPG 作为源文件,如下所示:

convert rose.svg rose.png

这不起作用。我没有收到任何错误,但仍然没有 PNG 文件。

然后我在命令行中尝试了这个命令,它可以工作。我尝试了不同的 SVG 文件,但它们都无法使用 ASP 进行转换,但都可以通过命令行工作。

因此该组件似乎已安装,并且我可以从 ASP 转换和写入文件,所以我猜权限也很好。

这可能是什么问题?

谢谢

编辑:

我修改了下面发布的示例。此代码当前有效:

Dim sourceFile : sourceFile = server.mappath("/tempbild/rose.jpg")
Dim destFile : destFile = server.mappath("/tempbild/test.png")

Dim img: Set img = CreateObject("ImageMagickObject.MagickImage.1")
Dim DrawResult
DrawResult  = img.Convert(sourceFile, destFile)
If Err.Number <> 0 Then 
    Response.Write("ImageMagick component failed: " & Err.Number & ": " &
Err.Description)
else
    response.write("ImageMagick component tested successfully: " & DrawResult)
end if

Set img = nothing

当我在 sourceFile 或 destFile 中将文件类型更改为 SVG 时,它会停止工作。我没有收到错误消息,也没有 DrawResult。

【问题讨论】:

    标签: vbscript asp-classic svg imagemagick


    【解决方案1】:

    如果您使用 COM 对象,ImageMagick 有一种相当独特的工作方式。
    命令行中的参数应在 COM 调用中作为字符串传递,但它们保留其“-”前缀。
    我有一个绘制多边形的示例函数,它应该让您了解如何在 ASP 中实现 Imagemagick 指令:

    function DrawPoly(destFile, coordinates, fillcolor, strokecolor)
        ' Draws a single polygon and returns a result-image
        Dim img: Set img = CreateObject("ImageMagickObject.MagickImage.1")
        dim polygon, DrawCommand, DrawResult
            polygon = trim(coordinates)
            DrawCommand = "polygon " & trim(polygon)
            DrawResult  = img.Convert(Server.Mappath(destFile), "-matte", "-fill", fillColor, "-stroke", strokeColor, "-draw", DrawCommand, Server.Mappath(destFile))
            If Err.Number <> 0 Then Response.Write(Err.Number & ": " & Err.Description & vbCrLf & msgs)
        DrawPoly = destFile
        Set img = nothing
    end function
    

    edit:这是另一段代码,稍微简单一点,看看 ImageMagick 是否有效。请注意,您需要在写入映像的目录中授予 IUSR_[machinename] 写入权限。

        Dim destFile : destFile = server.mappath("/test.jpg")
        Dim img: Set img = CreateObject("ImageMagickObject.MagickImage.1")
        Dim DrawResult
            DrawResult  = img.Convert("logo:","-format","%m,%h,%w",destFile)
            If Err.Number <> 0 Then 
                Response.Write("ImageMagick component failed: " & Err.Number & ": " & Err.Description)
            else
                response.write("ImageMagick component tested successfully: <a href=""/~temp/test.jpg"" target=""_blank"">" & DrawResult & "</a>")
            end if
    
    Set img = nothing
    

    HTH,

    埃里克

    【讨论】:

    • 非常感谢您的帮助。请看我的编辑。
    • Charles,你想转换成 SVG 还是 PNG? SVG 是一种矢量格式,我可以对不起作用的图像进行成像...
    • 我想从 SVG 转换为 PNG。我设法使用下面的答案使其工作。
    【解决方案2】:

    好的,我终于找到了答案here。在 jpg 和 png 之间转换时,IIS 似乎不使用 TEMP 目录,这就是它起作用的原因。但是,在转换为 svg 或从 svg 转换时,会写入 TEMP 目录。在服务器的 TEMP 目录(在我的例子中是 c:\windows\temp)你至少需要给 IUSR 用户“更改”权限,我添加了“写”权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 2017-05-16
      • 2012-04-08
      • 1970-01-01
      • 2018-10-26
      • 2012-11-30
      相关资源
      最近更新 更多