GithubHelp home page GithubHelp logo

jesperdramsch / code2image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from axju/code2image

0.0 2.0 0.0 589 KB

Create code snippet with pygments and pillow

License: MIT License

Python 100.00%

code2image's Introduction

code2image

Create code snippet with pygments and pillow.

Install

$ pip install code2image

Basic uses

$ python examples/shadow.py

https://raw.githubusercontent.com/axju/code2image/master/examples/shadow.png

This package was developed to automate some boring image creation process. But it has also a script for some command line fun.

$ code2image --help
usage: code2image [-h] [--kind {simple,shadow,background}]
                  [--imagename IMAGENAME] [--code CODE]
                  [--background BACKGROUND] [--font-size FONT_SIZE]
                  [--font-name FONT_NAME] [--line_pad LINE_PAD]
                  [--line-numbers] [--shadow-color SHADOW_COLOR]
                  [--shadow-dt SHADOW_DT] [--offset OFFSET] [--blur BLUR]
                  [--epilog EPILOG]
                  codefile

Create nice code snippets

positional arguments:
  codefile              The code file

optional arguments:
  -h, --help            show this help message and exit
  --kind {simple,shadow,background}
                        Change the result
  --imagename IMAGENAME
                        The output image
  --code CODE           Code background color
  --background BACKGROUND
                        Image background color
  --font-size FONT_SIZE
                        font size
  --font-name FONT_NAME
                        font name
  --line_pad LINE_PAD   line pad
  --line-numbers        line numbers
  --shadow-color SHADOW_COLOR
                        Shadow color
  --shadow-dt SHADOW_DT
                        Shadow offset
  --offset OFFSET       Border width
  --blur BLUR           Shadow blur
  --scale SCALE         A scale
  --epilog EPILOG       A epilog

To create nice images for instagram:

$ code2image --kind background --scale 1 /pathe/to/code/file

Python examples

from code2image.cls import Code2Image

c2i = Code2Image()

# load the source code from this file
with open(__file__) as f:
    code = f.read()

# create the image with highlighted code
img = c2i.highlight(code)

# save the image
img.save('simple.png')

See the "examples" folder for more.

Development

Clone repo

$ git clone https://github.com/axju/code2image.git

Create virtual environment for linux

$ python3 -m venv venv
$ source venv/bin/activate

or create virtual environment for windows

$ python -m venv venv
$ venv/Scripts/activate

update dev-tools

$ python -m pip install --upgrade wheel pip setuptools twine tox flake8

Install local

$ pip install -e .

Publish the packages

$ python setup.py sdist bdist_wheel
$ twine upload dist/*

Run some tests

$ flake8 code2image
$ python setup.py test
$ python -m unittest discover -v
$ tox

I do not know why, but tox will fail :(

code2image's People

Contributors

axju avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.