Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: text renderer, artifact manager, image vstack #41

Merged
merged 3 commits into from
Mar 14, 2024
Merged

Conversation

yxlao
Copy link
Owner

@yxlao yxlao commented Mar 14, 2024

Changes

  1. Text Rendering: Adds functions for text rendering with customization options. This significantly improves the library's capability for incorporating text into images for a variety of applications.

    import camtools as ct
    rendered_image = ct.render.render_text("Hello, World!", font_size=24, font_type="tex")
  2. Artifact Management with ArtifactManager: Introduces the ArtifactManager to manage external files efficiently. It checks for local availability and downloads files when necessary. Artifacts are hosted on camtools-artifacts. Artifacts will be cached in ~/.camtools.

    import camtools as ct
    artifact_manager = ct.artifact.ArtifactManager()
    font_path = artifact_manager.get_artifact_path("a1/texgyrepagella-regular.otf")
  3. Image Vertical Stacking: Adds a vstack_images function to vertically stack images with options for alignment and background color. =

    import camtools as ct
    im_renders = ...
    im_renders_stacked = ct.image.vstack_images(im_renders)

Text rendering example

import camtools as ct
from matplotlib import pyplot as plt
im_render = ct.render.render_text(
    "Example default layout.",
    font_size=72,
)
plt.imshow(im_render)
plt.show()

download

im_render = ct.render.render_text(
    "Example tight layout.",
    font_size=72,
    tight_layout=True,
)
plt.imshow(im_render)
plt.show()

download

im_render = ct.render.render_text(
    "Example multi-line\nlong texts.",
    font_size=72,
    font_color=(1.0, 0.0, 0.0),
    tight_layout=True,
    multiline_alignment="center",
)
plt.imshow(im_render)
plt.show()

download

im_renders = ct.render.render_texts(
    ["Text one", "Example two", "Longer text three"],
    font_size=72,
    font_type="tex",
    font_color=(1.0, 0.0, 0.0),
    multiline_alignment="center",
    same_height=True,
    same_width=False,
)
im_renders_stacked = ct.image.vstack_images(
    im_renders,
    background_color=(0.5, 0.5, 0.5),
)
plt.imshow(im_renders_stacked)
plt.show()

download

im_renders = ct.render.render_texts(
    ["Text one", "Example two", "Longer text three"],
    font_size=72,
    font_type="tex",
    font_color=(1.0, 0.0, 0.0),
    multiline_alignment="center",
    same_height=True,
    same_width=True,
)
im_renders_stacked = ct.image.vstack_images(
    im_renders,
    background_color=(0.5, 0.5, 0.5),
)
plt.imshow(im_renders_stacked)
plt.show()

download

@yxlao yxlao changed the title new: text rendering support new: text renderer, artifact manager, image vstack Mar 14, 2024
@yxlao yxlao changed the title new: text renderer, artifact manager, image vstack feat: text renderer, artifact manager, image vstack Mar 14, 2024
@yxlao yxlao merged commit cbac2b1 into master Mar 14, 2024
3 checks passed
@yxlao yxlao deleted the render-text branch March 14, 2024 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant