Skip to content

Commit be6f95b

Browse files
committed
feat: add flag to disable the embedding of generation metadata
1 parent 2b19c83 commit be6f95b

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

examples/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Generation Options:
123123
--vace-strength <float> wan vace strength
124124
--increase-ref-index automatically increase the indices of references images based on the order they are listed (starting with 1).
125125
--disable-auto-resize-ref-image disable auto resize of ref images
126+
--disable-image-metadata do not embed generation metadata on image files
126127
-s, --seed RNG seed (default: 42, use random seed for < 0)
127128
--sampling-method sampling method, one of [euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing, tcd,
128129
res_multistep, res_2s] (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
@@ -357,12 +357,14 @@ bool save_results(const SDCliParams& cli_params,
357357
if (!img.data)
358358
return false;
359359

360-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + idx);
360+
std::string params = gen_params.embed_image_metadata
361+
? get_image_params(ctx_params, gen_params, gen_params.seed + idx)
362+
: "";
361363
int ok = 0;
362364
if (is_jpg) {
363-
ok = stbi_write_jpg(path.string().c_str(), img.width, img.height, img.channel, img.data, 90, params.c_str());
365+
ok = stbi_write_jpg(path.string().c_str(), img.width, img.height, img.channel, img.data, 90, params.size() > 0 ? params.c_str() : nullptr);
364366
} else {
365-
ok = stbi_write_png(path.string().c_str(), img.width, img.height, img.channel, img.data, 0, params.c_str());
367+
ok = stbi_write_png(path.string().c_str(), img.width, img.height, img.channel, img.data, 0, params.size() > 0 ? params.c_str() : nullptr);
366368
}
367369
LOG_INFO("save result image %d to '%s' (%s)", idx, path.string().c_str(), ok ? "success" : "failure");
368370
return ok != 0;

examples/common/common.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ struct SDGenerationParams {
10421042
std::string control_video_path;
10431043
bool auto_resize_ref_image = true;
10441044
bool increase_ref_index = false;
1045+
bool embed_image_metadata = true;
10451046

10461047
std::vector<int> skip_layers = {7, 8, 9};
10471048
sd_sample_params_t sample_params;
@@ -1267,6 +1268,11 @@ struct SDGenerationParams {
12671268
"disable auto resize of ref images",
12681269
false,
12691270
&auto_resize_ref_image},
1271+
{"",
1272+
"--disable-image-metadata",
1273+
"do not embed generation metadata on image files",
1274+
false,
1275+
&embed_image_metadata},
12701276
};
12711277

12721278
auto on_seed_arg = [&](int argc, const char** argv, int index) {
@@ -1597,6 +1603,7 @@ struct SDGenerationParams {
15971603

15981604
load_if_exists("auto_resize_ref_image", auto_resize_ref_image);
15991605
load_if_exists("increase_ref_index", increase_ref_index);
1606+
load_if_exists("embed_image_metadata", embed_image_metadata);
16001607

16011608
load_if_exists("skip_layers", skip_layers);
16021609
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
@@ -115,6 +115,7 @@ Default Generation Options:
115115
--vace-strength <float> wan vace strength
116116
--increase-ref-index automatically increase the indices of references images based on the order they are listed (starting with 1).
117117
--disable-auto-resize-ref-image disable auto resize of ref images
118+
--disable-image-metadata do not embed generation metadata on image files
118119
-s, --seed RNG seed (default: 42, use random seed for < 0)
119120
--sampling-method sampling method, one of [euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing, tcd,
120121
res_multistep, res_2s] (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");
@@ -528,7 +528,9 @@ int main(int argc, const char** argv) {
528528
if (results[i].data == nullptr) {
529529
continue;
530530
}
531-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
531+
std::string params = gen_params.embed_image_metadata
532+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
533+
: "";
532534
auto image_bytes = write_image_to_vector(output_format == "jpeg" ? ImageFormat::JPEG : ImageFormat::PNG,
533535
results[i].data,
534536
results[i].width,
@@ -775,7 +777,9 @@ int main(int argc, const char** argv) {
775777
for (int i = 0; i < num_results; i++) {
776778
if (results[i].data == nullptr)
777779
continue;
778-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
780+
std::string params = gen_params.embed_image_metadata
781+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
782+
: "";
779783
auto image_bytes = write_image_to_vector(output_format == "jpeg" ? ImageFormat::JPEG : ImageFormat::PNG,
780784
results[i].data,
781785
results[i].width,
@@ -1093,7 +1097,9 @@ int main(int argc, const char** argv) {
10931097
continue;
10941098
}
10951099

1096-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
1100+
std::string params = gen_params.embed_image_metadata
1101+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
1102+
: "";
10971103
auto image_bytes = write_image_to_vector(ImageFormat::PNG,
10981104
results[i].data,
10991105
results[i].width,

0 commit comments

Comments
 (0)