pub struct Image {
pub image: Option<(String, Vec<u8>)>,
pub mask: Option<(String, Vec<u8>)>,
pub prompt: Option<String>,
pub n: Option<u32>,
pub size: Option<Size>,
pub response_format: Option<Format>,
pub user: Option<String>,
}
Expand description
Given a prompt and an instruction, the model will return an edited version of the prompt.
Fields§
§image: Option<(String, Vec<u8>)>
The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
mask: Option<(String, Vec<u8>)>
An additional image whose fully transparent areas (e.g. where alpha is
zero) indicate where image
should be edited. Must be a valid PNG
file, less than 4MB, and have the same dimensions as image
.
prompt: Option<String>
A text description of the desired image(s). The maximum length is 1000 characters.
n: Option<u32>
The number of images to generate. Must be between 1 and 10.
size: Option<Size>
The size of the generated images. Must be one of 256x256
, 512x512
,
or 1024x1024
. Use given enum variant.
response_format: Option<Format>
The format in which the generated images are returned. Must be one of
url
or b64_json
.
user: Option<String>
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Implementations§
source§impl Image
impl Image
sourcepub fn set_image(&mut self, filename: &str, bytes: Vec<u8>)
pub fn set_image(&mut self, filename: &str, bytes: Vec<u8>)
Set target image.
Arguments
filename
- Image filename to edit or create variantbytes
- Image bytes to edit or create variant
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let mut image = Image::default();
image.set_prompt("Make it cartoon-like.");
image.set_image(
"a.png",
std::fs::read(std::path::PathBuf::from(
"D:\\Contents\\Downloads\\WeChat Image_20230320174259.png",
))
.unwrap(),
);
let result = image.editing().await?;
println!("{}", result.data.get(0).unwrap().url.clone().unwrap());
Ok(())
}
More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let mut image = Image::default();
image.set_prompt("Make it cartoon-like.");
image.set_image(
"a.png",
std::fs::read(std::path::PathBuf::from(
"D:\\Contents\\Downloads\\WeChat Image_20230320174259.png",
))
.unwrap(),
);
let result = image.variation().await?;
println!("{}", result.data.get(0).unwrap().url.clone().unwrap());
Ok(())
}
sourcepub fn set_image_mask(&mut self, filename: &str, bytes: Vec<u8>)
pub fn set_image_mask(&mut self, filename: &str, bytes: Vec<u8>)
Set target image mask.
Arguments
filename
- Image filename to use as a maskbytes
- Image bytes to use as a mask
sourcepub fn set_prompt(&mut self, content: &str)
pub fn set_prompt(&mut self, content: &str)
Examples found in repository?
More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let mut image = Image::default();
image.set_prompt("Make it cartoon-like.");
image.set_image(
"a.png",
std::fs::read(std::path::PathBuf::from(
"D:\\Contents\\Downloads\\WeChat Image_20230320174259.png",
))
.unwrap(),
);
let result = image.editing().await?;
println!("{}", result.data.get(0).unwrap().url.clone().unwrap());
Ok(())
}
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let mut image = Image::default();
image.set_prompt("Make it cartoon-like.");
image.set_image(
"a.png",
std::fs::read(std::path::PathBuf::from(
"D:\\Contents\\Downloads\\WeChat Image_20230320174259.png",
))
.unwrap(),
);
let result = image.variation().await?;
println!("{}", result.data.get(0).unwrap().url.clone().unwrap());
Ok(())
}
sourcepub async fn editing(&self) -> Result<ImageResponse, Box<dyn Error>>
pub async fn editing(&self) -> Result<ImageResponse, Box<dyn Error>>
Send edit request to OpenAI.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let mut image = Image::default();
image.set_prompt("Make it cartoon-like.");
image.set_image(
"a.png",
std::fs::read(std::path::PathBuf::from(
"D:\\Contents\\Downloads\\WeChat Image_20230320174259.png",
))
.unwrap(),
);
let result = image.editing().await?;
println!("{}", result.data.get(0).unwrap().url.clone().unwrap());
Ok(())
}
sourcepub async fn generation(&mut self) -> Result<ImageResponse, Box<dyn Error>>
pub async fn generation(&mut self) -> Result<ImageResponse, Box<dyn Error>>
Send generation request to OpenAI.
sourcepub async fn variation(&mut self) -> Result<ImageResponse, Box<dyn Error>>
pub async fn variation(&mut self) -> Result<ImageResponse, Box<dyn Error>>
Send variation request to OpenAI.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
log4rs::init_file("log4rs.yml", Default::default()).unwrap();
let mut image = Image::default();
image.set_prompt("Make it cartoon-like.");
image.set_image(
"a.png",
std::fs::read(std::path::PathBuf::from(
"D:\\Contents\\Downloads\\WeChat Image_20230320174259.png",
))
.unwrap(),
);
let result = image.variation().await?;
println!("{}", result.data.get(0).unwrap().url.clone().unwrap());
Ok(())
}