Skip to content

Commit d24c657

Browse files
committed
feat: add wanx background image generation api support
1 parent 96ba00d commit d24c657

26 files changed

+754
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The input of background generation task.
5+
/// </summary>
6+
public class BackgroundGenerationInput
7+
{
8+
/// <summary>
9+
/// The image url to generation background on.
10+
/// </summary>
11+
public required string BaseImageUrl { get; set; }
12+
13+
/// <summary>
14+
/// The reference image url for.
15+
/// </summary>
16+
public string? RefImageUrl { get; set; }
17+
18+
/// <summary>
19+
/// The prompt the background would generation from.
20+
/// </summary>
21+
public string? RefPrompt { get; set; }
22+
23+
/// <summary>
24+
/// The negative prompt.
25+
/// </summary>
26+
public string? NegRefPrompt { get; set; }
27+
28+
/// <summary>
29+
/// The title to be put in generated image, max length is 8.
30+
/// </summary>
31+
public string? Title { get; set; }
32+
33+
/// <summary>
34+
/// Valid when <see cref="Title"/> is set, max length is 10.
35+
/// </summary>
36+
public string? SubTitle { get; set; }
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The output of background generation task.
5+
/// </summary>
6+
public record BackgroundGenerationOutput : DashScopeTaskOutput
7+
{
8+
/// <summary>
9+
/// The generated image urls.
10+
/// </summary>
11+
public List<BackgroundGenerationResult>? Results { get; set; }
12+
13+
/// <summary>
14+
/// The generated result of texts.
15+
/// </summary>
16+
public BackgroundGenerationTextResult? TextResults { get; set; }
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The parameters of background generation task.
5+
/// </summary>
6+
public class BackgroundGenerationParameters
7+
{
8+
/// <summary>
9+
/// The number of images to be generated.
10+
/// </summary>
11+
public int? N { get; set; }
12+
13+
/// <summary>
14+
/// Range at [0, 999], controls the distance from generated image to reference image.
15+
/// </summary>
16+
public int? NoiseLevel { get; set; }
17+
18+
/// <summary>
19+
/// Range at [0,1]. When RefImageUrl and RefPrompt are both set, controls the percentage of ref prompt weight.
20+
/// </summary>
21+
public float? RefPromptWeight { get; set; }
22+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The result of background generation task.
5+
/// </summary>
6+
/// <param name="Url">The url of generated image.</param>
7+
public record BackgroundGenerationResult(string Url);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The results of background generation task.
5+
/// </summary>
6+
/// <param name="Urls">The urls of images that put texts on.</param>
7+
/// <param name="Params">The generated texts for image.</param>
8+
public record BackgroundGenerationTextResult(
9+
List<BackgroundGenerationTextResultUrl> Urls,
10+
List<BackgroundGenerationTextResultParams>? Params);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The gradient of background generation text.
5+
/// </summary>
6+
/// <param name="Type">Type of gradient. e.g. <c>linear</c></param>
7+
/// <param name="GradientUnits">Unit of gradient. e.g. <c>pixels</c></param>
8+
/// <param name="ColorStops">Color stops of gradient.</param>
9+
public record BackgroundGenerationTextResultGradient(
10+
string Type,
11+
string GradientUnits,
12+
List<BackgroundGenerationTextResultGradientColorStop> ColorStops)
13+
{
14+
/// <summary>
15+
/// Coords of each stop, use "x1", "y1", "x2", "y2"... to access the coords.
16+
/// </summary>
17+
public Dictionary<string, int>? Coords { get; set; }
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The color stop of gradient in background generation result.
5+
/// </summary>
6+
/// <param name="Color">The color of current stop.</param>
7+
/// <param name="Offset">The position of current stop.</param>
8+
public record BackgroundGenerationTextResultGradientColorStop(string Color, float Offset);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Text.Json.Serialization;
2+
using Cnblogs.DashScope.Sdk.Internals;
3+
4+
namespace Cnblogs.DashScope.Sdk;
5+
6+
/// <summary>
7+
/// Represents one layer of background generation text result.
8+
/// </summary>
9+
/// <param name="Idx">The if of the layer.</param>
10+
/// <param name="Type">The type of layer, can be "text" or "text_mask".</param>
11+
/// <param name="Top">The top position of the layer.</param>
12+
/// <param name="Left">The left position of the layer.</param>
13+
/// <param name="Width">The width of the layer.</param>
14+
/// <param name="Height">The height of the layer.</param>
15+
/// <param name="SubType">Available when type is "text". The type of text, can ba "Title" or "SubTitle".</param>
16+
/// <param name="Content">Available when type is "text". The content of the text.</param>
17+
/// <param name="FontFamily">Available when type is "text". The font family of the text.</param>
18+
/// <param name="FontSize">Available when type is "text". The font size of the text.</param>
19+
/// <param name="FontWeight">Available when type is "text". The font weight of the text. e.g. Medium.</param>
20+
/// <param name="FontColor">Available when type is "text". The color of the text in HEX format.</param>
21+
/// <param name="Direction">Available when type is "text". The direction of the text. e.g. vertical or horizontal.</param>
22+
/// <param name="Alignment">Available when type is "text". The alignment of the text, can be center, left or right.</param>
23+
/// <param name="LineHeight">Available when type is "text". The line height of the text.</param>
24+
/// <param name="FontItalic">Available when type is "text". Is the text needs to be italic.</param>
25+
/// <param name="FontLineThrough">Available when type is "text". Is the text has line through.</param>
26+
/// <param name="FontUnderLine">Available when type is "text". Is the text has underline.</param>
27+
/// <param name="TextShadow">Available when type is "text". The text shadow of the text. e.g. 2px 2px #80808080</param>
28+
/// <param name="TextStroke">Available when type is "text". The stroke of the text. e.g. 1px #fffffff0</param>
29+
/// <param name="Opacity">The opacity of the layer.</param>
30+
/// <param name="Radius">Available when type is "text_mask". The border radius of the mask.</param>
31+
/// <param name="BoxShadow">Available when type is "text_mask". The box shadow of the mask.</param>
32+
/// <param name="Color">Available when type is "text_mask". Color of the mask.</param>
33+
/// <param name="Gradient">Available when type is "text_mask". The gradient of the mask.</param>
34+
public record BackgroundGenerationTextResultLayer(
35+
int Idx,
36+
string Type,
37+
int Top,
38+
int Left,
39+
int Width,
40+
int Height,
41+
string? SubType = null,
42+
string? Content = null,
43+
string? FontFamily = null,
44+
int? FontSize = null,
45+
string? FontWeight = null,
46+
string? FontColor = null,
47+
string? Direction = null,
48+
string? Alignment = null,
49+
float? LineHeight = null,
50+
bool? FontItalic = null,
51+
bool? FontLineThrough = null,
52+
bool? FontUnderLine = null,
53+
[property: JsonConverter(typeof(DashScopeZeroAsNullConvertor))]
54+
string? TextShadow = null,
55+
string? TextStroke = null,
56+
float? Opacity = null,
57+
int? Radius = null,
58+
string? BoxShadow = null,
59+
string? Color = null,
60+
BackgroundGenerationTextResultGradient? Gradient = null);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The generated styles of text in one image of background generation task.
5+
/// </summary>
6+
/// <param name="SampleIdx">The id of image.</param>
7+
/// <param name="Layers">The layers of styled text.</param>
8+
public record BackgroundGenerationTextResultParams(int SampleIdx, List<BackgroundGenerationTextResultLayer> Layers);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Cnblogs.DashScope.Sdk;
2+
3+
/// <summary>
4+
/// The generated background text url.
5+
/// </summary>
6+
/// <param name="Url">The url of generated text.</param>
7+
public record BackgroundGenerationTextResultUrl(string Url);

0 commit comments

Comments
 (0)