-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathoptimize.py
More file actions
165 lines (144 loc) · 4.96 KB
/
optimize.py
File metadata and controls
165 lines (144 loc) · 4.96 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
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
import json
from logging import NOTSET, lastResort
# read from .env file
from dotenv import load_dotenv
load_dotenv()
import cloudinary
from cloudinary.utils import cloudinary_url
# get reference to config instance, return "https" URLs by setting secure=True
config = cloudinary.config(secure=True)
print(config.cloud_name)
print(config.api_key)
# Log the configuration
# ==============================
print("**** Set up and configure the SDK:****\n",
config.cloud_name, config.api_key, "\n")
# DOCS: https://cloudinary.com/documentation/image_transformations
# Resize an asset
# url, options = cloudinary_url(
# "llama",
# width=500,
# crop="scale"
# )
# print("****Resize: Transform to scale down, maintaining original aspect ratio****\nTransformation URL --> " + url, "\n")
# Crop an asset
# url, options = cloudinary_url(
# "cld-sample",
# height=800,
# width=800,
# crop="fill"
# )
# print("**** Crop an asset****\nTransformation URL --> " + url, "\n")
# Crop with gravity
# url, options = cloudinary_url(
# "cld-sample",
# width=800,
# height=800,
# crop="thumb",
# gravity="auto"
# )
# print("**** Crop with Gravity ****\nTransformation URL --> " + url, "\n")
# Auto format
# url, options = cloudinary_url(
# "sealion",
# width=600,
# height=800,
# crop="fill",
# fetch_format="auto"
# )
# print("**** Auto Format ****\nTransformation URL --> " + url, "\n")
# Auto quality
# url, options = cloudinary_url(
# "sealion",
# width=600,
# height=800,
# crop="fill",
# quality="auto"
# )
# print("**** Auto Quality ****\nTransformation URL --> " + url, "\n")
# Auto format, Auto quality, Auto Gravity - Cloudinary's special sauce
url, options = cloudinary_url(
"cld-sample",
width=600,
height=800,
crop="fill",
gravity="auto",
fetch_format="auto",
quality="auto",
)
print("**** Auto Format, Auto Quality, Auto Gravity - Both ****\nTransformation URL --> " + url, "\n")
# Rounding
# url, options = cloudinary_url(
# "puma",
# width=300,
# height=300,
# crop="thumb",
# gravity="auto",
# radius="max"
# )
# print("**** Rounding the corners of an asset with 1:1 aspect ratio****\nTransformation URL --> " + url, "\n")
# Borders
# url, options = cloudinary_url(
# "iguana",
# width=300,
# height=300,
# crop="fill",
# gravity="auto",
# border="10px_solid_green"
# )
# print("**** Adding a green border to an asset ****\nTransformation URL --> " + url, "\n")
# Auto background color
# url, options = cloudinary_url(
# "llama",
# width=400,
# height=400,
# crop="pad",
# quality="auto",
# background="auto"
# )
# print("**** Adding an automatic background color to a padded crop, based on one or more predominant colors in the asset****\nTransformation URL --> " + url, "\n")
# Color effect
# url, options = cloudinary_url(
# "cld-sample",
# height=300,
# crop="scale",
# quality="auto",
# effect="tint:40:gold"
# )
# print("**** Add Color Effect ****\nTransformation URL --> " + url, "\n")
# Improve effect
# url, options = cloudinary_url(
# "i-love-ants",
# height=400,
# crop="scale",
# effect="improve:outdoor"
# )
# print("**** Improve effect for an outdoor asset ****\nTransformation URL --> " + url, "\n")
# Artistic filter
# url, options = cloudinary_url(
# "puma",
# height=400,
# crop="scale",
# effect="art:hairspray"
# )
# print("**** Add the artistic effect, hairspray ****\nTransformation URL --> " + url, "\n")
# Overlays - Text over image
# url, options = cloudinary_url("cld-sample",
# transformation=[
# {'crop': 'fill', 'width': 500},
# {'quality': 'auto'},
# {'color': "#FFFFFF", 'overlay': {'font_family': "arial", 'font_size': 30, 'font_weight': "bold",
# 'text_decoration': "underline", 'letter_spacing': 3, 'text': "Dalmation!"}},
# {'flags': "layer_apply",
# 'gravity': "north_east", 'y': 10, 'x': 10}
# ])
# print("**** Overlay - Transform to add text over image in the top right corner ****\nTransformation URL --> " + url, "\n")
# Overlays - Image over video
# url, options = cloudinary_url("tortoise", resource_type="video",
# transformation=[
# {'crop': 'fill', 'width': 500},
# {'overlay': 'cld-training-logo'},
# {'flags': "layer_apply", 'gravity': "north_east", 'y': 10, 'x': 10, 'width':100, 'opacity':50},
# {'quality': 'auto'}
# ])
# print("**** Overlay - Transform to add a Cloudinary logo overlay to the north east corner of an video ****\nTransformation URL --> " + url, "\n")