Example #1
0
def png(s, filename, scale=2.2, speckle=0.1, color="0f116f", fontpath=None):
    data = skimpyAPI.Png(s,
                         scale=scale,
                         speckle=speckle,
                         color=color,
                         fontpath=fontpath).data(filename)
    print('[PNG image] <br> <img src="%s">' % filename)
Example #2
0
def go(req, s="example", wave=None, **others):
    if wave is not None:
        # redirect to wave file if wave is requested
        return skimpyModPyConfig.makeWaveAndRedirect(wave)
    s = skimpyGimpy.clean(s)
    if not s:
        s = " "
    D = {}
    color = "ff0000"
    prescale = 1
    pngscale = 2.2
    speckle = 0.1
    word = s
    # present the word as PNG and preformatted text and offer a link to a wave representation.
    (fpath, hpath) = skimpyModPyConfig.getPNGPaths()
    skimpyAPI.Png(word, speckle=speckle, scale=pngscale,
                  color=color).data(fpath)
    D = {}
    D["pct"] = "%"
    D["skimpy"] = skimpyAPI.Pre(word,
                                speckle=speckle,
                                scale=prescale,
                                color=color).data()
    D["img"] = hpath
    D["s"] = repr(s)
    D["s0"] = urllib.parse.quote(s)
    return template % D
Example #3
0
    def __init__(self,
                 word=None,
                 wordsize=4,
                 speckle=0.06,
                 scale=2.0,
                 color="00FFFF",
                 test=False):
        """Generate image captcha for word (if word is None, randomly generate
        a word). place it under /public/captcha/<captchafile>.png.
        A hash digest is generated for the image file, which is used as
        `captchafile` name.
        """
        from zeta.config.environment import envpath

        self.path = join(envpath, 'public', 'captcha')
        self.word = word or self.randomword(len=wordsize)
        self.wordsize = wordsize
        self.speckle = speckle
        self.scale = scale
        self.color = color
        self.file = self.captchafile(self.word)

        pngGenerator = skimpyAPI.Png(self.word,
                                     speckle=self.speckle,
                                     scale=self.scale,
                                     color=self.color)
        pngGenerator.data(self.file)
        self.urlpath = join('/captcha', basename(self.file))
        session['captcha'] = self
        session.save()
        return
 def image(self):
     """Generate a captcha image"""
     self._verify_session()
     self._setheaders('image/png')
     return skimpyAPI.Png(self._generate_words()[0],
                          fontpath=VERAMONO).data()
Example #5
0
def apiTest():
    "example of skimpyAPI usage"

    # import the API interface module
    from skimpyGimpy import skimpyAPI

    # this is the text we want to encode
    WORD = "example text"

    #HTML GENERATION:
    # these are the parameters we want to use
    # for preformatted text
    HTMLSPECKLE = 0.1
    HTMLSCALE = 0.7
    HTMLCOLOR = "001199"
    HTMLFILE = "WORD.html"

    # create an HTML generator
    htmlGenerator = skimpyAPI.Pre(
        WORD,
        speckle=HTMLSPECKLE,  # optional
        scale=HTMLSCALE,  # optional
        color=HTMLCOLOR,  # optional
    )
    # store the preformatted text as htmlText
    htmlText = htmlGenerator.data()

    # store the preformatted text as htmlText
    # and also write text to file
    htmlText = htmlGenerator.data(HTMLFILE)

    #PNG GENERATION:
    # these are the parameters we want to use
    # for PNG image output
    PNGSPECKLE = 0.11
    PNGSCALE = 2.1
    PNGCOLOR = "00EEAA"
    PNGFONTPATH = "../fonts/radon-wide.bdf"
    PNGFILE = "WORD.png"

    # create an PNG generator
    pngGenerator = skimpyAPI.Png(
        WORD,
        speckle=PNGSPECKLE,  # optional
        scale=PNGSCALE,  # optional
        color=PNGCOLOR,  # optional
        fontpath=PNGFONTPATH  # optional
    )

    # store the PNG data as pngText
    pngText = pngGenerator.data()

    # store the PNG data as pngText
    # and also write PNG to file
    pngGenerator.data(PNGFILE)

    #WAVE GENERATION:
    # these are the parameters we want to use
    # for WAVE audio output
    INDEXFILEPATH = "../wave/waveIndex.zip"
    WAVEFILE = "WORD.wav"

    # create a wave generator
    waveGenerator = skimpyAPI.Wave(
        WORD,
        indexFile=INDEXFILEPATH  # required!
    )
    # generate the wave data as waveText
    waveText = waveGenerator.data()

    # generate the wave data as waveText
    # and also save to file
    waveText = waveGenerator.data(WAVEFILE)
Example #6
0
htmlText = htmlGenerator.data(HTMLFILE)

#PNG GENERATION:
# these are the parameters we want to use
# for PNG image output
PNGSPECKLE = 0.11
PNGSCALE = 2.1
PNGCOLOR = "00EEAA"
PNGFONTPATH = "../fonts/radon-wide.bdf"
PNGFILE = "png/WORD.png"

# create an PNG generator
pngGenerator = skimpyAPI.Png(
    WORD,
    speckle=PNGSPECKLE,  # optional
    scale=PNGSCALE,  # optional
    color=PNGCOLOR,  # optional
    fontpath=PNGFONTPATH  # optional
)

# store the PNG data as pngText
pngText = pngGenerator.data()

# store the PNG data as pngText
# and also write PNG to file
pngGenerator.data(PNGFILE)

#WAVE GENERATION:
# these are the parameters we want to use
# for WAVE audio output
INDEXFILEPATH = "../wave/waveIndex.zip"