コード例 #1
0
 def getLayers(self):
     word = Words.defaultWordList.pick()
     self.addSolution(word)
     return [
         Backgrounds.SolidColor(),
         Text.TextLayer(word, fontFactory=Text.FontFactory((15, 15), "vera"),
             textColor='black', borderSize=0),
         Distortions.WarpBase(),
         ]
コード例 #2
0
ファイル: examples.py プロジェクト: jango2015/fruit-1
 def getLayers(self):
     word = WordList('basic-english').pick()
     self.addSolution(word)
     return [
         random.choice(
             [Backgrounds.CroppedImage(),
              Backgrounds.TiledImage()]),
         Text.TextLayer(word,
                        borderSize=1,
                        fontFactory=Text.FontFactory(18,
                                                     "vera/VeraBd.ttf")),
         Distortions.SineWarp()
     ]
コード例 #3
0
ファイル: captcha.py プロジェクト: yayoec/python
class NumberCaptcha(ImageCaptcha):
    """A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
    fontFactory = Text.FontFactory(16, "vera/Vera.ttf")
    defaultSize = (60, 24)

    def __init__(self, digits=4):
        if digits > 10:
            digits = 10
        self.solution = ''.join(
            ['%s' % i for i in random.sample(range(0, 10), digits)])

        super(NumberCaptcha, self).__init__()

    def getLayers(self):
        self.addSolution(self.solution)

        textLayer = Text.TextLayer(self.solution,
                                   borderSize=1,
                                   fontFactory=self.fontFactory)

        return [  # random.choice([ Backgrounds.TiledImage() ]),
            [
                Backgrounds.SolidColor('white'),
                Backgrounds.RandomDots(
                    colors=['yellow', 'blue', 'green', 'red'], numDots=10)
            ],
            textLayer,
            Distortions.SineWarp(),
        ]
コード例 #4
0
ファイル: captcha.py プロジェクト: yayoec/python
class ChineseIdiomCaptcha(ImageCaptcha):
    """A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
    fontFactory = Text.FontFactory(16, "cn/simyou.ttf")
    defaultSize = (80, 25)

    def __init__(self, solution=u'验证码', from_list=True):
        if from_list:
            idiom_chinese = Words.WordList("basic-english",
                                           minLength=5,
                                           maxLength=8)
            self.solution = idiom_chinese.pick()
        else:
            self.solution = solution

        super(ChineseIdiomCaptcha, self).__init__()

    def getLayers(self):
        self.addSolution(self.solution)

        textLayer = Text.TextLayer(self.solution,
                                   borderSize=2,
                                   fontFactory=self.fontFactory)

        return [
            Backgrounds.CroppedImage(),
            textLayer,
            Distortions.SineWarp(amplitudeRange=(1, 1)),
        ]
コード例 #5
0
ファイル: simple_example.py プロジェクト: lerouxb/seymour
    def getLayers(self):
        #word = Words.defaultWordList.pick()
        self.addSolution(self.word)
        #return [
            #Backgrounds.SolidColor(),
            #random.choice([
                #Backgrounds.CroppedImage(),
                #Backgrounds.TiledImage(),
            #    Backgrounds.Grid(size=10)
            #]),
            #Text.TextLayer(word, borderSize=1),
            #Backgrounds.Grid(size=15),
            #Distortions.SineWarp(amplitudeRange=(2, 3.0)),
            #Distortions.WigglyBlocks(blockSize=5),
            #Backgrounds.RandomDots(dotSize=2, numDots=400),
        #    ]

        return [
            Backgrounds.SolidColor(),
            Backgrounds.Grid(size=10),
            Distortions.SineWarp(amplitudeRange=(3, 5.0)),
            Text.TextLayer(self.word, borderSize=0),
            Backgrounds.RandomDots(dotSize=2, numDots=800),
            Distortions.SineWarp(amplitudeRange=(3, 6.0)),
        ]
コード例 #6
0
ファイル: captcha.py プロジェクト: yayoec/python
class EnglishWordCaptcha(ImageCaptcha):
    """A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
    fontFactory = Text.FontFactory(16, "vera/Vera.ttf")
    defaultSize = (80, 25)

    def __init__(self, solution=u'验证码', from_list=True):
        if from_list:
            self.solution = Words.basic_english_restricted.pick()
        else:
            self.solution = solution

        super(EnglishWordCaptcha, self).__init__()

    def getLayers(self):
        self.addSolution(self.solution)

        textLayer = Text.TextLayer(self.solution,
                                   borderSize=1,
                                   fontFactory=self.fontFactory)

        return [
            random.choice([Backgrounds.TiledImage()]),
            textLayer,
            Distortions.SineWarp(),
        ]
コード例 #7
0
ファイル: captcha.py プロジェクト: yangzxstar/reddit
 def getLayers(self, solution="blah"):
     self.addSolution(solution)
     return ((Backgrounds.Grid(size=8, foreground="white"),
              Distortions.SineWarp(amplitudeRange=(5, 9))),
             (Text.TextLayer(solution,
                             textColor='white',
                             fontFactory=self.fontFactory),
              Distortions.SineWarp()))
コード例 #8
0
ファイル: Tests.py プロジェクト: zschuan1230/wswp_places
 def getLayers(self):
     word = Words.defaultWordList.pick()
     self.addSolution(word)
     return [
         Backgrounds.TiledImage(),
         Backgrounds.RandomDots(),
         Text.TextLayer(word, borderSize=1),
         Distortions.WigglyBlocks(),
         ]
コード例 #9
0
ファイル: views.py プロジェクト: lerouxb/seymour
 def getLayers(self):
     return [
         Backgrounds.SolidColor(),
         Backgrounds.Grid(size=10),            
         Distortions.SineWarp(amplitudeRange=(3, 5.0)),
         Text.TextLayer(self.word, borderSize=0),            
         Backgrounds.RandomDots(dotSize=2, numDots=800),
         Distortions.SineWarp(amplitudeRange=(3, 6.0)),
     ]
コード例 #10
0
 def get_layers(self, word):
     return [
         Backgrounds.TiledImage(),
         Backgrounds.RandomDots(),
         Text.TextLayer(word,
                        borderSize=1,
                        fontFactory=self.get_font_factory()),
         #            Distortions.WigglyBlocks(),
     ]
コード例 #11
0
    def get_layers(self, word):
        textLayer = Text.TextLayer(word,
                                   borderSize=1,
                                   fontFactory=self.fontFactory)

        return [
            Backgrounds.CroppedImage(),
            textLayer,
            Distortions.SineWarp(amplitudeRange=(2, 4)),
        ]
コード例 #12
0
 def getLayers(self):
     word = Words.defaultWordList.pick()
     self.addSolution(word)
     return [
         random.choice([
             Backgrounds.CroppedImage(),
             Backgrounds.TiledImage(),
         ]),
         Text.TextLayer(word, borderSize=1)
     ]
コード例 #13
0
 def get_layers(self, word):
     return [
         random.choice([
             Backgrounds.CroppedImage(),
             Backgrounds.TiledImage(),
         ]),
         Text.TextLayer(word,
                        borderSize=1,
                        fontFactory=self.get_font_factory()),
         Distortions.SineWarp(),
     ]
コード例 #14
0
ファイル: captcha.py プロジェクト: yangzxstar/reddit
class RandCaptcha(ImageCaptcha):
    defaultSize = (120, 50)
    fontFactory = Text.FontFactory(18, "vera/VeraBd.ttf")

    def getLayers(self, solution="blah"):
        self.addSolution(solution)
        return ((Backgrounds.Grid(size=8, foreground="white"),
                 Distortions.SineWarp(amplitudeRange=(5, 9))),
                (Text.TextLayer(solution,
                                textColor='white',
                                fontFactory=self.fontFactory),
                 Distortions.SineWarp()))
コード例 #15
0
ファイル: Tests.py プロジェクト: zschuan1230/wswp_places
    def getLayers(self, solution="*****@*****.**"):
        self.addSolution(solution)

        textLayer = Text.TextLayer(solution,
                                   borderSize = 2,
                                   fontFactory = self.fontFactory)

        return [
            Backgrounds.CroppedImage(),
            textLayer,
            Distortions.SineWarp(amplitudeRange = (2, 4)),
            ]
コード例 #16
0
ファイル: captcha.py プロジェクト: yayoec/python
    def getLayers(self):
        self.addSolution(self.solution)

        textLayer = Text.TextLayer(self.solution,
                                   borderSize=1,
                                   fontFactory=self.fontFactory)

        return [
            random.choice([Backgrounds.TiledImage()]),
            textLayer,
            Distortions.SineWarp(),
        ]
コード例 #17
0
ファイル: captcha.py プロジェクト: yayoec/python
    def getLayers(self):
        self.addSolution(self.solution)

        textLayer = Text.TextLayer(self.solution,
                                   borderSize=2,
                                   fontFactory=self.fontFactory)

        return [
            Backgrounds.CroppedImage(),
            textLayer,
            Distortions.SineWarp(amplitudeRange=(1, 1)),
        ]
コード例 #18
0
ファイル: FCCaptcha.py プロジェクト: samyisok/orphereus
 def getLayers(self):
     word = self.word
     ff = Text.FontFactory(26, self.font)
     bg = random.choice([
         Backgrounds.SolidColor(),
         Backgrounds.CroppedImage(),
         Backgrounds.TiledImage(),
     ])
     bg = (bg, Backgrounds.Grid(),
           Distortions.SineWarp(amplitudeRange=(6, 10),
                                periodRange=(0.1, 0.4)))
     layers = [
         bg,
     ]
     if not self.easyMode:
         layers.append(Backgrounds.RandomDots())
     layers.extend([  #Distortions.WigglyBlocks(),
         Text.TextLayer(word, borderSize=1, fontFactory=ff),
         Distortions.SineWarp()
         #Distortions.SineWarp()
     ])
     return layers
コード例 #19
0
class AntiSpam(BaseRender):
    fontFactory = Text.FontFactory(20, "vera/VeraBd.ttf")

    def get_layers(self, word):
        textLayer = Text.TextLayer(word,
                                   borderSize=1,
                                   fontFactory=self.fontFactory)

        return [
            Backgrounds.CroppedImage(),
            textLayer,
            Distortions.SineWarp(amplitudeRange=(2, 4)),
        ]
コード例 #20
0
ファイル: captcha.py プロジェクト: yayoec/python
    def getLayers(self):
        self.addSolution(self.solution)

        textLayer = Text.TextLayer(self.solution,
                                   borderSize=1,
                                   fontFactory=self.fontFactory)

        return [  # random.choice([ Backgrounds.TiledImage() ]),
            [
                Backgrounds.SolidColor('white'),
                Backgrounds.RandomDots(
                    colors=['yellow', 'blue', 'green', 'red'], numDots=10)
            ],
            textLayer,
            Distortions.SineWarp(),
        ]
コード例 #21
0
ファイル: Tests.py プロジェクト: zschuan1230/wswp_places
class AntiSpam(ImageCaptcha):
    """A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
    fontFactory = Text.FontFactory(20, "vera/VeraBd.ttf")
    defaultSize = (512,50)

    def getLayers(self, solution="*****@*****.**"):
        self.addSolution(solution)

        textLayer = Text.TextLayer(solution,
                                   borderSize = 2,
                                   fontFactory = self.fontFactory)

        return [
            Backgrounds.CroppedImage(),
            textLayer,
            Distortions.SineWarp(amplitudeRange = (2, 4)),
            ]
コード例 #22
0
class BaseRender(object):
    defaultSize = (100, 30)
    defaultfontfactory = Text.FontFactory(20, "vera")

    def __init__(self):
        self.fontfactory = None
        self._word = None

    def render(self, word=None, size=None):
        if size is None:
            size = self.defaultSize
        if not word:
            word = self.word
        return word, self.__do_render(self.get_layers(word),
                                      Image.new("RGB", size))

    def get_layers(self, word):
        return self.renderlist

    def set_font_factory(self, factory):
        self.fontfactory = factory

    def get_font_factory(self):
        if not self.fontfactory:
            return self.defaultfontfactory
        return self.fontfactory

    def __get_word(self):
        if not self._word:
            self._word = Words.defaultWordList.pick()
        return self._word

    word = property(__get_word)

    def __do_render(self, _list, img):
        for i in _list:
            if isinstance(i, (tuple, list)):
                img = self.__do_render(img)
            else:
                img = i.render(img) or img
        return img