Image API는 Product Studio 하위 API의 일부입니다. Google Product Studio(GPS) API의 생성형 AI 도구를 활용하여 제품 이미지를 생성하고 최적화합니다. 이를 사용하여 고객 참여도와 전환을 개선할 수 있습니다.
API를 사용하여 무엇을 생성할 수 있나요?
- 제공된 제품 정보와 텍스트 프롬프트를 기반으로 AI가 생성한 배경이 있는 제품 이미지
- 원본 이미지의 배경이 삭제된 제품 이미지
- 원본 이미지의 해상도가 개선된 제품 이미지
이미지 배경 생성
GenerateProductImageBackground
메서드는 원본 제품 이미지와 배경을 설명하는 텍스트 프롬프트를 사용하여 AI 생성 배경이 있는 제품 이미지를 만들 수 있습니다.
API는 다음을 허용합니다.
- 제품 이미지: 다음 중 하나일 수 있습니다.
- 제품 이미지를 가리키는 URI (예:
{"image_uri": "https://my-store.com/img/1.png"}
) - 원시 이미지 바이트(예:
{"image_bytes": b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01'}
)
- 제품 이미지를 가리키는 URI (예:
- 프롬프트: 생성할 배경을 지정하는 문자열입니다.
product_description
: 제품 설명입니다.background_description
: 원하는 배경에 대한 설명입니다.
이미지 배경 삭제하기
RemoveProductImageBackground
메서드는 원본 제품 이미지에서 배경이 삭제된 이미지를 생성할 수 있습니다.
API는 다음을 허용합니다.
- 제품 이미지: 다음 중 하나일 수 있습니다.
- 제품 이미지를 가리키는 URI입니다(예:
{"image_uri": "https://my-store.com/img/1.png"}
). - 원시 이미지 바이트(예:
{"image_bytes": b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01'}
)
- 제품 이미지를 가리키는 URI입니다(예:
- 배경 색상: 삭제 후 배경의 색상입니다. RGB 형식으로 제공됩니다. 색상이 지정되지 않으면 배경은 RGBA 4채널 투명 이미지가 됩니다.
이미지 확대
UpscaleProductImage
메서드는 원본 제품 이미지의 해상도가 향상된 이미지를 생성할 수 있습니다.
API는 제품 이미지를 허용합니다. 다음 중 하나일 수 있습니다.
- 제품 이미지를 가리키는 URI입니다(예:
{"image_uri": "https://my-store.com/img/1.png"}
). - 원시 이미지 바이트(예:
{"image_bytes": "image_bytes"}
)
클라이언트 라이브러리 사용
클라이언트 라이브러리를 사용하여 요청을 제출하는 것이 좋습니다. 언어에 지원되는 클라이언트 라이브러리가 없는 경우 Maven 프로젝트 내에 설치할 수 있도록 이메일이나 공유 드라이브 폴더를 통해 라이브러리 파일을 직접 제공해 드릴 수 있습니다.
예
다음 예에서는 API를 사용하여 제품 이미지를 생성하거나 최적화합니다.
제품 이미지의 배경 생성
이 예시에서는 선택한 배경으로 제품 이미지를 생성하는 방법을 보여줍니다.
요청
요청 본문에는 이미지 (URI 또는 바이트)와 배경 생성 프롬프트가 포함됩니다. 이미지 URI를 사용하는 요청 구조의 예는 다음과 같습니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground
{
"input_image": {
"image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
},
"config": {
"product_description": "a jar",
"background_description": "sitting on a cracked stone surface surrounded by a cherry blossom tree and pink and white flowers in the background, high resolution, product photography, strong shadows and lights, creative"
}
}
또는 원시 이미지 바이트를 사용할 수 있습니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground
{
"input_image": {
"image_bytes": "b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff'"
},
"config": {
"product_description": "a jar",
"background_description": "sitting on a cracked stone surface surrounded by a cherry blossom tree and pink and white flowers in the background, high resolution, product photography, strong shadows and lights, creative"
}
}
응답
다음과 같은 응답이 표시됩니다.
{
"generated_image": {
"image_bytes": "b'\x7d\x1b\x8f\x04\x5c\x9e\x23\xf0\x6a\xd1\x4b\x87\x0c\x3e\xa9\x21\xb5'",
"generation_time": "2025-05-13T00:06:54.754828Z"
},
}
또는 return_image_uri
이 output_config,
에서 true
로 설정된 경우 다음과 같이 표시됩니다.
{
"generated_image": {
"uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEvIFfK0YaLKvwvIBc9ItJtJGFE6hi25o6-N3Fz6YTw57pFghfIVlCGve7eyJcQkhoAqGAf8NDzW70qjwGOCuHhiouqF2nqxBwCcfDxZPkYRl3h7CIjyev9asJw7x-0g0V_xvurfowZJ0moXu98kmV01A3Thv2ZRlTAiOPYuEb8wnY7EeyD9l48lDdwJgZ4jqxtTgrRbwvpno4NICj9q830RzATiBHuJ_WUFQJiHOMAqbGyrQIWQTQ",
"generation_time": "2025-05-13T00:06:54.754828Z"
}
}
코드 샘플
다음은 제품 이미지 배경을 생성하는 방법을 보여주는 코드 샘플입니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateImageBackgroundConfig;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductImageBackgroundRequest;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductImageBackgroundResponse;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceSettings;
import com.google.shopping.merchant.productstudio.v1alpha.InputImage;
import com.google.shopping.merchant.productstudio.v1alpha.OutputImageConfig;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create product images with generated backgrounds. */
public class GenerateProductImageBackgroundSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void generateProductImageBackground(Config config, String imageUri)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
ImageServiceSettings imageServiceSettings =
ImageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ImageServiceClient imageServiceClient = ImageServiceClient.create(imageServiceSettings)) {
OutputImageConfig outputImageConfig =
// Set this field to false to return the image bytes in the response instead.
OutputImageConfig.newBuilder().setReturnImageUri(true).build();
InputImage inputImage =
InputImage.newBuilder()
// You can also use image bytes here instead of a URI.
.setImageUri(imageUri)
.build();
GenerateImageBackgroundConfig generateImageBackgroundConfig =
GenerateImageBackgroundConfig.newBuilder()
.setProductDescription("a jar")
.setBackgroundDescription(
"sitting on a cracked stone surface surrounded by a cherry blossom tree and pink"
+ " and white flowers in the background, high resolution, product"
+ " photography, strong shadows and lights, creative")
.build();
GenerateProductImageBackgroundRequest request =
GenerateProductImageBackgroundRequest.newBuilder()
.setName(name)
.setOutputConfig(outputImageConfig)
.setInputImage(inputImage)
.setConfig(generateImageBackgroundConfig)
.build();
System.out.println("Sending GenerateProductImageBackground request: " + name);
GenerateProductImageBackgroundResponse response =
imageServiceClient.generateProductImageBackground(request);
System.out.println("Generated product image background response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Replace with your image URI.
String imageUri =
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg";
generateProductImageBackground(config, imageUri);
}
}
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import GenerateImageBackgroundConfig
from google.shopping.merchant_productstudio_v1alpha import GenerateProductImageBackgroundRequest
from google.shopping.merchant_productstudio_v1alpha import ImageServiceClient
from google.shopping.merchant_productstudio_v1alpha import InputImage
from google.shopping.merchant_productstudio_v1alpha import OutputImageConfig
# Gets the merchant account ID from the user's configuration.
_ACCOUNT = configuration.Configuration().read_merchant_info()
# The name of the account to which the request is sent.
# Format: accounts/{account}
_NAME = f"accounts/{_ACCOUNT}"
def generate_product_image_background(image_uri: str) -> None:
"""Generates a product image with a custom background.
Args:
image_uri: The URI of the input image.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = ImageServiceClient(credentials=credentials)
# Creates the output config.
# Set `return_image_uri` to False to return the image bytes in the response.
output_config = OutputImageConfig(return_image_uri=True)
# Creates the input image.
# You can also use image bytes here instead of a URI.
input_image = InputImage(image_uri=image_uri)
# Creates the generate image background config.
generate_image_background_config = GenerateImageBackgroundConfig(
product_description="a jar",
background_description=(
"sitting on a cracked stone surface surrounded by a cherry blossom"
" tree and pink and white flowers in the background, high"
" resolution, product photography, strong shadows and lights,"
" creative"
),
)
# Creates the request.
request = GenerateProductImageBackgroundRequest(
name=_NAME,
output_config=output_config,
input_image=input_image,
config=generate_image_background_config,
)
# Makes the request and catches and prints any error messages.
try:
print(f"Sending GenerateProductImageBackground request: {_NAME}")
response = client.generate_product_image_background(request=request)
print("Generated product image background response below:")
print(response)
except RuntimeError as e:
print("Request failed.")
print(e)
if __name__ == "__main__":
# The URI of the image to use as the base for the generation.
# Replace with your image URI.
_IMAGE_URI = (
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
)
generate_product_image_background(_IMAGE_URI)
제품 이미지에서 배경 삭제하기
이 예에서는 제품 이미지에서 배경을 삭제하는 방법을 보여줍니다.
요청
요청 본문에는 이미지 (URI 또는 바이트)와 선택적으로 배경을 대체할 색상이 포함됩니다.
참고:
- [0~255] 범위의 RGB 형식으로 색상 값을 지정합니다.
- 배경색을 지정하지 않으면 RGBA 4채널 투명 이미지가 됩니다.
다음은 이미지 URI를 사용하고 배경을 녹색 (0, 255, 0)으로 설정하는 요청 구조의 예입니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:removeProductImageBackground
{
"input_image": {
"image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
},
"config": {
"background_color": {
"red": 0,
"green": 255,
"blue": 0
}
}
}
또는 원시 이미지 바이트를 사용하여 동일한 기능을 실행할 수 있습니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:removeProductImageBackground
{
"input_image": {
"image_bytes": "b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff'"
},
"config": {
"background_color": {
"red": 0,
"green": 255,
"blue": 0
}
}
}
응답
다음과 같은 응답이 표시됩니다.
{
"generated_image": {
"image_bytes": "b'\x7d\x1b\x8f\x04\x5c\x9e\x23\xf0\x6a\xd1\x4b\x87\x0c\x3e\xa9\x21\xb5'",
"generation_time": "2025-05-13T00:06:54.754828Z"
},
}
또는 return_image_uri
이 output_config
에서 true
로 설정된 경우 다음과 같이 표시됩니다.
{
"generated_image": {
"uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEsYi83dcMKVV44i3vHDHzz_PJLuPyJHh9iX7IrsZ0ZIIRIS6SB4ovBmr0L9lZ1VNacZ5duwhcJ8Q8mXMYaIEArf2ieC2OuKEhRzVb-UxlkAUpitEpS5-M3Y3Ch3TGhQTZmBJXlsHLTuf0XcPwNHoNxJlgF0v_mQ6DIlPugZKC_WiYN2DNUkJivfr4WvifhMn5NaMKpDwpH4Acj-bdGNQ77M-8sj4SyEu3sHCF8ZtnMvF5DbGIYOJQ"
}
}
코드 샘플
다음은 제품 이미지 배경을 삭제하는 방법을 보여주는 코드 샘플입니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceSettings;
import com.google.shopping.merchant.productstudio.v1alpha.InputImage;
import com.google.shopping.merchant.productstudio.v1alpha.OutputImageConfig;
import com.google.shopping.merchant.productstudio.v1alpha.RemoveImageBackgroundConfig;
import com.google.shopping.merchant.productstudio.v1alpha.RemoveProductImageBackgroundRequest;
import com.google.shopping.merchant.productstudio.v1alpha.RemoveProductImageBackgroundResponse;
import com.google.shopping.merchant.productstudio.v1alpha.RgbColor;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create product images with the background removed. */
public class RemoveProductImageBackgroundSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void removeProductImageBackground(Config config, String imageUri) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
ImageServiceSettings imageServiceSettings =
ImageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ImageServiceClient imageServiceClient = ImageServiceClient.create(imageServiceSettings)) {
OutputImageConfig outputImageConfig =
// Set this field to false to return the image bytes in the response instead.
OutputImageConfig.newBuilder().setReturnImageUri(true).build();
InputImage inputImage =
InputImage.newBuilder()
// You can also use image bytes here instead of a URI.
.setImageUri(imageUri)
.build();
RemoveImageBackgroundConfig removeImageBackgroundConfig =
RemoveImageBackgroundConfig.newBuilder()
// Setting the background color to green. Don't set this field if you want the image
// to have a RGBA 4-channel transparent image as the background.
.setBackgroundColor(RgbColor.newBuilder().setRed(0).setGreen(255).setBlue(0))
.build();
RemoveProductImageBackgroundRequest request =
RemoveProductImageBackgroundRequest.newBuilder()
.setName(name)
.setOutputConfig(outputImageConfig)
.setInputImage(inputImage)
.setConfig(removeImageBackgroundConfig)
.build();
System.out.println("Sending RemoveProductImageBackground request: " + name);
RemoveProductImageBackgroundResponse response =
imageServiceClient.removeProductImageBackground(request);
System.out.println("Removed product image background response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Replace with your image URI.
String imageUri =
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg";
removeProductImageBackground(config, imageUri);
}
}
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import ImageServiceClient
from google.shopping.merchant_productstudio_v1alpha import InputImage
from google.shopping.merchant_productstudio_v1alpha import OutputImageConfig
from google.shopping.merchant_productstudio_v1alpha import RemoveImageBackgroundConfig
from google.shopping.merchant_productstudio_v1alpha import RemoveProductImageBackgroundRequest
from google.shopping.merchant_productstudio_v1alpha import RgbColor
# Gets the merchant account ID from the user's configuration.
_ACCOUNT = configuration.Configuration().read_merchant_info()
# The name of the account to which the request is sent.
# Format: accounts/{account}
_NAME = f"accounts/{_ACCOUNT}"
def remove_product_image_background(image_uri: str) -> None:
"""Removes the background from a product image.
Args:
image_uri: The URI of the input image.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = ImageServiceClient(credentials=credentials)
# Creates the output config.
# Set `return_image_uri` to False to return the image bytes in the response.
output_config = OutputImageConfig(return_image_uri=True)
# Creates the input image.
# You can also use image bytes here instead of a URI.
input_image = InputImage(image_uri=image_uri)
# Creates the remove image background config.
# Setting the background color to green. Don't set this field if you want the
# image to have a RGBA 4-channel transparent image as the background.
remove_image_background_config = RemoveImageBackgroundConfig(
background_color=RgbColor(red=0, green=255, blue=0)
)
# Creates the request.
request = RemoveProductImageBackgroundRequest(
name=_NAME,
output_config=output_config,
input_image=input_image,
config=remove_image_background_config,
)
# Makes the request and catches and prints any error messages.
try:
print(f"Sending RemoveProductImageBackground request: {_NAME}")
response = client.remove_product_image_background(request=request)
print("Removed product image background response below:")
print(response)
except RuntimeError as e:
print("Request failed.")
print(e)
if __name__ == "__main__":
# The URI of the image to remove the background from.
# Replace with your image URI.
_IMAGE_URI = (
"https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
)
remove_product_image_background(_IMAGE_URI)
제품 이미지 확대
이 예에서는 제품 이미지의 품질과 크기를 개선하는 방법을 보여줍니다.
요청
요청 본문에는 이미지 (URI 또는 바이트)가 포함됩니다. 다음은 이미지 URI를 사용하는 요청 구조의 예입니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:upscaleProductImage
{
"input_image": {
"image_uri": "https://services.google.com/fh/files/misc/ring_image_400_600.jpg"
}
}
또는 원시 이미지 바이트를 대신 사용할 수 있습니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:upscaleProductImage
{
"input_image": {
"image_bytes": "b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff'"
}
}
응답
다음과 같은 대답을 받을 수 있습니다.
{
"generated_image": {
"image_bytes": "b'\x7d\x1b\x8f\x04\x5c\x9e\x23\xf0\x6a\xd1\x4b\x87\x0c\x3e\xa9\x21\xb5'",
"generation_time": "2025-05-13T00:06:54.754828Z"
},
}
또는 return_image_uri
이 output_config,
에서 true
로 설정된 경우 다음과 같이 표시됩니다.
{
"generated_image": {
"uri": "https://lh3.googleusercontent.com/gps-generations/AI9LgEvIFfK0YaLKvwvIBc9ItJtJGFE6hi25o6-N3Fz6YTw57pFghfIVlCGve7eyJcQkhoAqGAf8NDzW70qjwGOCuHhiouqF2nqxBwCcfDxZPkYRl3h7CIjyev9asJw7x-0g0V_xvurfowZJ0moXu98kmV01A3Thv2ZRlTAiOPYuEb8wnY7EeyD9l48lDdwJgZ4jqxtTgrRbwvpno4NICj9q830RzATiBHuJ_WUFQJiHOMAqbGyrQIWQTQ"
}
}
코드 샘플
제품 이미지를 업스케일하는 방법을 보여주는 코드 샘플은 다음과 같습니다.
자바
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.ImageServiceSettings;
import com.google.shopping.merchant.productstudio.v1alpha.InputImage;
import com.google.shopping.merchant.productstudio.v1alpha.OutputImageConfig;
import com.google.shopping.merchant.productstudio.v1alpha.UpscaleProductImageRequest;
import com.google.shopping.merchant.productstudio.v1alpha.UpscaleProductImageResponse;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create upscaled product images. */
public class UpscaleProductImageSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void upscaleProductImage(Config config, String imageUri) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
ImageServiceSettings imageServiceSettings =
ImageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ImageServiceClient imageServiceClient = ImageServiceClient.create(imageServiceSettings)) {
OutputImageConfig outputImageConfig =
// Set this field to false to return the image bytes in the response instead.
OutputImageConfig.newBuilder().setReturnImageUri(true).build();
InputImage inputImage =
InputImage.newBuilder()
// You can also use image bytes here instead of a URI.
.setImageUri(imageUri)
.build();
UpscaleProductImageRequest request =
UpscaleProductImageRequest.newBuilder()
.setName(name)
.setOutputConfig(outputImageConfig)
.setInputImage(inputImage)
.build();
System.out.println("Sending UpscaleProductImage request: " + name);
UpscaleProductImageResponse response = imageServiceClient.upscaleProductImage(request);
System.out.println("Upscaled product image response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// Replace with your image URI.
String imageUri = "https://services.google.com/fh/files/misc/ring_image_400_600.jpg";
upscaleProductImage(config, imageUri);
}
}
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import ImageServiceClient
from google.shopping.merchant_productstudio_v1alpha import InputImage
from google.shopping.merchant_productstudio_v1alpha import OutputImageConfig
from google.shopping.merchant_productstudio_v1alpha import UpscaleProductImageRequest
# Gets the merchant account ID from the user's configuration.
_ACCOUNT = configuration.Configuration().read_merchant_info()
# The name of the account to which the request is sent.
# Format: accounts/{account}
_NAME = f"accounts/{_ACCOUNT}"
def upscale_product_image(image_uri: str) -> None:
"""Upscales a product image.
Args:
image_uri: The URI of the input image.
"""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = ImageServiceClient(credentials=credentials)
# Creates the output config.
# Set `return_image_uri` to False to return the image bytes in the response.
output_config = OutputImageConfig(return_image_uri=True)
# Creates the input image.
# You can also use image bytes here instead of a URI.
input_image = InputImage(image_uri=image_uri)
# Creates the request.
request = UpscaleProductImageRequest(
name=_NAME, output_config=output_config, input_image=input_image
)
# Makes the request and catches and prints any error messages.
try:
print(f"Sending UpscaleProductImage request: {_NAME}")
response = client.upscale_product_image(request=request)
print("Upscaled product image response below:")
print(response)
except RuntimeError as e:
print("Request failed.")
print(e)
if __name__ == "__main__":
# The URI of the image to upscale.
# Replace with your image URI.
_IMAGE_URI = "https://services.google.com/fh/files/misc/ring_image_400_600.jpg"
upscale_product_image(_IMAGE_URI)
일반적인 오류 및 문제
다음은 몇 가지 일반적인 문제와 해결 방법입니다.
'입력 이미지가 필요합니다.'
다음과 같은 오류 메시지가 표시되면 요청 본문에 input_image
를 추가하세요.
Error message:
"error": {
"code": 400,
"message": "[input_image] Input image is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
'이미지 필드가 하나 이상 필요합니다'
다음 오류 메시지가 표시되면 요청 본문에서 image_uri
또는 image_bytes
중 하나만 올바르게 채우세요.
Error message:
"error": {
"code": 400,
"message": "[input_image.image] At least one field of image is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
예를 들어 다음과 같이 게시하면 오류가 발생합니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground
{
"config": {
"product_description": "a jar",
"background_description": "sitting on a cracked stone surface surrounded by a cherry blossom tree and pink and white flowers in the background, high resolution, product photography, strong shadows and lights, creative"
}
}
'제품 이미지 배경을 생성하려면 구성이 필요합니다'
이 오류가 발생하면 요청 본문에 config
를 추가하고 product_description
와 background_description
를 모두 채웁니다.
Error message:
"error": {
"code": 400,
"message": "[config] Config is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
예를 들어 이를 게시하면 오류가 발생합니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground
{
"input_image": {
"image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
}
}
'제품 이미지를 생성하려면 제품 설명이 필요합니다'
다음 두 오류 메시지 중 하나가 표시되면 config
에서 product_description
와 background_description
를 모두 입력해야 합니다.
다음은 제품 설명이 누락된 경우의 예입니다.
Error message:
"error": {
"code": 400,
"message": "[config.product_description] Product description is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
다음은 배경 설명이 누락된 예입니다.
Error message:
"error": {
"code": 400,
"message": "[config.background_description] Background description is required to generate product image background.",
"status": "INVALID_ARGUMENT",
...
}
예를 들어 다음 요청을 실행하면 오류가 발생합니다.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}/generatedImages:generateProductImageBackground
{
"input_image": {
"image_uri": "https://services.google.com/fh/files/misc/abundance_intention_bath_salts.jpg"
},
"config": {
}
}