upScaleImageBase64 method
Create a higher resolution version of an input image.
This operation outputs an image with a maximum pixel count of 4,194,304. This is equivalent to dimensions such as 2048x2048 and 4096x1024.
Implementation
Future<List<ImageResponse>> upScaleImageBase64({
required String apiKey,
required String engineId,
required ImageUpScaleRequestParams params,
required Uint8List image,
String? organization,
String? clientId,
String? clientVersion,
}) async {
Map<String, String> headers = {
"Authorization": apiKey,
"Accept": "application/json",
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
};
if (organization != null) {
headers.putIfAbsent("Organization", () => organization);
}
if (clientId != null) {
headers.putIfAbsent("Stability-Client-ID", () => clientId);
}
if (clientVersion != null) {
headers.putIfAbsent("Stability-Client-Version", () => clientVersion);
}
Uri endpoint;
if (secure) {
endpoint =
Uri.https(baseUrl, "/v1/generation/$engineId/image-to-image/upscale");
} else {
endpoint =
Uri.http(baseUrl, "/v1/generation/$engineId/image-to-image/upscale");
}
var request = http.MultipartRequest('POST', endpoint)
..headers.addAll(headers)
..fields.addAll(
params.toJson().map((key, value) => MapEntry(key, value.toString())))
..fields.remove("text_prompts")
..files.add(http.MultipartFile.fromBytes("image", image));
List<TextPrompt>? prompts = params.textPrompts;
if (prompts != null) {
int index = 0;
for (var element in prompts) {
request.fields['text_prompts[$index][text]'] = element.text;
request.fields['text_prompts[$index][weight]'] =
element.weight.toString();
index++;
}
}
var response = await request.send();
if (response.statusCode == 200 || response.statusCode == 201) {
return ImageResponseListDto.fromJson(jsonDecode(
const Utf8Decoder().convert(await response.stream.toBytes())))
.artifacts;
} else {
var error = ServerError.fromJson(jsonDecode(
const Utf8Decoder().convert(await response.stream.toBytes())));
throw GenerationException(
statusCode: response.statusCode, message: error.message);
}
}