Skip to content

Commit 4ad5e82

Browse files
clsungbe-hase
authored andcommitted
Support 2017/11/30 "New options for template message images" (#90)
* Support 2017/11/30 "New options for template message images" Support the following image options for buttons/carousel template message: - imageAspectRatio - imageSize - imageBackgroundColor * flake8, E231 * default None for image options
1 parent 549fe6b commit 4ad5e82

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

linebot/models/template.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ class ButtonsTemplate(Template):
100100
Template message with an image, title, text, and multiple action buttons.
101101
"""
102102

103-
def __init__(self, text=None, title=None, thumbnail_image_url=None, actions=None, **kwargs):
103+
def __init__(self, text=None, title=None, thumbnail_image_url=None,
104+
image_aspect_ratio=None,
105+
image_size=None, image_background_color=None,
106+
actions=None, **kwargs):
104107
"""__init__ method.
105108
106109
:param str text: Message text.
@@ -114,6 +117,19 @@ def __init__(self, text=None, title=None, thumbnail_image_url=None, actions=None
114117
Aspect ratio: 1:1.51
115118
Max width: 1024px
116119
Max: 1 MB
120+
:param str image_aspect_ratio: Aspect ratio of the image.
121+
Specify one of the following values:
122+
rectangle: 1.51:1
123+
square: 1:1
124+
:param str image_size: Size of the image.
125+
Specify one of the following values:
126+
cover: The image fills the entire image area.
127+
Parts of the image that do not fit in the area are not displayed.
128+
contain: The entire image is displayed in the image area.
129+
A background is displayed in the unused areas to the left and right
130+
of vertical images and in the areas above and below horizontal images.
131+
:param str image_background_color: Background color of image.
132+
Specify a RGB color value.
117133
:param actions: Action when tapped.
118134
Max: 4
119135
:type actions: list[T <= :py:class:`linebot.models.template.TemplateAction`]
@@ -125,6 +141,9 @@ def __init__(self, text=None, title=None, thumbnail_image_url=None, actions=None
125141
self.text = text
126142
self.title = title
127143
self.thumbnail_image_url = thumbnail_image_url
144+
self.image_aspect_ratio = image_aspect_ratio
145+
self.image_size = image_size
146+
self.image_background_color = image_background_color
128147
self.actions = _get_actions(actions)
129148

130149

@@ -161,12 +180,24 @@ class CarouselTemplate(Template):
161180
Template message with multiple columns which can be cycled like a carousel.
162181
"""
163182

164-
def __init__(self, columns=None, **kwargs):
183+
def __init__(self, columns=None, image_aspect_ratio=None,
184+
image_size=None, **kwargs):
165185
"""__init__ method.
166186
167187
:param columns: Array of columns.
168-
Max: 5
188+
Max: 10
169189
:type columns: list[T <= :py:class:`linebot.models.template.CarouselColumn`]
190+
:param str image_aspect_ratio: Aspect ratio of the image.
191+
Specify one of the following values:
192+
rectangle: 1.51:1
193+
square: 1:1
194+
:param str image_size: Size of the image.
195+
Specify one of the following values:
196+
cover: The image fills the entire image area.
197+
Parts of the image that do not fit in the area are not displayed.
198+
contain: The entire image is displayed in the image area.
199+
A background is displayed in the unused areas to the left and right
200+
of vertical images and in the areas above and below horizontal images.
170201
:param kwargs:
171202
"""
172203
super(CarouselTemplate, self).__init__(**kwargs)
@@ -180,6 +211,8 @@ def __init__(self, columns=None, **kwargs):
180211
column, CarouselColumn
181212
))
182213
self.columns = new_columns
214+
self.image_aspect_ratio = image_aspect_ratio
215+
self.image_size = image_size
183216

184217

185218
class ImageCarouselTemplate(Template):
@@ -194,7 +227,7 @@ def __init__(self, columns=None, **kwargs):
194227
"""__init__ method.
195228
196229
:param columns: Array of columns.
197-
Max: 5
230+
Max: 10
198231
:type columns: list[T <= :py:class:`linebot.models.template.ImageCarouselColumn`]
199232
:param kwargs:
200233
"""
@@ -217,7 +250,8 @@ class CarouselColumn(Base):
217250
https://devdocs.line.me/en/#column-object
218251
"""
219252

220-
def __init__(self, text=None, title=None, thumbnail_image_url=None, actions=None, **kwargs):
253+
def __init__(self, text=None, title=None, thumbnail_image_url=None,
254+
image_background_color=None, actions=None, **kwargs):
221255
"""__init__ method.
222256
223257
:param str text: Message text.
@@ -231,6 +265,8 @@ def __init__(self, text=None, title=None, thumbnail_image_url=None, actions=None
231265
Aspect ratio: 1:1.51
232266
Max width: 1024px
233267
Max: 1 MB
268+
:param str image_background_color: Background color of image.
269+
Specify a RGB color value.
234270
:param actions: Action when tapped.
235271
Max: 3
236272
:type actions: list[T <= :py:class:`linebot.models.template.TemplateAction`]
@@ -241,6 +277,7 @@ def __init__(self, text=None, title=None, thumbnail_image_url=None, actions=None
241277
self.text = text
242278
self.title = title
243279
self.thumbnail_image_url = thumbnail_image_url
280+
self.image_background_color = image_background_color
244281
self.actions = _get_actions(actions)
245282

246283

tests/api/test_send_template_message.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def setUp(self):
6565
"type": "buttons",
6666
"thumbnailImageUrl":
6767
"https://example.com/image.jpg",
68+
"imageAspectRatio": None,
69+
"imageSize": None,
70+
"imageBackgroundColor": None,
6871
"title": "Menu",
6972
"text": "Please select",
7073
"actions": [
@@ -151,6 +154,7 @@ def setUp(self):
151154
CarouselColumn(
152155
thumbnail_image_url='https://example.com'
153156
'/item2.jpg',
157+
image_background_color='#000000',
154158
title='this is menu2', text='description2',
155159
actions=[
156160
PostbackTemplateAction(
@@ -210,6 +214,7 @@ def setUp(self):
210214
{
211215
"thumbnailImageUrl":
212216
"https://example.com/item1.jpg",
217+
"imageBackgroundColor": None,
213218
"title": "this is menu1",
214219
"text": "description1",
215220
"actions": [
@@ -234,6 +239,7 @@ def setUp(self):
234239
{
235240
"thumbnailImageUrl":
236241
"https://example.com/item2.jpg",
242+
"imageBackgroundColor": "#000000",
237243
"title": "this is menu2",
238244
"text": "description2",
239245
"actions": [
@@ -258,6 +264,7 @@ def setUp(self):
258264
{
259265
"thumbnailImageUrl":
260266
"https://example.com/item3.jpg",
267+
"imageBackgroundColor": None,
261268
"title": "this is menu3",
262269
"text": "description3",
263270
"actions": [
@@ -290,7 +297,9 @@ def setUp(self):
290297
}
291298
]
292299
}
293-
]
300+
],
301+
"imageAspectRatio": None,
302+
"imageSize": None
294303
}
295304
}]
296305

0 commit comments

Comments
 (0)