MCPcopy Create free account
hub / github.com/Sygil-Dev/sygil-webui / createHTMLGallery

Function createHTMLGallery

scripts/imglab.py:132–170  ·  view source on GitHub ↗
(images)

Source from the content-addressed store, hash-verified

130
131
132def createHTMLGallery(images):
133 html3 = """
134 <div class="gallery-history" style="
135 display: flex;
136 flex-wrap: wrap;
137 align-items: flex-start;">
138 """
139 mkdwn_array = []
140 for i in images:
141 bImg = i.read()
142 i = Image.save(bImg, "PNG")
143 width, height = i.size
144 # get random number for the id
145 image_id = "%s" % (str(images.index(i)))
146 (data, mimetype) = STImage._normalize_to_bytes(bImg.getvalue(), width, "auto")
147 this_file = in_memory_file_manager.add(data, mimetype, image_id)
148 img_str = this_file.url
149 # img_str = 'data:image/png;base64,' + b64encode(image_io.getvalue()).decode('ascii')
150 # get image size
151
152 # make sure the image is not bigger then 150px but keep the aspect ratio
153 if width > 150:
154 height = int(height * (150 / width))
155 width = 150
156 if height > 150:
157 width = int(width * (150 / height))
158 height = 150
159
160 # mkdwn = f"""<img src="{img_str}" alt="Image" with="200" height="200" />"""
161 mkdwn = f"""<div class="gallery" style="margin: 3px;" >
162<a href="{img_str}">
163<img src="{img_str}" alt="Image" width="{width}" height="{height}">
164</a>
165</div>
166"""
167 mkdwn_array.append(mkdwn)
168 html3 += "".join(mkdwn_array)
169 html3 += "</div>"
170 return html3
171
172
173def layout():

Callers

nothing calls this directly

Calls 2

saveMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected