コンテンツにスキップ
quickthumb
すべてのドキュメント

図形

.shape()は位置を指定して、長方形、楕円、カプセル、三角形、星、多角形を追加します。

シグネチャ

canvas.shape(
    shape,
    position,
    width,
    height,
    color,
    fill=None,
    border_radius=0,
    opacity=1.0,
    rotation=0.0,
    align=None,
    points=None,
    star_points=5,
    inner_radius=0.5,
    effects=None,
)

パラメーター

パラメーター 型 既定値 説明
shape str 必須 "rectangle"、"ellipse"、"pill"、"triangle"、"star"、"polygon"です。
position tuple 必須 (x, y)位置。整数(ピクセル)か百分率文字列("50%")です。
width int 必須 図形の幅(ピクセル)。正の整数です。
height int 必須 図形の高さ(ピクセル)。正の整数です。
color str 必須 塗りの色。16進文字列("#RRGGBB"、"#RRGGBBAA")です。
fill LinearGradient \| RadialGradient \| None None 図形内を塗り、図形とともに回転するグラデーションです。グラデーションを描けない対象(PPTX、PDF、SVG、HTML)ではcolorが単色の代替になります。
border_radius int 0 角の丸み(ピクセル)。"rectangle"専用の0以上の整数です。
opacity float 1.0 0.0から1.0までの不透明度です。
rotation float 0.0 回転角(度)です。
align str \| Align \| tuple \| None None 図形のどの点をpositionに合わせるか。Alignを参照してください。
points list[tuple[float, float]] \| None None "polygon"の頂点。図形の枠内で0.0–1.0に正規化し、3点以上が必要です。
star_points int 5 "star"の突起数。最小3です。
inner_radius float 0.5 "star"の外半径に対する内半径の比率。0.0より大きく1.0より小さい値です。
effects list \| None [] Stroke、Shadow、Glowのリストです。

例

ラベル用の長方形

from quickthumb import Shadow, Stroke

canvas.shape(
    shape="rectangle",
    position=(64, 64),
    width=320,
    height=96,
    color="#CC0000",
    border_radius=14,
    effects=[
        Stroke(width=3, color="#FFFFFF"),
        Shadow(offset_x=0, offset_y=10, color="#000000", blur_radius=18),
    ],
)

回転したバッジ

canvas.shape(
    shape="rectangle",
    position=(64, 64),
    width=360,
    height=120,
    color="#CC0000",
    border_radius=16,
    opacity=0.95,
    rotation=-4,
    align=("left", "top"),
)

楕円・円

# Circle: set width == height
canvas.shape(
    shape="ellipse",
    position=("50%", "50%"),
    width=200,
    height=200,
    color="#22d3ee",
    align=("center", "middle"),
)

カプセル

両端が完全に丸い長方形です。border_radiusは不要です。

canvas.shape(
    shape="pill",
    position=(64, 60),
    width=220,
    height=56,
    color="#B8FF00",
)

三角形

width × heightの枠に内接する上向きの二等辺三角形です。向きを変えるにはrotationを使います。

canvas.shape(
    shape="triangle",
    position=("50%", "20%"),
    width=140,
    height=120,
    color="#F59E0B",
    align=("center", "middle"),
    rotation=180,   # point down
)

星

star_pointsが突起数、inner_radiusが鋭さを決めます。値が小さいほど尖ります。

from quickthumb import Glow

canvas.shape(
    shape="star",
    position=("80%", "50%"),
    width=280,
    height=280,
    color="#7C5CFF",
    align=("center", "middle"),
    rotation=12,
    star_points=5,
    inner_radius=0.45,
    effects=[Glow(color="#7C5CFF", radius=40, opacity=0.5)],
)

多角形

頂点を図形の枠に対して正規化します。(0.0, 0.0)が左上、(1.0, 1.0)が右下です。

# A right-pointing arrow
canvas.shape(
    shape="polygon",
    position=(600, 60),
    width=160,
    height=100,
    color="#53BF9D",
    points=[
        (0.0, 0.25), (0.6, 0.25), (0.6, 0.0),
        (1.0, 0.5),
        (0.6, 1.0), (0.6, 0.75), (0.0, 0.75),
    ],
)

中央の図形にグローを付ける

from quickthumb import Glow

canvas.shape(
    shape="rectangle",
    position=("50%", "80%"),
    width=480,
    height=72,
    color="#111827",
    border_radius=36,
    align=("center", "middle"),
    effects=[Glow(color="#22d3ee", radius=24, opacity=0.4)],
)

検証規則

  • shape、position、width、height、colorは必須です。
  • positionは2要素のタプルです。百分率文字列は-?N%形式です。
  • border_radiusは0以上です。
  • opacityは0.0から1.0の範囲です。
  • pointsは"polygon"で必須で、ほかの図形では拒否されます。各値を0.0–1.0に正規化した3点以上が必要です。
  • star_pointsは3以上、inner_radiusは0.0より大きく1.0より小さい値です。