|
''' |
|
title: Image |
|
''' |
|
|
|
import simplestart as ss |
|
|
|
import cv2 |
|
from PIL import Image |
|
import os |
|
|
|
ss.md("## ss.image") |
|
|
|
ss.md(''' |
|
#### π
Example |
|
''') |
|
|
|
ss.space() |
|
|
|
img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" |
|
|
|
cols = ss.columns([60,"flex:40"], border=True) |
|
with cols[0]: |
|
mytext = ss.text("This is image") |
|
ss.space() |
|
myimg = ss.image(img, fit="contain", width=300, height=300) |
|
ss.text("Image fit mode: @fit_str") |
|
|
|
def onradiochange(event): |
|
|
|
|
|
ss.session["fit_str"] = event.value |
|
myimg.fit = event.value |
|
|
|
|
|
def onradiochange2(event): |
|
value = event.value |
|
index = event.index |
|
|
|
source = ["Http", "PIL", "OpenCV", "Local"] |
|
ss.session["source_str"] = source[index] |
|
|
|
|
|
if index == 0: |
|
img = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" |
|
ss.session["image_path"] = "\"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg\"" |
|
myimg.image = img |
|
if index == 1: |
|
image = Image.open('./media/image/dalao.jpeg') |
|
ss.session["image_path"] = "Image.open('./media/image/dalao.jpeg')" |
|
myimg["image"] = image |
|
if index == 2: |
|
img = cv2.imread('./media/image/cat.jpeg',cv2.IMREAD_COLOR) |
|
ss.session["image_path"] = "cv2.imread('./media/image/cat.jpeg',cv2.IMREAD_COLOR)" |
|
myimg.image = img |
|
if index == 3: |
|
file_path = './media/image/dog.jpeg' |
|
ss.session["image_path"] = "\"./media/image/dog.jpeg\"" |
|
myimg.image = file_path |
|
|
|
def sel_change(event): |
|
myimg.border = "border" in event.value |
|
|
|
if "title" in event.value: |
|
myimg.title = "Title of image" |
|
else: |
|
myimg.title = "" |
|
|
|
if "elevation" in event.value: |
|
myimg.elevation = 12 |
|
else: |
|
myimg.elevation = 0 |
|
|
|
with cols[1]: |
|
ss.text("Image fit mode") |
|
ss.radio(["fill", "contain", "cover", "none", "scale-down"], index = 1, inline = True, onchange=onradiochange) |
|
ss.space() |
|
ss.text("Image source") |
|
ss.radio(["Http image","PIL image", "OpenCV image", "Local image"], index = 0, inline = True, onchange=onradiochange2) |
|
|
|
ss.md("---") |
|
ss.selectbox(["border", "title", "elevation"], label = "Others", multiple = True, onchange = sel_change) |
|
|
|
ss.space() |
|
|
|
ss.write(''' |
|
#### π Code |
|
''') |
|
|
|
ss.md(''' |
|
```python |
|
import simplestart as ss |
|
import cv2 |
|
from PIL import Image |
|
|
|
img = @image_path |
|
ss.image(img, fit="@fit_str") |
|
``` |
|
''') |
|
|
|
def onPageLoad(): |
|
ss.session["fit_str"] = "contain" |
|
ss.session["source_str"] = "Http" |
|
ss.session["image_path"] = "\"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg\"" |