【问题标题】:ExifTool: Removing all metadata of an image except one in java applicationExifTool:删除图像的所有元数据,Java应用程序中的元数据除外
【发布时间】:2020-06-05 06:48:09
【问题描述】:

我想删除图像的所有元数据,除了“版权”。我正在使用这个的 exiftool。这个命令是“exiftool -all= -tagsFromFile @ -copyright Tunis_Bab_Souika_1899.jpg”。但是当我这样做时在java应用程序中。它以某种方式删除所有标签。

这里是代码 sn-p -

    val outputConsumer = ArrayListOutputConsumer()
    val exiftoolCmd = ExiftoolCmd()
    exiftoolCmd.setOutputConsumer(outputConsumer)
    val operation = ETOperation()
    println("File name" + sourceImage.toFile().absolutePath)
    operation.addImage(sourceImage.toFile().absolutePath)
    // exiftool -all= -tagsFromFile @ -copyright Tunis_Bab_Souika_1899.jpg
    operation.addRawArgs("-all=")
    operation.addRawArgs("-tagsFromFile @")
    operation.addRawArgs("-copyright")

    println("About to execute")
    try {exiftoolCmd.run(operation)
        println("Inside try")
    } catch (e: java.lang.Exception) {
        throw RuntimeException(e)
    }
    val output = outputConsumer.output
        .stream()
        .map { obj: String -> obj.trim { it <= ' ' } }
        .collect(toList())
    println("ooutput$output")

【问题讨论】:

  • 我不太了解 java 或它向命令行传递数据的方式,但也许将 -tagsFromFile @ 拆分为两个单独的 addRawArgs?从技术上讲,它们是两个独立的参数,当它通过时,它可能会做一些事情,比如将整个事情用引号括起来。这会导致 exiftool 失败。
  • 在“Inside Try”附近使用 println(operation.getCmdArgs()) 来查看添加的参数。 operation.addRawArgs("-tagsFromFile @") 可能需要 operation.addRawArgs("-tagsFromFile", "@")

标签: java image imagemagick metadata exiftool


【解决方案1】:

回答我的问题 - 这对我有用 -

 operation.delTags("all")
            operation.tagsFromFile("@")
            operation.getTags("copyright")
            operation.addImage(sourceImage.toFile().absolutePath)

【讨论】:

    猜你喜欢
    • 2018-09-02
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    相关资源
    最近更新 更多