Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Do not remove metadata when --remove-metadata=no #214

Open
jgneff opened this issue Mar 8, 2020 · 2 comments
Open

Do not remove metadata when --remove-metadata=no #214

jgneff opened this issue Mar 8, 2020 · 2 comments

Comments

@jgneff
Copy link

jgneff commented Mar 8, 2020

svgcleaner removes the content of the metadata element even when the option --remove-metadata is set to no.

The input file is the example from the documentation:

input.svg:

<svg xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:cc="http://creativecommons.org/ns#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <metadata id="metadata1">
    <rdf:RDF>
      <cc:Work rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
          rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
        <dc:title/>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <circle fill="green" cx="50" cy="50" r="45"/>
</svg>

Removing the metadata works fine:

ubuntu@xenial:~$ ~/opt/svgcleaner-0.9.5/svgcleaner \
    --indent=0 --remove-metadata=yes input.svg remove-metadata-yes.svg

remove-metadata-yes.svg:

<svg>
<circle cx="50" cy="50" fill="#008000" r="45"/>
</svg>

Yet even when --remove-metadata=no, svgcleaner removes the content of the metadata element, leaving an empty element in its place:

ubuntu@xenial:~$ ~/opt/svgcleaner-0.9.5/svgcleaner \
    --indent=0 --remove-metadata=no input.svg remove-metadata-no.svg

remove-metadata-no.svg:

<svg>
<metadata/>
<circle cx="50" cy="50" fill="#008000" r="45"/>
</svg>

I would like the final output file to contain my metadata for a Creative Commons license.

@JoKalliauer
Copy link
Contributor

JoKalliauer commented Mar 8, 2020

@jgneff --remove-metadata=no --remove-nonsvg-elements no --remove-nonsvg-attributes no

You should try

ubuntu@xenial:~$ ~/opt/svgcleaner-0.9.5/svgcleaner \
    --indent=0 --remove-metadata=no --remove-nonsvg-elements no  --remove-nonsvg-attributes no input.svg remove-metadata-no.svg

@RazrFalcon --remove-metadata=no should per default set --remove-nonsvg-elements no --remove-nonsvg-attributes no otherwise it is confusing, see also #141 (comment)

@jgneff
Copy link
Author

jgneff commented Mar 30, 2020

Thank you, @JoKalliauer. Now I get it. I didn't realize that the options were independent. I can understand how that might be useful, but the downside is that you then kind of need to understand all of the options to get it right, and there are a lot of them.

svgcleaner is a great tool, regardless. I ended up just letting svgcleaner remove the metadata, and I add it with sed afterwards, as shown below.

~/opt/svgcleaner-0.9.5/svgcleaner --indent=0 tmp/file.svg tmp/file-clean.svg
sed -e "/<svg/r tmp/metadata.xml" \
    -e '1 i <?xml version="1.0" encoding="UTF-8"?>' \
    -e "s/Arimo/Arimo,Liberation Sans,Arial,sans-serif/g" tmp/file-clean.svg \
    > out/file.svg

As you can see, I also add an XML declaration because of a bug in my old copy of ExifTool 10.10 (fixed in version 11.66), and I add a full font stack. By the way, this font stack works great with very good metric compatibility across systems. The only one that is slightly off is Android, which has no Arial-compatible font and uses Roboto for the sans-serif, but it's good enough and not worth converting the text to paths.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants