-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimage_transform.py
More file actions
54 lines (49 loc) · 2.15 KB
/
image_transform.py
File metadata and controls
54 lines (49 loc) · 2.15 KB
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
"""
The Image Delivery API is used to retrieve, manipulate and/or convert image
files of your Contentstack account and deliver it to your web or mobile properties.
It is an second parameter in which we want to place different manipulation key and
value in array form ImageTransform method is define for image manipulation with
different transform_params in second parameter in array form
"""
import logging
class ImageTransform: # pylint: disable=too-few-public-methods
"""
The Image Delivery API is used to retrieve, manipulate and/or convert image
files
"""
def __init__(self, http_instance, image_url, logger=None, **kwargs):
"""
creates instance of the ImageTransform class
:param httpInstance: instance of HttpsConnection
:param image_url: url on which manipulation required, Image transformation url
:param kwargs: parameter in which we want to place different
manipulation key-worded, variable-length argument list
------------------------------
Example::
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> stack.image_transform('image_url', width=100, height=100)
------------------------------
"""
super().__init__()
self.http_instance = http_instance
self.image_url = image_url
self.image_params = kwargs
self.logger = logger or logging.getLogger(__name__)
def get_url(self):
"""
Returns a complete url after concatenate with parameters
:return: updated asset url
------------------------------
Example::
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> image_url = stack.image_transform('image_url', width=100, height=100)
>>> result = image_url.fetch()
------------------------------
"""
args = ['{0}={1}'.format(k, v)
for k, v in list(self.image_params.items())]
if args:
self.image_url += '?{0}'.format('&'.join(args))
return self.image_url