Skip to content

Commit 9533c5e

Browse files
committed
feat: add flag to disable the embedding of generation metadata
1 parent 0d5b9c7 commit 9533c5e

5 files changed

Lines changed: 24 additions & 7 deletions

File tree

examples/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Generation Options:
122122
--vace-strength <float> wan vace strength
123123
--increase-ref-index automatically increase the indices of references images based on the order they are listed (starting with 1).
124124
--disable-auto-resize-ref-image disable auto resize of ref images
125+
--disable-image-metadata do not embed generation metadata on image files
125126
-s, --seed RNG seed (default: 42, use random seed for < 0)
126127
--sampling-method sampling method, one of [euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing,
127128
tcd] (default: euler for Flux/SD3/Wan, euler_a otherwise)

examples/cli/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,14 @@ bool save_results(const SDCliParams& cli_params,
354354
if (!img.data)
355355
return;
356356

357-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + idx);
357+
std::string params = gen_params.embed_image_metadata
358+
? get_image_params(ctx_params, gen_params, gen_params.seed + idx)
359+
: "";
358360
int ok = 0;
359361
if (is_jpg) {
360-
ok = stbi_write_jpg(path.string().c_str(), img.width, img.height, img.channel, img.data, 90, params.c_str());
362+
ok = stbi_write_jpg(path.string().c_str(), img.width, img.height, img.channel, img.data, 90, params.size() > 0 ? params.c_str() : nullptr);
361363
} else {
362-
ok = stbi_write_png(path.string().c_str(), img.width, img.height, img.channel, img.data, 0, params.c_str());
364+
ok = stbi_write_png(path.string().c_str(), img.width, img.height, img.channel, img.data, 0, params.size() > 0 ? params.c_str() : nullptr);
363365
}
364366
LOG_INFO("save result image %d to '%s' (%s)", idx, path.string().c_str(), ok ? "success" : "failure");
365367
};

examples/common/common.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ struct SDGenerationParams {
10351035
std::string control_video_path;
10361036
bool auto_resize_ref_image = true;
10371037
bool increase_ref_index = false;
1038+
bool embed_image_metadata = true;
10381039

10391040
std::vector<int> skip_layers = {7, 8, 9};
10401041
sd_sample_params_t sample_params;
@@ -1260,6 +1261,11 @@ struct SDGenerationParams {
12601261
"disable auto resize of ref images",
12611262
false,
12621263
&auto_resize_ref_image},
1264+
{"",
1265+
"--disable-image-metadata",
1266+
"do not embed generation metadata on image files",
1267+
false,
1268+
&embed_image_metadata},
12631269
};
12641270

12651271
auto on_seed_arg = [&](int argc, const char** argv, int index) {
@@ -1590,6 +1596,7 @@ struct SDGenerationParams {
15901596

15911597
load_if_exists("auto_resize_ref_image", auto_resize_ref_image);
15921598
load_if_exists("increase_ref_index", increase_ref_index);
1599+
load_if_exists("embed_image_metadata", embed_image_metadata);
15931600

15941601
load_if_exists("skip_layers", skip_layers);
15951602
load_if_exists("high_noise_skip_layers", high_noise_skip_layers);

examples/server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Default Generation Options:
114114
--vace-strength <float> wan vace strength
115115
--increase-ref-index automatically increase the indices of references images based on the order they are listed (starting with 1).
116116
--disable-auto-resize-ref-image disable auto resize of ref images
117+
--disable-image-metadata do not embed generation metadata on image files
117118
-s, --seed RNG seed (default: 42, use random seed for < 0)
118119
--sampling-method sampling method, one of [euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing,
119120
tcd] (default: euler for Flux/SD3/Wan, euler_a otherwise)

examples/server/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ std::vector<uint8_t> write_image_to_vector(
256256
result = stbi_write_jpg_to_func(c_func, &ctx, width, height, channels, image, quality);
257257
break;
258258
case ImageFormat::PNG:
259-
result = stbi_ext_write_png_to_func(c_func, &ctx, width, height, channels, image, width * channels, params.c_str());
259+
result = stbi_ext_write_png_to_func(c_func, &ctx, width, height, channels, image, width * channels, params.size() > 0 ? params.c_str() : nullptr);
260260
break;
261261
default:
262262
throw std::runtime_error("invalid image format");
@@ -475,7 +475,9 @@ int main(int argc, const char** argv) {
475475
if (results[i].data == nullptr) {
476476
continue;
477477
}
478-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
478+
std::string params = gen_params.embed_image_metadata
479+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
480+
: "";
479481
auto image_bytes = write_image_to_vector(output_format == "jpeg" ? ImageFormat::JPEG : ImageFormat::PNG,
480482
results[i].data,
481483
results[i].width,
@@ -697,7 +699,9 @@ int main(int argc, const char** argv) {
697699
for (int i = 0; i < num_results; i++) {
698700
if (results[i].data == nullptr)
699701
continue;
700-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
702+
std::string params = gen_params.embed_image_metadata
703+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
704+
: "";
701705
auto image_bytes = write_image_to_vector(output_format == "jpeg" ? ImageFormat::JPEG : ImageFormat::PNG,
702706
results[i].data,
703707
results[i].width,
@@ -953,7 +957,9 @@ int main(int argc, const char** argv) {
953957
continue;
954958
}
955959

956-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
960+
std::string params = gen_params.embed_image_metadata
961+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
962+
: "";
957963
auto image_bytes = write_image_to_vector(ImageFormat::PNG,
958964
results[i].data,
959965
results[i].width,

0 commit comments

Comments
 (0)