8
8
AspectRatioValidationError , AnalyzeError
9
9
from .helpers import validate_width_height_ratio , deprecated
10
10
from .mimetypes_ import guess_extension , guess_type
11
- from .optionals import magic_mime_from_buffer , ensure_wand
11
+ from .optionals import magic_mime_from_buffer
12
12
from .typing_ import Dimension
13
13
14
14
@@ -95,89 +95,6 @@ def process(self, descriptor: StreamDescriptor, context: dict):
95
95
)
96
96
97
97
98
- @deprecated
99
- class WandAnalyzer (Analyzer ):
100
- """
101
- .. deprecated:: 0.16
102
-
103
- .. versionadded:: 0.4
104
-
105
- .. versionchanged:: 0.5
106
-
107
- - Inherited from :class:`.Analyzer`
108
- - The ``analyze`` method renamed to ``process`` to override the parent
109
- method.
110
-
111
- Analyze an image using ``wand``.
112
-
113
- .. warning:: Installing ``wand`` is required for using this class.
114
- otherwise, an :exc:`.OptionalPackageRequirementError` will be
115
- raised.
116
-
117
- Use it as follow
118
-
119
- .. testcode::
120
-
121
- from sqlalchemy import TypeDecorator, Unicode, Column, Integer
122
- from sqlalchemy.ext.declarative import declarative_base
123
- from sqlalchemy.dialects.postgresql import JSONB
124
-
125
- from sqlalchemy_media import Image, WandAnalyzer
126
-
127
-
128
- class ProfileImage(Image):
129
- __pre_processors__ = WandAnalyzer()
130
-
131
- Base = declarative_base()
132
-
133
- class Member(Base):
134
- __tablename__ = 'person'
135
-
136
- id = Column(Integer, primary_key=True)
137
- avatar = Column(ProfileImage.as_mutable(JSONB))
138
-
139
- The use it inside :class:`.ContextManager` context:
140
-
141
- ::
142
-
143
- from sqlalchemy_media import ContextManager
144
-
145
- session = <....>
146
-
147
- with ContextManager(session):
148
- me = Member(avatar=ProfileImage.create_from('donkey.jpg'))
149
- print(me.avatar.width)
150
- print(me.avatar.height)
151
- print(me.avatar.content_type)
152
-
153
- .. note:: This object currently selects ``width``, ``height`` and
154
- ``mimetype`` of the image.
155
-
156
- """
157
-
158
- def process (self , descriptor : StreamDescriptor , context : dict ):
159
- ensure_wand ()
160
- from wand .image import Image as WandImage
161
- from wand .exceptions import WandException
162
-
163
- # This processor requires seekable stream.
164
- descriptor .prepare_to_read (backend = 'memory' )
165
-
166
- try :
167
- with WandImage (file = descriptor )as img :
168
- context .update (
169
- width = img .width ,
170
- height = img .height ,
171
- content_type = img .mimetype
172
- )
173
-
174
- except WandException :
175
- raise AnalyzeError (str (WandException ))
176
-
177
- # prepare for next processor, calling this method is not bad.
178
- descriptor .prepare_to_read (backend = 'memory' )
179
-
180
-
181
98
class Validator (Processor ):
182
99
"""
183
100
@@ -360,39 +277,16 @@ class ImageProcessor(Processor):
360
277
- If you pass both ``width`` and ``height``, aspect ratio may not be
361
278
preserved.
362
279
363
- :param fmt: This argument will be directly passing to ``Wand`` or
364
- ``Pillow``. so, for list of available choices, see:
365
- `ImageMagic Documentation
366
- <http://www.imagemagick.org/script/formats.php>`_
367
-
280
+ :param format: The image format. i.e jpeg, gif, png
368
281
:param width: The new image width.
369
282
:param height: The new image height.
370
283
:param crop: Used to crop the image.
371
284
372
285
.. versionadded:: 0.6
373
286
374
- The crop dimension as a dictionary containing the keys described
375
- `here <http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.BaseImage.crop>`_.
376
-
377
- Including you can
378
- use percent ``%`` sing to automatically calculate the values from original
379
- image dimension::
287
+ The crop argument is 4-tuple of (left, top, right, bottom)
380
288
381
- ImageProcessor(crop=dict(width='50%', height='50%', gravity='center'))
382
- ImageProcessor(crop=dict(width='10%', height='10%', gravity='south_east'))
383
-
384
- Or::
385
-
386
- ImageProcessor(crop=dict(
387
- top='10%',
388
- bottom='10%',
389
- left='10%',
390
- right='10%',
391
- width='80%',
392
- height='80%'
393
- ))
394
-
395
- Included from wand documentation::
289
+ ImageProcessor(crop=(10, 10, 120, 230))
396
290
397
291
+--------------------------------------------------+
398
292
| ^ ^ |
@@ -410,12 +304,6 @@ class ImageProcessor(Processor):
410
304
| <--------------- right ----------> |
411
305
+--------------------------------------------------+
412
306
413
- .. seealso::
414
-
415
- - ``crop`` `method <http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.BaseImage.crop>`_. # noqa
416
- - ``gravity`` `argument <http://docs.wand-py.org/en/0.4.1/wand/image.html#wand.image.GRAVITY_TYPES>`_.
417
- - `Wand <http://docs.wand-py.org/>`_
418
-
419
307
"""
420
308
421
309
def __init__ (self , fmt : str = None , width : int = None , height : int = None , crop = None ):
@@ -489,9 +377,6 @@ class ImageAnalyzer(Analyzer):
489
377
Analyze an image using available image library by calling the
490
378
:classmethod:`.imaging.ImagingLibrary.get_available()
491
379
492
- .. warning:: If none of ``Wand`` or ``Pillow`` are installed the
493
- :exc:`.OptionalPackageRequirementError` will be raised.
494
-
495
380
.. note:: This object currently selects ``width``, ``height`` and
496
381
``mimetype`` of an image.
497
382
0 commit comments