[Alpha] Templating mode
Warning: Templating mode is available as an alpha feature.
This means that the feature (or parts of it) might be deprecated with two week warning.
Overview
Templating Mode enables the scalable generation of personalized and visually consistent images by connecting predefined design templates with dynamic content.
By creating a reusable image layout (a template) in the Photoroom editor and assigning unique identifiers to each customizable layer, developers can programmatically inject content—like text, product images, or branding elements—through API calls.
This approach is ideal for automating image creation for use cases such as product listings, ads, social media creatives, and more.
Step 1: Create your template
Start a design from an image or from a Photoroom template. For example, open or upload an image in the Design tab.
Turn the design into a template to access the templating features (click on the ellipsis
...button in the top menu bar, then on theTurn into templateoption).You can now add your image and text layers.
On any text (or image) layer you can toggle on the
Replaceable Texttoggle (respectively theReplaceable Subjecttoggle). You can then edit theUnique IDfield to give each of your layer a clear name.Make the template public to enable the API to access it: select
Public linkfrom the sharing settings. This means the template is public only to the people who know about this specific template ID. It enables the API to have access to your template.Click on the
Previewtab, and click on the template ID at the bottom of this tab. This copies the template ID in your clipboard.
Step 2: Create images through the API
The key is to keep track of the Unique IDs defined in your template for each layer, as they will be reused in your API calls.
Here is an example API call:
curl --request POST \
--url https://image-api.photoroom.com/v2/edit \
--header 'x-api-key: YOUR_API_KEY' \
--form templateId=YOUR_TEMPLATE_ID \
--form 'layers.author.text.content=Tom C.' \
--form 'layers.review.text.content=”Nice product, I love it“' \
--form 'layers.product.image.imageUrl=https://images.unsplash.com/photo-1541643600914-78b084683601?q=80&w=1200&auto=format&fit=crop'
The first attribute needed is templateId, which allows you to connect the API to your template.
All layer attributes are set using layers.UNIQUE_ID.image.ATTRIBUTE or layers.UNIQUE_ID.text.ATTRIBUTE (with UNIQUE_ID replaced by the actual layer unique id, and ATTRIBUTE being replaced by the attribute you want to target).
Here is a list of all attributes:
text layer
content(string): replaces the text contentforegroundColor(hexadecimal color string): replaces the text colorbackgroundColor(hexadecimal color string): replaces the background colorfont(string): replaces the font of the text (refer to the Photoroom editor for the full list of available fonts)
image layer
imageFile(binary): replaces the image (can only specify one ofimageFileandimageUrl)imageUrl(url string): replaces the image (can only specify one ofimageFileandimageUrl)removeBackground(autoornever): choose whether to remove the background of this image (defaults toauto)useForAIBackground(autoornever): choose whether the image is taken into account when building the AI background (defaults toauto), this is only useful if you have defined an AI background in your template or API call.horizontalAlignment(left,centerorright): defines the horizontal alignment of the image within its box (defaults toauto)verticalAlignment(top,centerorbottom): defines the vertical alignment of the image within its box (defaults toauto)margin(percentage string like10%or decimal number like0.1): defines margins around the objectyou can use
marginTop,marginRight,marginBottom,marginLeftif you want to specify different margins
padding(percentage string like10%or decimal number like0.1): defines padding around the object, the padding will be ignored on each side where the segmented object is croppedyou can use
paddingTop,paddingRight,paddingBottom,paddingLeftif you want to specify different paddings
segmentation: Enables text-guided segmentation for this image. IfremoveBackgroundisnever, the result will be "zoomed" to the segmented subject.segmentation.prompt: A textual description of what the segmentation should keep, for examplebook,pen,ballsegmentation.negativePrompt(optional): A textual description of what the segmentation should removesegmentation.mode: eitherkeepSalientObjectorignoreSalientObject, defaultignoreSalientObject. If it'skeepSalientObject, the salient object of the image (i.e. what the default segmentation would have kept) will also be kept by the segmentation in addition to theprompt.
Note: the removeBackground=never and useForAIBackground=never are great when used with logos, so that only your products have their background removed and does not affect the AI background.
Here is an example of a more complex API call:
curl --request POST \\
--url https://image-api.photoroom.com/v2/edit \\
--header 'x-api-key: YOUR_API_KEY' \\
--form templateId=YOUR_TEMPLATE_ID \\
--form 'layers.author.text.content=Tom C.' \\
--form layers.author.text.foregroundColor=DC143C \\
--form layers.author.text.backgroundColor=fe9167 \\
--form 'layers.review.text.font=Permanent Marker' \\
--form 'layers.rating.text.content=★ ★ ★ ★ ☆' \\
--form 'layers.review.text.content=”Nice product, I love it“' \\
--form 'layers.cta.text.content=BUY NOW' \\
--form 'layers.product.image.imageUrl=https://images.unsplash.com/photo-1541643600914-78b084683601?q=80&w=1200&auto=format&fit=crop' \\
--form layers.product.image.removeBackground=auto \\
--form layers.product.image.useForAIBackground=auto \\
--form layers.product.image.horizontalAlignment=center \\
--form layers.product.image.verticalAlignment=center \\
--form layers.product.image.margin=0.1
Frequently Asked Questions (FAQ)
How many images can I replace (in the same row)?
There is a maximum of 10 replaceable images at the moment.
Last updated
Was this helpful?