Nordic Layers · Nordic Byte

Tài liệu API

Nordic Layers là một REST API qua HTTPS tại https://app.layers.nordicbyte.co.uk. Dự án là một tài liệu JSON gồm các lớp; bạn thay đổi nó bằng các thao tác và xuất thành ảnh. Trình chỉnh sửa trên trình duyệt dùng cùng API này.

Xác thực

Tạo khóa API trong bảng điều khiển tài khoản và gửi kèm mọi yêu cầu /v1. Khóa bắt đầu bằng nl_key_.

Authorization: Bearer nl_key_…

Quy trình thông thường

  1. Tải lên từng ảnh bằng POST /v1/assets, với tệp là nội dung thô của yêu cầu (PNG, JPEG, WebP, GIF, BMP hoặc TIFF). Phản hồi có id của ảnh.
  2. Tạo dự án bằng POST /v1/projects với width, height và background. Bạn có thể truyền luôn các steps đầu tiên trong cùng lệnh gọi.
  3. Chỉnh sửa bằng POST /v1/projects/{id}/run: một thao tác dạng {"op": …} hoặc nhiều thao tác dạng {"steps": [...]}. Xem kết quả bằng GET /v1/projects/{id}/preview, miễn phí.
  4. Xuất bằng POST /v1/projects/{id}/export. Phản hồi chứa URL của tệp, hoặc chính bức ảnh nếu dùng "response": "image".

Yêu cầu đầu tiên

Tạo dự án 1080×1080 có chuyển sắc và tiêu đề, rồi xuất sang WebP:

curl -X POST https://app.layers.nordicbyte.co.uk/v1/projects \
  -H "Authorization: Bearer $NL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "First post",
    "width": 1080,
    "height": 1080,
    "steps": [
      {"op": "layer.addFill", "gradient": {"colors": ["#1E3A5F", "#64B5F6"], "angle": 135}},
      {"op": "text.add", "content": "Hello, layers", "fontName": "Segoe UI", "fontSize": 110, "bold": true, "color": "#FFFFFF"},
      {"op": "effects.set", "shadow": {"opacity": 0.4, "distance": 12, "size": 24}}
    ]
  }'

# → {"project": {"id": "…", …}}

curl -X POST https://app.layers.nordicbyte.co.uk/v1/projects/$PROJECT_ID/export \
  -H "Authorization: Bearer $NL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "format": "webp",
    "quality": 90
  }'

Endpoint

Phương thứcĐường dẫnChức năng
GET/healthTrạng thái dịch vụ
GET/v1/opsDanh mục mọi thao tác và tham số của chúng (công khai)
POST/v1/assets?name=photo.jpgTải ảnh lên; nội dung yêu cầu là tệp
GET/v1/assetsLiệt kê ảnh của bạn và cho biết dự án nào đang dùng chúng
DELETE/v1/assets/{id}Xóa một ảnh
POST/v1/projectsTạo dự án (khung vẽ, hoặc cả tài liệu, kèm các bước tùy chọn)
GET/v1/projectsLiệt kê dự án của bạn
GET/v1/projects/{id}Một dự án cùng tài liệu của nó
PUT/v1/projects/{id}/documentThay thế toàn bộ tài liệu
POST/v1/projects/{id}/runÁp dụng một thao tác hoặc một danh sách bước
POST/v1/projects/{id}/undoHoàn tác thay đổi gần nhất
POST/v1/projects/{id}/redoLàm lại
GET/v1/projects/{id}/preview?size=1024Xem trước PNG miễn phí, cạnh dài tối đa size px
POST/v1/projects/{id}/exportXuất PNG, JPEG hoặc WebP; có thể kèm các bước chỉ áp dụng cho tệp này
POST/v1/renderKết xuất không lưu trạng thái cho cả tài liệu
GET/v1/exportsLiệt kê các bản xuất của bạn
GET/v1/exports/{id}/fileTải một bản xuất
DELETE/v1/projects/{id}Xóa một dự án

Thao tác

Mỗi thao tác là một đối tượng có op và các tham số của nó. Lớp được tham chiếu bằng id hoặc tên; nếu không có layer, lớp đang chọn sẽ được dùng. Tên không phân biệt hoa thường và khoảng trắng, nên "Linear Dodge (Add)" và "linearDodge" là cùng một chế độ hòa trộn. Với steps, các bước chạy theo thứ tự và dừng ở lỗi đầu tiên (trừ khi đặt "stopOnError": false); các bước trước đó vẫn được giữ nguyên.

Lớp

Thao tácTham sốChức năng
layer.addcolor, nameAlias of layer.addFill (the web has no empty pixel layers).
layer.addFillcolor | gradient {colors: [..], angle, type: linear|radial}, name, above, atBottomA colour or gradient layer the size of the canvas.
layer.addImageasset_id | color, name, rect | origin | center, width, height, fit (stretch|contain|cover), fitCanvas (contain|cover), above, atBottom, opacity, blendModeAdd an uploaded image (asset_id) or a solid colour (color).
layer.cliplayerClip a layer to the one below it (clipping mask).
layer.deletelayer | layersDelete layers.
layer.duplicatelayer, nameCopy a layer above itself.
layer.getlayerOne layer with all its settings.
layer.list—Layers from bottom to top.
layer.movelayer, above | below (layer), toTop, atBottom, index, offsetReorder a layer.
layer.renamelayer, nameRename a layer.
layer.selectlayerMake a layer the active one.
layer.setBlendModelayer | layers, blendMode (normal, darken, multiply, colorBurn, linearBurn, lighten, screen, colorDodge, linearDodge, overlay, softLight, hardLight, difference, exclusion, subtract, divide, hue, saturation, color, luminosity)Blend mode.
layer.setFilllayer, color | gradientChange a fill layer's colour or gradient.
layer.setImagelayer, asset_id, fit (stretch|contain|cover)Replace a layer's image and keep its box (templates).
layer.setOpacitylayer | layers, opacityLayer opacity, 0 to 1.
layer.setVisiblelayer | layers, visibleShow or hide layers.
layer.uncliplayerRelease a clipping mask.

Văn bản

Thao tácTham sốChức năng
text.addcontent, fontName, fontSize, color, alignment, leading, bold, italic, boxWidth, origin | center, nameAdd a text layer.
text.defaults—Fonts on the server and whether complex scripts are shaped.
text.setlayer, content, fontName, fontSize, color, alignment, leading, bold, italic, boxWidthChange a text layer.

Hình

Thao tácTham sốChức năng
shape.addshape, rect | from+to, color, cornerRadius, lineWidth, nameAdd a rectangle, ellipse or line.
shape.setlayer, color, cornerRadius, lineWidthChange a shape layer.

Biến đổi

Thao tácTham sốChức năng
transform.fliplayer | layers, axis (horizontal|vertical)Flip horizontally or vertically.
transform.movelayer | layers, dx, dy | to [x, y]Move by dx/dy or to a point.
transform.rotatelayer | layers, angleRotate by an angle (degrees, clockwise).
transform.scalelayer | layers, factor | percent | width | heightScale around each layer's centre.
transform.setlayer | layers, x, y, width, height, rotation, flipX, flipYBox, rotation and flips.

Điều chỉnh trên một lớp

Thao tácTham sốChức năng
adjust.blackWhitelayer | layers, reds, yellows, greens, cyans, blues, magentas, tint, tintHue, tintSaturationNon-destructive blackWhite on a layer (adds it or updates it).
adjust.brightnessContrastlayer | layers, brightness, contrastNon-destructive brightnessContrast on a layer (adds it or updates it).
adjust.clearlayer | layersRemove every adjustment and filter from a layer.
adjust.colorBalancelayer | layers, shadows, midtones, highlights, preserveLuminosityNon-destructive colorBalance on a layer (adds it or updates it).
adjust.curveslayer | layers, rgb, red, green, blueNon-destructive curves on a layer (adds it or updates it).
adjust.exposurelayer | layers, exposure, offset, gammaNon-destructive exposure on a layer (adds it or updates it).
adjust.gradientMaplayer | layers, shadows, highlights, reversedNon-destructive gradientMap on a layer (adds it or updates it).
adjust.grainlayer | layers, amount, size, seedNon-destructive grain on a layer (adds it or updates it).
adjust.hueSaturationlayer | layers, hue, saturation, lightness, colorizeNon-destructive hueSaturation on a layer (adds it or updates it).
adjust.invertlayer | layers, no settingsNon-destructive invert on a layer (adds it or updates it).
adjust.levelslayer | layers, black, white, gamma, outputBlack, outputWhiteNon-destructive levels on a layer (adds it or updates it).
adjust.removelayer | layers, kindRemove one adjustment or filter from a layer.

Bộ lọc

Thao tácTham sốChức năng
filter.addNoiselayer | layers, amount, gaussian, monochromatic, seedNon-destructive addNoise on a layer (adds it or updates it).
filter.gaussianBlurlayer | layers, radiusNon-destructive gaussianBlur on a layer (adds it or updates it).
filter.motionBlurlayer | layers, angle, distanceNon-destructive motionBlur on a layer (adds it or updates it).
filter.pixelatelayer | layers, sizeNon-destructive pixelate on a layer (adds it or updates it).
filter.sharpenlayer | layers, amount, radius, thresholdNon-destructive sharpen on a layer (adds it or updates it).
filter.vignettelayer | layers, amount, midpoint, roundness, feather, colorNon-destructive vignette on a layer (adds it or updates it).

Lớp điều chỉnh

Thao tácTham sốChức năng
adjustmentLayer.addkind, settings…, name, aboveAn adjustment layer: changes everything below it.
adjustmentLayer.getlayerAn adjustment layer's settings.
adjustmentLayer.setlayer, settings…Change an adjustment layer (partial).

Mặt nạ lớp

Thao tácTham sốChức năng
mask.addlayer, reveal | hide | rect | ellipse (rect) | gradient (from, to) | asset_id (+ rect), feather, invert, cornerRadiusAdd or replace a layer mask.
mask.blurlayer, radiusFeather the layer mask.
mask.deletelayerRemove the layer mask.
mask.invertlayerInvert the layer mask.
mask.setEnabledlayer, enabledTurn the layer mask on or off.

Hiệu ứng lớp

Thao tácTham sốChức năng
effects.copyfrom, layer | layersCopy effects from one layer to others.
effects.getlayerA layer's effects.
effects.removelayer | layers, kindsRemove effects (all, or the ones named).
effects.setlayer | layers, shadow {…}, stroke {…}, outerGlow {…}, colorOverlay {…}Set effects (partial): shadow, outerGlow, stroke, colorOverlay.
effects.setEnabledlayer, kind, enabledTurn one effect on or off.

Khung vẽ

Thao tácTham sốChức năng
canvas.croprect [x, y, width, height]Crop the canvas to a rectangle.
canvas.imageSizewidth and/or height, or percentScale the whole document.
canvas.setBackgroundcolorBackground colour, or null for transparent.
canvas.sizewidth, height, anchor (topLeft…bottomRight, default center)Change the canvas without scaling layers.

Dự án

Thao tácTham sốChức năng
project.state—The whole document.

Chế độ hòa trộn

Họ phông chữ

Mẫu

Truyền steps vào lệnh xuất và chúng sẽ được áp dụng lên một bản sao của dự án, chỉ cho tệp đó. Một mẫu, nhiều tệp: đổi văn bản bằng text.set và ảnh bằng layer.setImage, giữ nguyên khung của lớp.

curl -X POST https://app.layers.nordicbyte.co.uk/v1/projects/$TEMPLATE_ID/export \
  -H "Authorization: Bearer $NL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "format": "png",
    "steps": [
      {"op": "text.set", "layer": "Title", "content": "Nueva colección"},
      {"op": "layer.setImage", "layer": "Photo", "asset_id": "photo_dunes"}
    ]
  }'

Kết xuất không lưu trạng thái

POST /v1/render nhận một document đầy đủ (như được trả về trong project.document), các steps tùy chọn và tùy chọn xuất, và không lưu dự án. Với "response": "image", phản hồi là tệp ảnh.

curl -X POST https://app.layers.nordicbyte.co.uk/v1/render \
  -H "Authorization: Bearer $NL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {"width": 1200, "height": 630, "background": "#1E3A5F", "layers": ["…"]},
    "format": "png",
    "response": "image"
  }' \
  -o card.png

Lỗi

Lỗi được trả về dưới dạng JSON với code ổn định và thông báo detail bằng ngôn ngữ của tài khoản bạn. Một bước thất bại sẽ cho biết tham số nào sai. Khi hết lượt kết xuất của gói, API trả về 402 kèm quota_renders.

Giới hạn