psd.url
.
Each worker can load one PSD and you can have hundreds of concurrent workers with the same or
different PSDs. Workers go to sleep automatically after a period of inactivity configurable with
the timeout
parameter. To awaken a worker and resume where you left
off, simply interact with it via any of the API endpoints. Workers are ephemeral and their
id
should not be stored in persistent storage. 72 hours after a worker is
first spawned its state is lost.
psd .name
string
required
name
so that it can be retrieved from cache. If you make changes to your PSD, make sure to use a different name
so that the old version is not retrieved from cache.
psd .url
string
required
timeout
number
default:
60
id
string
psd .id
string
psd .name
string
name
so that it can be retrieved from cache. If you make changes to your PSD, make sure to use a different name
so that the old version is not retrieved from cache.
psd .url
string
psd .width
number
psd .height
number
const data = {
"psd": {
"name": "studio-model-tshirt-v1",
"url": "https://mockups.printondemand.tools/pexels-mart-production-9558724.zip"
},
"timeout": 60
}
fetch(`https://api.mockcity.com/v1/workers`, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`
}
}).then((r) => r.json())
{
"id": "59128b48-fef2-4ed5-908d-d621cdbb0840",
"psd": {
"id": "59128b48-fef2-4ed5-908d-d621cdbb0840",
"name": "studio-model-tshirt-v1",
"url": "https://mockups.printondemand.tools/pexels-mart-production-9558724.zip",
"width": 1920,
"height": 1920
},
"timeout": 60
}
{workerId}
workerId
. To awaken a worker and
resume where you left off, simply interact with it via any of the API endpoints. 72 hours after a
worker is first spawned its state is lost. Workers are ephemeral by nature and their
id
s should not be stored in persistent storage such as a database.
fetch(`https://api.mockcity.com/v1/workers/${workerId}`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${API_KEY}`
}
})
{workerId}
children
property with nested SmartObjects.
[number]id
string
id
is a deterministic and based on the the position of the SmartObject layer in the PSD.
[number]parentId
string | null
null
if the SmartObject is not nested in another SmartObject's document and is instead found the main PSD document.
[number]name
string
[number]width
number
[number]height
number
[number]imageParams
number
[number]bgColor
string
[number]imageParams .anchor .x
number
x
origin point of the image. The default is 0.5
, the centre of the image.
[number]imageParams .anchor .y
number
y
origin point of the image. The default is 0.5
, the centre of the image.
[number]imageParams .fit
string
inside
, outside
, width
and height
.
Describes how the image should fit the box defined by imageParams.width
and imageParams.height
. Loosely based on Sharp's resize fit option.
Tip: If you want to cover the entire SmartObject with your image, use fit outside
and make sure to keep the image centered and imageParams.width
and imageParams.height
set to 1
.
[number]imageParams .width
number
500px
and a imageParams.width
value of 0.5
:
500px
× 0.5
= 250px
[number]imageParams .height
number
400px
and a imageParams.height
value of 0.5
:
400px
× 0.5
= 200px
[number]imageParams .x
number
imageParams.width
.
[number]imageParams .y
number
imageParams.height
.
[number]imageParams .opacity
number
0
to 1
.
[number]imageParams .rotation
number
[number]children
array
children
array, resulting in a tree of SmartObjects.
fetch(`https://api.mockcity.com/v1/workers/${workerId}/smartobjects`, {
method: 'GET',
headers: {
Authorization: `Bearer ${API_KEY}`
}
}).then((r) => r.json())
[
{
"id": "0",
"parentId": null,
"name": "Layer 1.psd",
"width": 1269,
"height": 1514,
"bgColor": "#d1d5db",
"imageParams": {
"anchor": {
"x": 0,
"y": 0
},
"fit": "outside",
"height": 1,
"width": 1,
"x": 0,
"y": 0,
"opacity": 1,
"rotation": 0
},
"children": [
{
"id": "1",
"parentId": "0",
"name": "Nested Layer 1.psd",
"width": 500,
"height": 500,
"bgColor": "transparent",
"imageParams": {
"anchor": {
"x": 0.5,
"y": 0.5
},
"fit": "inside",
"height": 1,
"width": 1,
"x": 0.5,
"y": 0.5,
"opacity": 1,
"rotation": 0
},
"children": []
}
]
}
]
{workerId}
{smartObjectId}
smartObjectId
. Nested
SmartObjects can be accessed through the
children
property.
workerId
string
required
smartObjectId
string
required
id
string
id
is a deterministic and based on the the position of the SmartObject layer in the PSD.
parentId
string | null
null
if the SmartObject is not nested in another SmartObject's document and is instead found the main PSD document.
name
string
width
number
height
number
imageParams
number
bgColor
string
imageParams .anchor .x
number
x
origin point of the image. The default is 0.5
, the centre of the image.
imageParams .anchor .y
number
y
origin point of the image. The default is 0.5
, the centre of the image.
imageParams .fit
string
inside
, outside
, width
and height
.
Describes how the image should fit the box defined by imageParams.width
and imageParams.height
. Loosely based on Sharp's resize fit option.
Tip: If you want to cover the entire SmartObject with your image, use fit outside
and make sure to keep the image centered and imageParams.width
and imageParams.height
set to 1
.
imageParams .width
number
500px
and a imageParams.width
value of 0.5
:
500px
× 0.5
= 250px
imageParams .height
number
400px
and a imageParams.height
value of 0.5
:
400px
× 0.5
= 200px
imageParams .x
number
imageParams.width
.
imageParams .y
number
imageParams.height
.
imageParams .opacity
number
0
to 1
.
imageParams .rotation
number
children
array
children
array, resulting in a tree of SmartObjects.
fetch(`https://api.mockcity.com/v1/workers/${workerId}/smartobjects/${smartObjectId}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${API_KEY}`
}
}).then((r) => r.json())
{
"id": "0",
"parentId": null,
"name": "Layer 1.psd",
"width": 1269,
"height": 1514,
"bgColor": "#d1d5db",
"imageParams": {
"anchor": {
"x": 0,
"y": 0
},
"fit": "outside",
"height": 1,
"width": 1,
"x": 0,
"y": 0,
"opacity": 1,
"rotation": 0
},
"children": [
{
"id": "1",
"parentId": "0",
"name": "Nested Layer 1.psd",
"width": 500,
"height": 500,
"bgColor": "transparent",
"imageParams": {
"anchor": {
"x": 0.5,
"y": 0.5
},
"fit": "inside",
"height": 1,
"width": 1,
"x": 0.5,
"y": 0.5,
"opacity": 1,
"rotation": 0
},
"children": []
}
]
}
{workerId}
{smartObjectId}
workerId
string
required
smartObjectId
string
required
bgColor
string
default:
transparent
imageParams .anchor .x
number
default:
0.5
x
origin point of the image. The default is 0.5
, the centre of the image.
imageParams .anchor .y
number
default:
0.5
y
origin point of the image. The default is 0.5
, the centre of the image.
imageParams .fit
string
default:
inside
inside
, outside
, width
and height
.
Describes how the image should fit the box defined by imageParams.width
and imageParams.height
. Loosely based on Sharp's resize fit option.
Tip: If you want to cover the entire SmartObject with your image, use fit outside
and make sure to keep the image centered and imageParams.width
and imageParams.height
set to 1
.
imageParams .width
number
default:
1
500px
and a imageParams.width
value of 0.5
:
500px
× 0.5
= 250px
imageParams .height
number
default:
1
400px
and a imageParams.height
value of 0.5
:
400px
× 0.5
= 200px
imageParams .x
number
default:
0.5
imageParams.width
.
imageParams .y
number
default:
0.5
imageParams.height
.
imageParams .opacity
number
default:
1
0
to 1
.
imageParams .rotation
number
id
string
id
is a deterministic and based on the the position of the SmartObject layer in the PSD.
parentId
string | null
null
if the SmartObject is not nested in another SmartObject's document and is instead found the main PSD document.
name
string
width
number
height
number
imageParams
number
bgColor
string
imageParams .anchor .x
number
x
origin point of the image. The default is 0.5
, the centre of the image.
imageParams .anchor .y
number
y
origin point of the image. The default is 0.5
, the centre of the image.
imageParams .fit
string
inside
, outside
, width
and height
.
Describes how the image should fit the box defined by imageParams.width
and imageParams.height
. Loosely based on Sharp's resize fit option.
Tip: If you want to cover the entire SmartObject with your image, use fit outside
and make sure to keep the image centered and imageParams.width
and imageParams.height
set to 1
.
imageParams .width
number
500px
and a imageParams.width
value of 0.5
:
500px
× 0.5
= 250px
imageParams .height
number
400px
and a imageParams.height
value of 0.5
:
400px
× 0.5
= 200px
imageParams .x
number
imageParams.width
.
imageParams .y
number
imageParams.height
.
imageParams .opacity
number
0
to 1
.
imageParams .rotation
number
children
array
children
array, resulting in a tree of SmartObjects.
const data = {
bgColor: '#d1d5db',
// make image cover entire SmartObject document
imageParams: {
// set top left of image as its origin
anchor: {
x: 0,
y: 0
},
fit: 'outside', // refer to Sharp's resize 'fit' option to understand how 'outside' works
width: 1, // 100% of SmartObject width
height: 1, // 100% of SmartObject height
// position image at top left corner of SmartObject document
x: 0, // 0% of SmartObject width
y: 0 // 0% of SmartObject height
}
}
fetch(`https://api.mockcity.com/v1/workers/${workerId}/smartobjects/${smartObjectId}`, {
method: 'PATCH',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`
}
}).then((r) => r.json())
{
"id": "0",
"parentId": null,
"name": "Layer 1.psd",
"width": 1269,
"height": 1514,
"bgColor": "#d1d5db",
"imageParams": {
"anchor": {
"x": 0,
"y": 0
},
"fit": "outside",
"height": 1,
"width": 1,
"x": 0,
"y": 0,
"opacity": 1,
"rotation": 0
},
"children": [
{
"id": "1",
"parentId": "0",
"name": "Nested Layer 1.psd",
"width": 500,
"height": 500,
"bgColor": "transparent",
"imageParams": {
"anchor": {
"x": 0.5,
"y": 0.5
},
"fit": "inside",
"height": 1,
"width": 1,
"x": 0.5,
"y": 0.5,
"opacity": 1,
"rotation": 0
},
"children": []
}
]
}
{workerId}
{smartObjectId}
ArrayBuffer
on the request body.
workerId
string
required
smartObjectId
string
required
let imageArrayBuffer
// get image ArrayBuffer from canvas
let canvas // assign and draw to canvas
imageArrayBuffer = await canvas.toBlob((blob) => blob.arrayBuffer())
// or get image ArrayBuffer from URL
imageArrayBuffer = await fetch('https://mockcity.com/examples/peachy.png').then((res) =>
res.arrayBuffer()
)
const body = imageArrayBuffer
fetch(`https://api.mockcity.com/v1/workers/${workerId}/smartobjects/${smartObjectId}/image`, {
method: 'PUT',
body: body,
headers: {
'Content-Type': 'application/octet-stream',
Authorization: `Bearer ${API_KEY}`
}
})
{workerId}
ArrayBuffer
. Image dimensions
and format can be manipulated by supplying valid
Sharp resize
and
image output
options as a sharp
array of
{ method: methodName, params: methodParams } objects.
sharp[number] .method
string
resize
and image formats webp
, jpeg
and png
.
sharp[number] .params
array
const data = {
sharp: [
{ method: 'resize', params: [{ width: 512, height: 512, fit: 'outside' }] },
{ method: 'webp', params: [{ quality: 90 }] }
]
}
fetch(`https://api.mockcity.com/v1/workers/${workerId}/mockup`, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`
}
}).then((r) => r.arrayBuffer())