Editor API
Overview
Pixo allows you to manipulate the image and Pixo’s Plugin Settings from your application, thanks to the exec command.
The interface of exec is the following:
pixo_instance.exec('COMMAND', { param: 'value' })
where pixo_instance is a reference to an object instance of Pixo.Bridge:
const pixo_instance = new Pixo.Bridge({ option: 'value' })
Check the documentation for Pixo.Bridge constructor.
Because of its asynchronous nature, exec returns a Promise, which can be awaited, so your program knows when the operation is completed:
pixo_instance.exec('COMMAND')
    .then(state => console.log('COMMAND completed', { state }))
The promise is resolved with the updated state of Pixo Editor.
The cool part here is that instead of awaiting every single operation, you can chain a bunch of operations, and this will guarantee you that they will be executed in the same order they are invoked:
pixo_instance.exec('COMMAND1')
   .exec('COMMAND2')
   .exec('COMMANDN')
But even cooler is the fact that you don’t have to chain the commands, and they will still be executed in the right order, one after another:
pixo_instance.exec('COMMAND1');
pixo_instance.exec('COMMAND2');
pixo_instance.exec('COMMANDN');
State
The State object contains information about the current state of Pixo Editor: the currently active plugin, property values of every plugin, history, global settings, error state, etc. You can use the State object to update your external editing controls for Pixo Editor.
Subscribing to changes
You can get the new state by providing onStateChange callback to Pixo.Bridge constructor:
const pixo = new Pixo.Bridge({
    //... other options
    onStateChange: state => {
        //do something with the updated state
    },
});
The onStateChange callback will be executed every time the state changes, no matter if the change is triggered by the user within Pixo Editor or by the exec() method.
Receiving the new state
The exec() method will return a promise, which resolves when the command is executed, with the updated state:
pixo_instance.exec('ANY_COMMAND')
    .then(state => console.log('ANY_COMMAND completed', { state }))
There is also a GET_STATE command which returns current state.
Updating the state
Updating state happens through the SET_STATE command, which accept the new state as parameter. The new state is merged into the old/current state recursively, so this means that you may pass a partial state object:
const newstate = { active_plugin: 'draw' };
pixo_instance.exec('SET_STATE', { state: new_state });
Structure
The state is a JavaScript Object having the following structure:
- active_plugin Stringone of the following: “adjustments”, “filters”, “draw”, “crop”, “stickers”, “text”, “transform”, “frame”, “blur”, “shape”
- collapsed_panel Booleanwhether the Property Panel is collapsed or not
- plugins Objectcontaining data for most of Pixo’s feature plugins; has the following structure:- background Objectwith the following structure:-  type Stringone of the following: “original”, “solidcolor”, “transparent”, “replacement”
- bgcolor StringCSS color for the “solidcolor” type
 
-  type 
- crop Objectwith the following structure:- orientation Stringone of the following: “portrait”, “landscape”
- preset Numberfixed crop ratio preset, e.g.16 / 9,4 / 3, etc.
- ratio_locked Boolean
 
- orientation 
- draw Objectclick to see structure
- adjustments Objectclick to see structure
- text Objectclick to see structure
- filter Stringclick to see possible values
- frame Numberselected frame index
- shape Stringone of the following: “square”, “rectangle”, “circle”, “ellipse”, “roundsquare”, “roundrect”
 
- background 
- history Objectwith the following structure:- length Numbertotal history length
- current Numbercurrent index in the history
 
- length 
- error Stringerror message (if there is an error, otherwise will be"")
- track_history Booleanwhether history is tracked or not
Command Index
- ACTIVATE_PLUGIN
- ADD_TEXT
- ADJUST
- CROP
- GET_STATE
- INSERT_DRAW_SHAPE
- INSERT_STICKER
- REDO
- SELECT_FILTER
- SELECT_FRAME
- SELECT_SHAPE
- SET_BACKGROUND_TYPE
- SET_DRAWING_PROPERTY
- SET_MIN_CROP_DIMENSIONS
- SET_MAX_CROP_DIMENSIONS
- SET_STATE
- SET_TEXT_PROPERTY
- TRACK_HISTORY
- TRANSFORM
- UNDO
Global operations
Getting & setting the State
pixo_instance.exec('GET_STATE')
    .then(state => { console.log('current state', state) });
When updating the state, the new state is merged into the old/current state recursively, so this means that you may pass a partial state object:
pixo_instance.exec('SET_STATE', { state: { active_plugin: 'draw' } });
More information about Pixo’s State.
Activate Plugin
pixo_instance.exec('ACTIVATE_PLUGIN', { plugin: 'filters' })
See list of available plugins.
Undo/Redo
pixo_instance.exec('UNDO')
pixo_instance.exec('REDO')
Enable/Disable history tracking
Pixo allows you to disable history (undo/redo) tracking, and enable it back at any time:
pixo_instance.exec('TRACK_HISTORY', { track_history: false })
Plugin operations
Select Filter
pixo_instance.exec('SELECT_FILTER', { name: 'Amarok' })
- None
- Natural
- Amarok
- Klarendon
- Larc
- Mayfare
- Autumn
- Nightfall
- Sepia
- Grayscale
- BlackWhite
- Brownie
- Vintage
- Kodachrome
- Technicolor
- Polaroid
- Reddish
- Redify
- Convolute-Sharpen
- Convolute-ExtraSharp
- Convolute-Light
- Convolute-Dark
- Convolute-Blur
- Convolute-Emboss
- Invert
- Distressed
Insert Sticker
pixo_instance.exec('INSERT_STICKER', options)
Where options is an Object with the following shape:
- src StringThe URL of the sticker image to be inserted
- width Number(optional) The desired width of the sticker image. If the value is greater than1the width is set in pixels; otherwise it would be considered as a % of the edited image’s width, e.g.0.65= 65% of the edited image’s width. If not provided the natural width of the sticker image would be used unless larger than the edited image’s width.
- height Number(optional) The desired height of the sticker image. If the value is greater than1the height is set in pixels; otherwise it would be considered as a % of the edited image’s height, e.g.0.65= 65% of the edited image’s height. If not provided the natural height of the sticker image would be used unless larger than the edited image’s height.
- position (optional) StringorObjectwith the following possible values:- "top"
- "top-left"
- "top-right"
- "left"
- "center"
- "right"
- "bottom"
- "bottom-left"
- "bottom-right"
- Objectwith the following shape:- left NumberThe desired left boundary of the sticker image in pixels
- top NumberThe desired top boundary of the sticker image in pixels
 
- left 
 
- offset Object(optional) with the following shape:- x NumberThe desired horizontal offset in pixels (when larger than1) or % of edited image’s width
- y NumberThe desired vertical offset in pixels (when larger than1) or % of edited image’s height
 
- x 
Example:
pixo_instance.exec('INSERT_STICKER', { src: 'https://pixoeditor.com/editor/shared/images/logo.png' })
Add Text
pixo_editor.exec('ADD_TEXT', options)
Where options is an Object with the following shape:
- text Stringtext message to insert
- position (optional) StringorObjectwith the following possible values:- "top"
- "top-left"
- "top-right"
- "left"
- "center"
- "right"
- "bottom"
- "bottom-left"
- "bottom-right"
- Objectwith the following shape:- left NumberThe desired left boundary of the sticker image in pixels
- top NumberThe desired top boundary of the sticker image in pixels
 
- left 
 
- offset Object(optional) with the following shape:- x NumberThe desired horizontal offset in pixels (when larger than1) or % of edited image’s width
- y NumberThe desired vertical offset in pixels (when larger than1) or % of edited image’s height
 
- x 
- width Number(optional) The desired width of the text box. If the value is greater than1the width is set in pixels; otherwise it would be considered as a % of the edited image’s width, e.g.0.65= 65% of the edited image’s width. If not provided the width of the text box will be as big as the text inside.
- height Number(optional) The desired height of the text box. If the value is greater than1the height is set in pixels; otherwise it would be considered as a % of the edited image’s height, e.g.0.65= 65% of the edited image’s height. If not provided the height of the text box will be as big as the text inside.
- fontFamily Stringone of the following:- Arial
- Verdana
- Times New Roman
- Georgia
- Comic Sans MS
- Pacifico
- Roboto Condensed
- Oswald
- PT Sans
- Open Sans Condensed
- Ubuntu
- PT Sans Narrow
- Lobster
- Yanone Kaffeesatz
- Play
- Amatic SC
- Comfortaa
- Poiret One
- Russo One
- Philosopher
- Caveat
- Jura
- Marck Script
- Bad Script
- Montserrat Alternates
- Neucha
- Press Start 2P
- Pattaya
 
- fontSize Numberfrom10to100
- lineHeight Numberfrom-50to50
- charSpacing Number
- fontWeight Stringone of the following:- normal
- bold
 
- fontStyle Stringone of the following:- normal
- italic
 
- underline Boolean
- linethrough Boolean
- superscript Boolean
- subscript Boolean
- fill Stringany valid CSS color (incl. rgba)
- textShadow Boolean
- textShadowColor Stringany valid CSS color (incl. rgba)
- textShadowOffsetX Numberfrom-20to20
- textShadowOffsetY Numberfrom-20to20
- textShadowBlur Numberfrom0to12
- textStroke Boolean
- strokeWidth Numberfrom0to12
- textBackground Boolean
- textBackgroundColor Stringany valid CSS color (incl. rgba)
- background Boolean
- backgroundColor Stringany valid CSS color (incl. rgba)
Example:
pixo_editor.exec('ADD_TEXT', { text: 'Lorem Ipsum' })
Set Text Property
pixo_editor.exec('SET_TEXT_PROPERTY', { propname: 'fontFamily', value: 'Arial' })
- fontFamily Stringone of the following:- Arial
- Verdana
- Times New Roman
- Georgia
- Comic Sans MS
- Pacifico
- Roboto Condensed
- Oswald
- PT Sans
- Open Sans Condensed
- Ubuntu
- PT Sans Narrow
- Lobster
- Yanone Kaffeesatz
- Play
- Amatic SC
- Comfortaa
- Poiret One
- Russo One
- Philosopher
- Caveat
- Jura
- Marck Script
- Bad Script
- Montserrat Alternates
- Neucha
- Press Start 2P
- Pattaya
 
- fontSize Numberfrom10to100
- lineHeight Numberfrom-50to50
- charSpacing Number
- fontWeight Stringone of the following:- normal
- bold
 
- fontStyle Stringone of the following:- normal
- italic
 
- underline Boolean
- linethrough Boolean
- superscript Boolean
- subscript Boolean
- textAlign Stringone of the following:- left
- center
- right
 
- fill Stringany valid CSS color (incl. rgba)
- textShadow Boolean
- textShadowColor Stringany valid CSS color (incl. rgba)
- textShadowOffsetX Numberfrom-20to20
- textShadowOffsetY Numberfrom-20to20
- textShadowBlur Numberfrom0to12
- textStroke Boolean
- strokeWidth Numberfrom0to12
- textBackground Boolean
- textBackgroundColor Stringany valid CSS color (incl. rgba)
- background Boolean
- backgroundColor Stringany valid CSS color (incl. rgba)
Background
Replace existing background with solid color
pixo_instance.exec('SET_BACKGROUND_TYPE', { backgroundtype: 'solidcolor', bgcolor: 'red' })
Where “bgcolor” is a valid CSS color.
Remove background
pixo_instance.exec('SET_BACKGROUND_TYPE', { backgroundtype: 'transparent' })
Replace background
pixo_instance.exec('SET_BACKGROUND_TYPE', { backgroundtype: 'replacement', src: 'https://yourdomain.com/path/to/custom-background.jpg' })
Where “src” can be url or base64 image.
Restore original background
pixo_instance.exec('SET_BACKGROUND_TYPE', { backgroundtype: 'original' })
Select Frame
Pass the index of the frame to select:
pixo_instance.exec('SELECT_FRAME', { index: -1 })
-1 means no frame.
Select Shape
pixo_instance.exec('SELECT_SHAPE', { shape: 'circle' })
Available shapes:
- rhombus
- circle
- ellipse
- diamond
- star
- hexagon
- octagon
Crop
To crop the image with specific crop aspect ratio:
pixo_instance.exec('CROP', { crop : { ratio: 16/9 } })
To crop the image with specific crop rectangle:
pixo_instance.exec('CROP', { crop : { left: 0, right: 0, width: 200, height: 200 } })
To set minimum and maximum crop rectangle dimensions:
pixo_instance.exec('SET_MIN_CROP_DIMENSIONS', { min_width: 150, min_height: 85 })
pixo_instance.exec('SET_MAX_CROP_DIMENSIONS', { max_width: 300, max_height: 169 })
To programatically toggle the aspect ratio lock:
pixo_instance.exec('TOGGLE_CROP_RATIO_LOCK')
Transform
To rotate the image:
pixo_instance.exec('TRANSFORM', { operation: 'rotate', direction: 'right' })
Possible directions: 'left' and 'right'.
To flip the image:
pixo_instance.exec('TRANSFORM', { operation: 'flip', direction: 'hor' })
Possible directions: 'hor' and 'ver'.
Color Adjustments
pixo_instance.exec('ADJUST', { propname: 'brightness', value: 0.05 })
- brightness: -1to1
- contrast: -1to1
- hue-rotation: -2to2
- saturation: -1to1
- gamma-red: 0.01to2.2
- gamma-green: 0.01to2.2
- gamma-blue: 0.01to2.2
- blur: 0to1
- noise: 0to1000
- pixelate: 2to20
Set Draw Property
pixo_instance.exec('SET_DRAWING_PROPERTY', { propname: 'linewidth', value: 20 })
- enabled Boolean
- source String“brush” or “shape”
- brushmode Stringone of the following:- Pencil
- Circle
- Spray
- Blur
 
- linewidth Numberfrom0to150
- linecolor Stringany valid CSS color
- shapecolor Stringany valid CSS color
- shadowcolor Stringany valid CSS color
- shadowwidth Numberfrom0to150
- shadowoffset Numberfrom0to150
- blur Numberfrom0to1
Insert Draw Shape
pixo_instance.exec('INSERT_DRAW_SHAPE', { value: 'rectangle' })
List with possible shapes to insert:
- square
- rectangle
- circle
- ellipse
- roundsquare
- roundrect
