tools: Add svglib to view svg files.

This commit is contained in:
Andrew Hamilton 2019-06-29 16:06:14 +10:00
parent aa3c497124
commit a2bea77cd2
3 changed files with 35 additions and 17 deletions

View file

@ -23,7 +23,7 @@ then to run:
### Tools
Extensions(93) | Tools(54)
Extensions(96) | Tools(57)
----------:| -----
.* | [contents](http://pygments.org/) • metadata • [git_blame](https://git-scm.com/docs/git-blame) • [git_log](https://git-scm.com/docs/git-log)
.py | [python_syntax](https://en.wikipedia.org/wiki/Python_syntax_and_semantics) • [python_unittests](https://docs.python.org/3/library/unittest.html) • [pydoc](https://docs.python.org/3/library/pydoc.html) • [mypy](http://mypy-lang.org/) • [python_coverage](https://coverage.readthedocs.io/) • [pycodestyle](http://pycodestyle.pycqa.org/en/latest/) • [pydocstyle](http://www.pydocstyle.org/en/2.1.1/usage.html) • [pyflakes](https://pypi.org/project/pyflakes/) • [pylint](https://www.pylint.org/) • [python_gut](https://github.com/ahamilton/eris/blob/master/gut.py) • [python_modulefinder](https://docs.python.org/3/library/modulefinder.html) • [dis](https://docs.python.org/3/library/dis.html) • [python_mccabe](https://pypi.org/project/mccabe/) • [bandit](https://pypi.org/project/bandit/)
@ -35,8 +35,9 @@ Extensions(93) | Tools(54)
.lua | [lua_syntax](http://www.lua.org) • [lua_check](https://github.com/mpeterv/luacheck)
.js | [js_syntax](http://nodejs.org/)
.php | [php7_syntax](https://en.wikipedia.org/wiki/PHP)
.go | [go_vet](https://golang.org) • [golint](https://github.com/golang/lint) • [godoc](http://golang.org/x/tools)
.go | [go_vet](https://github.com/golang/go) • [golint](https://github.com/golang/lint) • [godoc](https://github.com/golang/go)
.bash .sh .dash .ksh | [shellcheck](https://www.shellcheck.net/)
.wasm | [wasm-validate](https://github.com/WebAssembly/wabt) • [wasm-objdump](https://github.com/WebAssembly/wabt)
.pdf | [pdf2txt](https://github.com/pdfminer/pdfminer.six)
.html .htm | [html_syntax](http://www.html-tidy.org/) • [html2text](http://www.mbayer.de/html2text/) • [pandoc](https://pandoc.org/)
.yaml .yml | [yamllint](https://github.com/adrienverge/yamllint)
@ -46,12 +47,13 @@ Extensions(93) | Tools(54)
.tar.bz2 | [tar_bz2](http://www.gnu.org/software/tar/manual/tar.html)
.rar | [unrar](http://www.rarlabs.com/)
.7z | [7z](http://p7zip.sourceforge.net/)
.xz | [unxz](http://tukaani.org/xz/)
.xz | [unxz](https://tukaani.org/xz/)
.a | [ar](https://en.wikipedia.org/wiki/Ar_(Unix)) • [nm](https://linux.die.net/man/1/nm)
.o | [objdump_headers](https://en.wikipedia.org/wiki/Objdump) • [objdump_disassemble](https://en.wikipedia.org/wiki/Objdump) • [readelf](https://en.wikipedia.org/wiki/Objdump)
.so | [nm](https://linux.die.net/man/1/nm)
.deb | [dpkg_contents](https://wiki.debian.org/Teams/Dpkg) • [dpkg_info](https://wiki.debian.org/Teams/Dpkg)
.rpm | [rpm](http://rpm.org/)
.png .jpg .gif .bmp .tif .tiff .tga | [mediainfo](https://mediaarea.net/MediaInfo) • [pil](http://python-pillow.github.io/)
.svg .svgz | [svglib](https://github.com/deeplook/svglib)
.mkv .mka .mks .ogg .ogm .avi .wav .mpeg .mpg .vob .mp4 .mpgv .mpv .m1v .m2v .mp2 .mp3 .asf .wma .wmv .qt .mov .rm .rmvb .ra .ifo .ac3 .dts .aac .flac .aiff .aifc .au .iff .flv .srt .ssa .ass .sami | [mediainfo](https://mediaarea.net/MediaInfo)
.iso | [isoinfo](https://manpages.debian.org/jessie/genisoimage/isoinfo.1.en.html)

View file

@ -434,6 +434,22 @@ def _resize_image(image, new_width):
PIL.Image.ANTIALIAS)
def _image_to_text(image):
text = "" * image.width
data = list(image.getdata())
width = image.width
rows = [data[row_index*width:(row_index+1)*width]
for row_index in range(image.height)]
if image.height % 2 == 1:
rows.append([None] * image.width)
return fill3.Fixed([
termstr.TermStr(text, tuple(termstr.CharStyle(
fg_color=top_pixel, bg_color=bottom_pixel)
for top_pixel, bottom_pixel in zip(rows[index],
rows[index+1])))
for index in range(0, image.height, 2)])
@deps(deps={"pip/pillow"}, url="python3-pil")
def pil(path):
import PIL.Image
@ -441,20 +457,16 @@ def pil(path):
with PIL.Image.open(image_file).convert("RGB") as image:
if image.width > MAX_IMAGE_SIZE:
image = _resize_image(image, MAX_IMAGE_SIZE)
text = "" * image.width
data = list(image.getdata())
width = image.width
rows = [data[row_index*width:(row_index+1)*width]
for row_index in range(image.height)]
if image.height % 2 == 1:
rows.append([None] * image.width)
result = fill3.Fixed([
termstr.TermStr(text, tuple(termstr.CharStyle(
fg_color=top_pixel, bg_color=bottom_pixel)
for top_pixel, bottom_pixel in zip(rows[index],
rows[index+1])))
for index in range(0, image.height, 2)])
return Status.normal, result
return Status.normal, _image_to_text(image)
@deps(deps={"pip/svglib"}, url="https://github.com/deeplook/svglib")
def svglib(path):
import svglib.svglib
import reportlab.graphics.renderPM
drawing = svglib.svglib.svg2rlg(path)
image = reportlab.graphics.renderPM.drawToPIL(drawing)
return Status.normal, _image_to_text(image)
@deps(deps={"go/github.com/golang/go/src/cmd/godoc" },

View file

@ -36,6 +36,7 @@ tools_for_extensions = [
[["deb"], ["dpkg_contents", "dpkg_info"]],
[["rpm"], ["rpm"]],
[["png", "jpg", "gif", "bmp", "tif", "tiff", "tga"], ["mediainfo", "pil"]],
[["svg", "svgz"], ["svglib"]],
[["mkv", "mka", "mks", "ogg", "ogm", "avi", "wav", "mpeg", "mpg", "vob",
"mp4", "mpgv", "mpv", "m1v", "m2v", "mp2", "mp3", "asf", "wma", "wmv",
"qt", "mov", "rm", "rmvb", "ra", "ifo", "ac3", "dts", "aac", "flac",
@ -227,6 +228,7 @@ tools_for_extensions = [
[lua_check]
dependencies = ["luarocks/luacheck"]
url = "https://github.com/mpeterv/luacheck"
command = "luacheck"
[go_vet]
@ -241,10 +243,12 @@ tools_for_extensions = [
[wasm-validate]
dependencies = ["git/github.com/WebAssembly/wabt"]
url = "https://github.com/WebAssembly/wabt"
command = "wasm-validate"
[wasm-objdump]
dependencies = ["git/github.com/WebAssembly/wabt"]
url = "https://github.com/WebAssembly/wabt"
command = "wasm-objdump --disassemble"
success_status = "normal"