Skip to content

Commit 3ee35c5

Browse files
committed
add meme remote_control and fogging
1 parent 6491bff commit 3ee35c5

File tree

7 files changed

+124
-6
lines changed

7 files changed

+124
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

meme_generator_memes/src/memes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod firefly_holdsign;
7373
mod fivethousand_choyen;
7474
mod flash_blind;
7575
mod flush;
76+
mod fogging;
7677
mod follow;
7778
mod forbid;
7879
mod frieren_take;
@@ -188,6 +189,7 @@ mod pyramid;
188189
mod raise_image;
189190
mod raise_sign;
190191
mod read_book;
192+
mod remote_control;
191193
mod repeat;
192194
mod rip;
193195
mod rip_angrily;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use skia_safe::{IRect, Image};
2+
3+
use meme_generator_core::error::Error;
4+
use meme_generator_utils::{
5+
builder::InputImage,
6+
canvas::CanvasExt,
7+
encoder::make_png_or_gif,
8+
image::{Fit, ImageExt},
9+
tools::{load_image, local_date},
10+
};
11+
12+
use crate::{options::NoOptions, register_meme};
13+
14+
const DEFAULT_TEXT: &str = "兄弟,回南了";
15+
16+
fn fogging(images: Vec<InputImage>, texts: Vec<String>, _: NoOptions) -> Result<Vec<u8>, Error> {
17+
let text = if !texts.is_empty() {
18+
&texts[0]
19+
} else {
20+
DEFAULT_TEXT
21+
};
22+
23+
let img = &images[0].image;
24+
let img_w = img.width().min(500);
25+
let img_h = img.height() * img_w / img.width();
26+
let mask = load_image("fogging/0.png")?;
27+
let mask = mask.resize_fit((img_w, img_h), Fit::Cover);
28+
29+
let mut surface = mask.to_surface();
30+
let canvas = surface.canvas();
31+
canvas.draw_text_area_auto_font_size(
32+
IRect::from_ltrb(10, 10, mask.width() - 10, 80),
33+
text,
34+
20.0,
35+
40.0,
36+
None,
37+
)?;
38+
let mask = surface.image_snapshot();
39+
40+
let func = |images: Vec<Image>| {
41+
let img = images[0].resize_exact((img_w, img_h));
42+
let img = img.gaussian_blur(10.0);
43+
let mut surface = img.to_surface();
44+
let canvas = surface.canvas();
45+
canvas.draw_image(&mask, (0, 0), None);
46+
Ok(surface.image_snapshot())
47+
};
48+
49+
make_png_or_gif(images, func)
50+
}
51+
52+
register_meme!(
53+
"fogging",
54+
fogging,
55+
min_images = 1,
56+
max_images = 1,
57+
min_texts = 0,
58+
max_texts = 1,
59+
keywords = &["回南天", "水雾"],
60+
default_texts = &[DEFAULT_TEXT],
61+
date_created = local_date(2025, 3, 16),
62+
date_modified = local_date(2025, 3, 16),
63+
);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use skia_safe::Image;
2+
3+
use meme_generator_core::error::Error;
4+
use meme_generator_utils::{
5+
builder::InputImage,
6+
encoder::{FrameAlign, GifInfo, make_gif_or_combined_gif},
7+
image::ImageExt,
8+
tools::{load_image, local_date, new_surface},
9+
};
10+
11+
use crate::{options::NoOptions, register_meme};
12+
13+
fn remote_control(images: Vec<InputImage>, _: Vec<String>, _: NoOptions) -> Result<Vec<u8>, Error> {
14+
let img = &images[0].image;
15+
let img_w = img.width();
16+
let img_h = img.height();
17+
let locs = vec![
18+
(0, 0),
19+
(img_w / 80, img_h / 80),
20+
(-img_w / 100, -img_h / 100),
21+
(img_w / 60, 0),
22+
(0, img_h / 60),
23+
];
24+
let overlay = load_image("remote_control/0.png")?;
25+
let overlay = overlay.resize_height((img_h as f32 / 2.5) as i32);
26+
27+
let func = |i: usize, images: Vec<Image>| {
28+
let mut surface = new_surface((img_w, img_h));
29+
let canvas = surface.canvas();
30+
canvas.draw_image(&images[0], locs[i], None);
31+
let x = img_w - overlay.width();
32+
let y = img_h - overlay.height();
33+
canvas.draw_image(&overlay, (x, y), None);
34+
Ok(surface.image_snapshot())
35+
};
36+
37+
make_gif_or_combined_gif(
38+
images,
39+
func,
40+
GifInfo {
41+
frame_num: 5,
42+
duration: 0.05,
43+
},
44+
FrameAlign::ExtendLoop,
45+
)
46+
}
47+
48+
register_meme!(
49+
"remote_control",
50+
remote_control,
51+
min_images = 1,
52+
max_images = 1,
53+
keywords = &["遥控", "控制"],
54+
date_created = local_date(2025, 3, 4),
55+
date_modified = local_date(2025, 3, 4),
56+
);

meme_generator_py/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,7 @@ fn get_version() -> &'static str {
520520

521521
#[pyfunction]
522522
fn get_meme(key: &str) -> Option<Meme> {
523-
match meme_generator::get_meme(key) {
524-
Some(meme) => Some(Meme { meme }),
525-
None => None,
526-
}
523+
meme_generator::get_meme(key).map(|meme| Meme { meme })
527524
}
528525

529526
#[pyfunction]

resources/images/fogging/0.png

266 KB
Loading
45.5 KB
Loading

0 commit comments

Comments
 (0)