~osomon/phatch/extract-all-metadata

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# Phatch - Photo Batch Processor
# Copyright (C) 2007-2008 www.stani.be
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see http://www.gnu.org/licenses/
#
# Phatch recommends SPE (http://pythonide.stani.be)
# for editing python files.

# Embedded icon is taken from www.openclipart.org (public domain)

from core import models
from lib.reverse_translation import _t
from core.pil import open_image
from lib.imtools import has_transparency

#---Pil
def init():
    global Image, ImageMath
    import Image
    import ImageMath
    
def put_highlight(image,highlight,resample_highlight,opacity,
        cache=None):
    if cache is None:
        cache   = {}
    resample_highlight  = getattr(Image,resample_highlight)
    id      = 'highlight_%s_w%d_h%d_o%d'\
        %(highlight,image.size[0],image.size[1],opacity)
    try:
        highlight    = cache[id]
    except KeyError:
        highlight    = open_image(highlight)\
            .convert('RGBA').resize(image.size,resample_highlight)
        if opacity < 100:
            #apply opacity
            highlight_alpha = highlight.split()[3]
            opacity         = (255*opacity)/100
            highlight.putalpha(ImageMath.eval("convert((a*o)/255, 'L')", 
                a=highlight_alpha, o=opacity))
        #store in cache
        cache[id]   = highlight
    if not has_transparency(image):
        image = image.convert('RGBA')
    else:
        if has_transparency(image):
            image = image.convert('RGBA')
        alpha = image.split()[-1]
        highlight = highlight.copy()
        highlight_alpha = highlight.split()[3]
        highlight.putalpha(ImageMath.eval("convert(min(a, b), 'L')", 
            a=alpha, b=highlight_alpha))

    overlay = highlight.convert('RGB')
    image.paste(overlay, mask=highlight)
    return image

#---Phatch
class Action(models.Action):
    """Apply a transparency highlight"""
    
    label       = _t('Highlight')
    author      = 'Nadia Alramli'
    cache       = True
    email       = 'mail@nadiana.com'
    init        = staticmethod(init)
    pil         = staticmethod(put_highlight)
    version     = '0.1'
    tags        = [_t('watermark'),_t('border'),_t('colors')]
    __doc__     = _t('Apply a transparency highlight')
    
    def interface(self,fields):
        fields[_t('Highlight')]          = self.HighlightFileField('Sphere Top')
        fields[_t('Resample Highlight')] = self.ImageResampleField('antialias')
        fields[_t('Opacity')]            = self.SliderField(100,0,100)
        
    icon  = \
'x\xda\x01\x16\x0c\xe9\xf3\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\
\x00\x00\x000\x08\x06\x00\x00\x00W\x02\xf9\x87\x00\x00\x00\x04sBIT\x08\x08\
\x08\x08|\x08d\x88\x00\x00\x0b\xcdIDATh\x81\xcd\x9ai\x90\\\xd7U\xc7\x7f\xe7\
\xde\xfbz\x9d\x9eU#\x8d\xac\xb1v)\xdee\x13KX\xc6\x10\x8b"\xc6\xc1\x86\x98T\
\xe2\x00\x05)\xa0\xd8R&!\xc5\x07\x9b\xf0\x01\xc3\x07\x8aJ\xc0\x05T\xc5\tUvQ\
\x80\x8b\x80\x81\x908\xc1\xc1\xc6K\x82c\x82%\'Q\xd9\x89\x8cdY#\xcb\xd1\xaeY\
\xba{\xba\xa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