Skip to content

Commit cc7b631

Browse files
committed
feat: add flag to disable the embedding of generation metadata
1 parent 399229e commit cc7b631

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
@@ -125,6 +125,7 @@ Generation Options:
125125
--vace-strength <float> wan vace strength
126126
--increase-ref-index automatically increase the indices of references images based on the order they are listed (starting with 1).
127127
--disable-auto-resize-ref-image disable auto resize of ref images
128+
--disable-image-metadata do not embed generation metadata on image files
128129
-s, --seed RNG seed (default: 42, use random seed for < 0)
129130
--sampling-method sampling method, one of [euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing,
130131
tcd, res_multistep, res_2s] (default: euler for Flux/SD3/Wan, euler_a

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
@@ -1036,6 +1036,7 @@ struct SDGenerationParams {
10361036
std::string control_video_path;
10371037
bool auto_resize_ref_image = true;
10381038
bool increase_ref_index = false;
1039+
bool embed_image_metadata = true;
10391040

10401041
std::vector<int> skip_layers = {7, 8, 9};
10411042
sd_sample_params_t sample_params;
@@ -1264,6 +1265,11 @@ struct SDGenerationParams {
12641265
"disable auto resize of ref images",
12651266
false,
12661267
&auto_resize_ref_image},
1268+
{"",
1269+
"--disable-image-metadata",
1270+
"do not embed generation metadata on image files",
1271+
false,
1272+
&embed_image_metadata},
12671273
};
12681274

12691275
auto on_seed_arg = [&](int argc, const char** argv, int index) {
@@ -1574,6 +1580,7 @@ struct SDGenerationParams {
15741580

15751581
load_if_exists("auto_resize_ref_image", auto_resize_ref_image);
15761582
load_if_exists("increase_ref_index", increase_ref_index);
1583+
load_if_exists("embed_image_metadata", embed_image_metadata);
15771584

15781585
load_if_exists("skip_layers", skip_layers);
15791586
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
@@ -205,6 +205,7 @@ Default Generation Options:
205205
--vace-strength <float> wan vace strength
206206
--increase-ref-index automatically increase the indices of references images based on the order they are listed (starting with 1).
207207
--disable-auto-resize-ref-image disable auto resize of ref images
208+
--disable-image-metadata do not embed generation metadata on image files
208209
-s, --seed RNG seed (default: 42, use random seed for < 0)
209210
--sampling-method sampling method, one of [euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm, ddim_trailing,
210211
tcd, res_multistep, res_2s] (default: euler for Flux/SD3/Wan, euler_a

examples/server/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ std::vector<uint8_t> write_image_to_vector(
260260
result = stbi_write_jpg_to_func(c_func, &ctx, width, height, channels, image, quality);
261261
break;
262262
case ImageFormat::PNG:
263-
result = stbi_ext_write_png_to_func(c_func, &ctx, width, height, channels, image, width * channels, params.c_str());
263+
result = stbi_ext_write_png_to_func(c_func, &ctx, width, height, channels, image, width * channels, params.size() > 0 ? params.c_str() : nullptr);
264264
break;
265265
default:
266266
throw std::runtime_error("invalid image format");
@@ -553,7 +553,9 @@ int main(int argc, const char** argv) {
553553
if (results[i].data == nullptr) {
554554
continue;
555555
}
556-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
556+
std::string params = gen_params.embed_image_metadata
557+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
558+
: "";
557559
auto image_bytes = write_image_to_vector(output_format == "jpeg" ? ImageFormat::JPEG : ImageFormat::PNG,
558560
results[i].data,
559561
results[i].width,
@@ -806,7 +808,9 @@ int main(int argc, const char** argv) {
806808
for (int i = 0; i < num_results; i++) {
807809
if (results[i].data == nullptr)
808810
continue;
809-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
811+
std::string params = gen_params.embed_image_metadata
812+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
813+
: "";
810814
auto image_bytes = write_image_to_vector(output_format == "jpeg" ? ImageFormat::JPEG : ImageFormat::PNG,
811815
results[i].data,
812816
results[i].width,
@@ -1126,7 +1130,9 @@ int main(int argc, const char** argv) {
11261130
continue;
11271131
}
11281132

1129-
std::string params = get_image_params(ctx_params, gen_params, gen_params.seed + i);
1133+
std::string params = gen_params.embed_image_metadata
1134+
? get_image_params(ctx_params, gen_params, gen_params.seed + i)
1135+
: "";
11301136
auto image_bytes = write_image_to_vector(ImageFormat::PNG,
11311137
results[i].data,
11321138
results[i].width,

0 commit comments

Comments
 (0)