Skip to content

Commit 89d4e84

Browse files
committed
Enables background image size to be modified at run time
1 parent 5ada36c commit 89d4e84

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "text-image-generator"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ impl Generator {
211211
})
212212
}
213213

214+
fn set_bg_size(&mut self, height: usize, width: usize) {
215+
self.bg_factory = BgFactory::new(&self.bg_factory.bg_dir, height, width);
216+
}
217+
214218
// fn set_latin_ch_dict(&mut self, ch: String, font_list: Vec<String>) {
215219
// if let Some(content) = &mut self.latin_ch_dict {
216220
// *content.entry(ch).or_insert(vec![]) = font_list;

src/merge_util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use super::effect_helper::{
1414
#[pyclass]
1515
pub struct BgFactory {
1616
images: Vec<GrayImage>,
17-
height: usize,
18-
width: usize,
17+
pub height: usize,
18+
pub width: usize,
19+
pub bg_dir: String,
1920
}
2021

2122
impl BgFactory {
@@ -86,6 +87,7 @@ impl BgFactory {
8687
images,
8788
height,
8889
width,
90+
bg_dir: dir.as_ref().to_string_lossy().to_string(),
8991
}
9092
}
9193

text_image_generator.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ class Generator:
118118
main_font_list: str
119119

120120
def __init__(self, config_path: str) -> None: ...
121+
def set_bg_size(
122+
self,
123+
height: int,
124+
width: int,
125+
):
126+
"""Set the background image's height and width.
127+
128+
:param height: specify the height of the background image
129+
:param width: specify the width of the background image
130+
"""
121131
def get_random_chinese(
122132
self, min: int, max: int, add_extra_symbol: bool = False
123133
) -> list[Tuple[str, list[Tuple[str, int, int, int]]]]:
@@ -143,7 +153,7 @@ class Generator:
143153
text_with_font_list: list[Tuple[str, list[Tuple[str, int, int, int]]]],
144154
text_color: Tuple[int, int, int],
145155
background_color: Tuple[int, int, int],
146-
apply_effect: bool = False
156+
apply_effect: bool = False,
147157
) -> npt.NDArray:
148158
"""
149159
Generate an image based on a given list of characters and font information.

0 commit comments

Comments
 (0)