Skip to content

Add SVG support using ImageMagick - #83

Merged
Tymewalk merged 16 commits into
masterfrom
wand-svg
Sep 19, 2016
Merged

Tymewalk merged 16 commits into
masterfrom
wand-svg

Conversation

@BookOwl

@BookOwl BookOwl commented Sep 13, 2016

Copy link
Copy Markdown
Member

This PR adds SVG costume support to Slither using the ImageMagick tool.
It should be almost ready to merge, I just need to check and make sure that I haven't forgotten or broke anything.

@BookOwl

BookOwl commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

I went through all the tests and fixed the bugs.

@BookOwl

BookOwl commented Sep 13, 2016 •

Copy link
Copy Markdown
Member Author

I think that this is ready, @Tymewalk

@BookOwl

BookOwl commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

I need to fix some windows bugs. :(

@BookOwl

BookOwl commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

I fixed the bugs! 📦

@BookOwl

BookOwl commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

OK, I fixed the windows bugs and the merge conflicts. @Tymewalk, I believe that this is ready to merge!

@Tymewalk

Copy link
Copy Markdown
Member

Need to check on Linux. Cloning the repo and testing now 🔹

@Tymewalk

Copy link
Copy Markdown
Member

I have ImageMagick installed, but I get this:

Traceback (most recent call last):
  File "slither/tests/svgTest.py", line 4, in <module>
    import slither
  File "/usr/local/lib/python2.7/dist-packages/slither-0.3.0-py2.7.egg/slither/__init__.py", line 1, in <module>
    from .slither import *
  File "/usr/local/lib/python2.7/dist-packages/slither-0.3.0-py2.7.egg/slither/slither.py", line 14, in     <module>
    if subprocess.call("identify -version", shell=True, stdout=subprocess.DEVNULL) != 0:
AttributeError: 'module' object has no attribute 'DEVNULL'

@BookOwl

BookOwl commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

That means that you are using a Python 3.2 or older. subprocess.DEVNULL is only in Python 3.3+

We don't have to have that feature, it just means that the output of the different commands might go to the terminal.

@Tymewalk

Copy link
Copy Markdown
Member

@BookOwl I ran with Python 2. Will we have to drop SVG support for that version?

@BookOwl

BookOwl commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

I don't think so, it just means that Python2 users (and people who use Python3.2 or lower) will get extra text in their terminal (unless I can figure out another way to get rid of it). I'll be pretty busy today, but I should be able to get it done this evening.

@BookOwl

BookOwl commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

I think that I found a solution: Pass open(os.devnull, "wb") to stdout instead of DEVNULL

@BookOwl

BookOwl commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

OK, I think that I've fixed it. Just let me test on Python2 real quick.

@BookOwl

BookOwl commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

OK, I've gotten it to work in both Python2 and Python3. @Tymewalk, please test again.

@Tymewalk

Copy link
Copy Markdown
Member

Just tested:

timmy@timmybox:/home/timmy/ghp/Slither$ python slither/tests/svgTest.py 
We have SVG support!
convert.im6: unable to open image `/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no images defined `info:' @ error/convert.c/ConvertImageCommand/3044.
Traceback (most recent call last):
  File "slither/tests/svgTest.py", line 12, in <module>
    svg.addCostume("assets/svg Logo.svg", "svg")
  File "/usr/local/lib/python2.7/dist-packages/slither-0.3.0-py2.7.egg/slither/slither.py", line 194, in addCostume
    costume = SVGCostume(costumePath, self.scale if hasattr(self, "scale") else 1)
  File "/usr/local/lib/python2.7/dist-packages/slither-0.3.0-py2.7.egg/slither/slither.py", line 149, in __init__
    shell=True)
  File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'convert "/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg" -format "%w %h" info:' returned non-zero exit status 1
timmy@timmybox:/home/timmy/ghp/Slither$ python3 slither/tests/svgTest.py 
We have SVG support!
convert.im6: unable to open image `/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no images defined `info:' @ error/convert.c/ConvertImageCommand/3044.
Traceback (most recent call last):
  File "slither/tests/svgTest.py", line 12, in <module>
    svg.addCostume("assets/svg Logo.svg", "svg")
  File "/usr/local/lib/python3.4/dist-packages/slither-0.3.0-py3.4.egg/slither/slither.py", line 194, in addCostume
    costume = SVGCostume(costumePath, self.scale if hasattr(self, "scale") else 1)
  File "/usr/local/lib/python3.4/dist-packages/slither-0.3.0-py3.4.egg/slither/slither.py", line 149, in __init__
    shell=True)
  File "/usr/lib/python3.4/subprocess.py", line 620, in check_output
    raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'convert "/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg" -format "%w %h" info:' returned non-zero exit status 1
timmy@timmybox:/home/timmy/ghp/Slither$ python3.4 slither/tests/svgTest.py 
We have SVG support!
convert.im6: unable to open image `/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no images defined `info:' @ error/convert.c/ConvertImageCommand/3044.
Traceback (most recent call last):
  File "slither/tests/svgTest.py", line 12, in <module>
    svg.addCostume("assets/svg Logo.svg", "svg")
  File "/usr/local/lib/python3.4/dist-packages/slither-0.3.0-py3.4.egg/slither/slither.py", line 194, in addCostume
    costume = SVGCostume(costumePath, self.scale if hasattr(self, "scale") else 1)
  File "/usr/local/lib/python3.4/dist-packages/slither-0.3.0-py3.4.egg/slither/slither.py", line 149, in __init__
    shell=True)
  File "/usr/lib/python3.4/subprocess.py", line 620, in check_output
    raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command 'convert "/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg" -format "%w %h" info:' returned non-zero exit status 1
timmy@timmybox:/home/timmy/ghp/Slither$ 

Tried on Python 2, Python 3, and Python 3.4 explicitly.

However, running slither/tests/svgTest.py as an executable results in this:

import.im6: unable to open image `slither': Is a directory @ error/blob.c/OpenBlob/2641.
slither/tests/svgTest.py: line 7: syntax error near unexpected token `"We have SVG support!"'
slither/tests/svgTest.py: line 7: `    print("We have SVG support!")'

I'm on Linux if it helps.

@BookOwl

BookOwl commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

Try running convert "/home/timmy/ghp/Slither/slither/tests/assets/svg Logo.svg" -format "%w %h" info: in your shell and see if it's still making that error.

@BookOwl

BookOwl commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

I found the problem: I didn't get the case of the test image right. On Windows and OS X it doesn't matter, but on Linux...

@BookOwl

BookOwl commented Sep 19, 2016

Copy link
Copy Markdown
Member Author

@Tymewalk, please test.

@Tymewalk

Copy link
Copy Markdown
Member

@BookOwl YESSS! 🎆

It works on Python 2 and 3 (Linux!) without using that convert command. Woo!

Also, when you said "case of the test image", I thought you meant something was special about it, not that the filename mattered...

I REALLY hate that case doesn't matter in Windows somedays. 😛

@Tymewalk

Copy link
Copy Markdown
Member

If there isn't anything else you can think of that we need to check, this is ready to merge!

0.4 here we come!

@BookOwl

BookOwl commented Sep 19, 2016

Copy link
Copy Markdown
Member Author

Yep, it can be quite a pain. 😛
I think that this is ready.

@Tymewalk

Copy link
Copy Markdown
Member

Anything else can be done later on. Merging now!

@Tymewalk
Tymewalk merged commit a2f6ab1 into master Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants