IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Django Python Discussion :

Probleme script watermark django


Sujet :

Django Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 29
    Points : 17
    Points
    17
    Par défaut Probleme script watermark django
    Le probleme est qu'il ne trouve pas le modules "utils.consts" , sauriez-vous comment l'installer sur windows ?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    from PIL import Image, ImageEnhance
     
    from Utils.consts import MARK_IMG, PADDING
     
    def reduce_opacity(img, opacity):   
        """Returns an image with reduced opacity."""
     
        assert opacity >= 0 and opacity <= 1
        if img.mode != 'RGBA':
            img = img.convert('RGBA')
        else:
            img = img.copy()
        alpha = img.split()[3]
        alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
        img.putalpha(alpha)
     
        return img
     
    def watermark(img, mark_img = MARK_IMG, position = 'bottom-right', opacity = 0.6):
        """Adds a watermark to an image."""
     
        img = Image.open(img)
        mark = Image.open(mark_img)
     
        img_w_p = img.size[0] - PADDING
        if img_w_p < mark.size[0]:
            ratio = float(img_w_p) / mark.size[0]
            w = int(mark.size[0] * ratio)
            h = int(mark.size[1] * ratio)
            mark = mark.resize((w, h))
     
        if opacity < 1:
            mark = reduce_opacity(mark, opacity)
     
        if img.mode != 'RGBA':
            img = img.convert('RGBA')
     
        # create a transparent layer the size of the image and draw the watermark in that layer.
        layer = Image.new('RGBA', img.size, (0,0,0,0))
     
        if position == 'over':
            for y in xrange(0, img.size[1], mark.size[1]):
                for x in xrange(0, img.size[0], mark.size[0]):
                    layer.paste(mark, (x, y))
        elif position == 'title':
            # title, but preserve the aspect ratio
            ratio = min(float(img.size[0]) / mark.size[0], float(img.size[1]) / mark.size[1])
            w = int(mark.size[0] * ratio)
            h = int(mark.size[1] * ratio)
            mark = mark.resize((w, h))
            # layer.paste(mark, ((img.size[0] - w) / 2, (img.size[1] - h) / 2))
            layer.paste(mark, ((img.size[0] - w) / 2, 0))
        elif position == 'top-left':
            position = (PADDING, PADDING)
            layer.paste(mark, position)
        elif position == 'top-right':
            position = (img.size[0] - mark.size[0] - PADDING, PADDING)
            layer.paste(mark, position)
        elif position == 'center':
            position = ((img.size[0] - mark.size[0])/2, (img.size[1] - mark.size[1])/2)
            layer.paste(mark, position)
        elif position == 'bottom-left':
            position = (PADDING, img.size[1] - mark.size[1]  -PADDING,)
            layer.paste(mark, position)
        else: # 'bottom-right' (default)
            position = (img.size[0] - mark.size[0] - PADDING, img.size[1] - mark.size[1] - PADDING,)
            layer.paste(mark, position)
     
        return Image.composite(layer, img, layer)
     
    def test():
        watermark('3.jpg',MARK_IMG,'LEFT_TOP',opacity=0.7).save("watermarked_lt.jpg",quality=90)
        watermark('3.jpg',MARK_IMG,'RIGHT_TOP',opacity=0.7).save("watermarked_rt.jpg",quality=90)
        watermark('3.jpg',MARK_IMG,'CENTER',opacity=0.7).save("watermarked_center.jpg",quality=90)
        watermark('3.jpg',MARK_IMG,'LEFT_BOTTOM',opacity=0.7).save("watermarked_lb.jpg",quality=90)
        watermark('3.jpg',MARK_IMG,'RIGHT_BOTTOM',opacity=0.7).save("watermarked_rb.jpg",quality=90)
        watermark('3.jpg',MARK_IMG,'OVER',opacity=0.7).save("watermarked_o.jpg",quality=90)
        watermark('3.jpg',MARK_IMG,'TITLE',opacity=0.7).save("watermarked_title.jpg",quality=90)
     
    if __name__ == '__main__':
        test()

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    De quel "Utils" parles-tu ?

    Avec un nom comme ça, Google nous inonde.

    Tu as un lien pour cet "Utils" ?

Discussions similaires

  1. [Javascript] probleme script d'impression
    Par pimpmyride dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 07/03/2006, 14h37
  2. Problème script de chargement de données oracle
    Par nkongolo.m dans le forum Linux
    Réponses: 4
    Dernier message: 24/01/2006, 11h46
  3. petit probleme script heure et date
    Par ion dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 08/12/2005, 20h47
  4. Problème scripting
    Par mlequim dans le forum Linux
    Réponses: 15
    Dernier message: 08/08/2005, 17h04
  5. Problème script Bash
    Par Sphost dans le forum Linux
    Réponses: 10
    Dernier message: 26/07/2005, 09h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo