Let's consider the following execute call:
const { outputFiles, exitCode, stderr} = await execute({
inputFiles: [await buildInputFile('fn.png', 'image1.png')],
commands: `
convert image1.png -bordercolor #ffee44 -background #eeff55 +polaroid image2.png
convert image2.png -fill #997711 -tint 55 image3.jpg
`
})
if (exitCode) {
alert(`There was an error with the command: ${stderr.join('\n')}`)
}
else {
await loadImageElement(outputFiles[1], document.querySelector('#outputImage'))
}
-
See execute and executeAndReturnOutputFile for information on how to execute commands. Also ExecuteResult and ExecuteConfig.
-
See ExecuteCommand for information about command syntaxes supported. Some utilities related to commands are asCommand, cliToArray, arrayToCli
-
See MagickInputFile, MagickOutputFile for information about image magick files.
- Some utilities related to files are buildInputFile, asInputFile, asOutputFile, loadImageElement, getInputFilesFromHtmlInputElement
-
See call for the low level command execution API
-
Some utilities related to images are: compare, extractInfo, getBuiltInImages
-
Some utilities related to image and execution management are ImageHome, ExecutionContext
- CallResult
- ExecuteConfig
- ExecuteEvent
- ExecuteListener
- ExecuteResult
- ExecuteResultOne
- ExecutionContext
- ImageHome
- MagickFile
- MagickInputFile
- MagickOutputFile
- Call
- addExecuteListener
- arrayToCli
- asCommand
- asExecuteConfig
- asInputFile
- asOutputFile
- blobToString
- buildImageSrc
- buildInputFile
- call
- cliToArray
- compare
- compareNumber
- createImageHome
- execute
- executeAndReturnOutputFile
- executeOne
- extractInfo
- getBuiltInImage
- getBuiltInImages
- getConfigureFolders
- getFileName
- getFileNameExtension
- getInputFilesFromHtmlInputElement
- getPixelColor
- isExecuteCommand
- isImage
- isInputFile
- isOutputFile
- loadImageElement
- newExecutionContext
- readFileAsText
Ƭ Command: ( string
| number
)[]
Defined in execute.ts:7
Ƭ ExecuteCommand: * Command[] | Command | string
*
Defined in execute.ts:49
Commands could have the following syntaxes:
- array form like
[['convert', 'foo.png', 'bar.gif'], ['identify', 'bar.gif']]
- just one array:
['convert', 'foo.png', 'bar.gif']
- command line strings:
['convert foo.png bar.gif', 'idenfity bar.gif']
- just one string:
'convert foo.png bar.gif'
Also, for command line strings, multiple commands can be specified in the same string separating with new lines:
const result = await execute(`
convert rose: -sharpen 0x1 reconstruct.jpg
compare rose: reconstruct.jpg difference.png
compare -compose src rose: reconstruct.jpg difference.png
`)
Also, command line strings support breaking the same command in multiple lines by using \
like in:
const result = await execute(`
convert -size 250x100 xc: +noise Random -channel R -threshold .4% \\
-negate -channel RG -separate +channel \\
\( +clone \) -compose multiply -flatten \\
-virtual-pixel Tile -background Black \\
-blur 0x.6 -motion-blur 0x15-90 -normalize \\
+distort Polar 0 +repage 'star inward.gif'
`)
If you need to escape arguments like file names with spaces, use single quotes '
, like the output file in the previous example 'star inward.gif'
● builtInImageNames: string
[] = ['rose:', 'logo:', 'wizard:', 'granite:', 'netscape:']
Defined in util/imageBuiltIn.ts:5
● knownSupportedReadWriteImageFormats: string
[] = [
'jpg', 'png',
'psd',
'tiff', 'xcf', 'gif', 'bmp', 'tga', 'miff', 'ico', 'dcm', 'xpm', 'pcx',
// 'pix', // gives error
'fits',
// 'djvu', // read only support
'ppm',
'pgm',
'pfm',
'mng',
'hdr',
'dds', // generated using convert -define "dds:compression={dxt1, dxt5, none}" to_rotate.png to_rotate.dds
'otb', // generated using convert to_rotate.png to_rotate.otb
'txt', // generated using convert to_rotate.png to_rotate.txt
// 'rgb', // fails because MustSpecifyImageSize `to_rotate.rgb' ]
Defined in util/support.ts:22
list of image formats that are known to be supported by wasm-imagemagick. See spec/formatSpec.ts
▸ Call(inputFiles: MagickInputFile[], command: string
[]): Promise
<MagickOutputFile[]>
Defined in magickApi.ts:27
call shortcut that only returns the output files.
Parameters:
Name | Type |
---|---|
inputFiles | MagickInputFile[] |
command | string [] |
Returns: Promise
<MagickOutputFile[]>
▸ addExecuteListener(l: ExecuteListener): void
Defined in execute.ts:128
Parameters:
Name | Type |
---|---|
l | ExecuteListener |
Returns: void
▸ arrayToCli(command: * Command | Command[]*): string
Defined in util/cli.ts:36
Generates a valid command line string from given string[]
that is compatible with call. Works with multiple commands by separating them with new lines and support comand splitting in new lines using \
. See ExecuteCommand for more information.
Parameters:
Name | Type |
---|---|
command | Command | Command[] |
Returns: string
▸ asCommand(c: ExecuteCommand): Command[]
Defined in util/cli.ts:99
Makes sure that given ExecuteCommand, in whatever syntax, is transformed to the form string[][]
that is compatible with call
Parameters:
Name | Type |
---|---|
c | ExecuteCommand |
Returns: Command[]
▸ asExecuteConfig(arg: * ExecuteConfig | ExecuteCommand*): ExecuteConfig
Defined in execute.ts:91
Transform configOrCommand: ExecuteConfig | ExecuteCommand
to a valid ExecuteConfig object
Parameters:
Name | Type |
---|---|
arg | ExecuteConfig | ExecuteCommand |
Returns: ExecuteConfig
▸ asInputFile(f: MagickFile, name?: string
): Promise
<MagickInputFile>
Defined in util/file.ts:82
Parameters:
Name | Type | Default value |
---|---|---|
f | MagickFile | - |
Default value name |
string |
f.name |
Returns: Promise
<MagickInputFile>
▸ asOutputFile(f: MagickFile, name?: string
): Promise
<MagickOutputFile>
Defined in util/file.ts:94
Parameters:
Name | Type | Default value |
---|---|---|
f | MagickFile | - |
Default value name |
string |
f.name |
Returns: Promise
<MagickOutputFile>
▸ blobToString(blb: Blob
): Promise
<string
>
Defined in util/file.ts:15
Parameters:
Name | Type |
---|---|
blb | Blob |
Returns: Promise
<string
>
▸ buildImageSrc(image: MagickFile, forceBrowserSupport?: boolean
): Promise
<string
>
Defined in util/html.ts:21
Return a string with the inline image content, suitable to be used to assign to an html img src attribute. See loadImageElement.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
image | MagickFile | - | |
Default value forceBrowserSupport |
boolean |
false | if true and the image extension is not supported by browsers, it will convert the image to png and return that src so it can be shown in browsers |
Returns: Promise
<string
>
▸ buildInputFile(url: string
, name?: string
): Promise
<MagickInputFile>
Defined in util/file.ts:57
Builds a new MagickInputFile by fetching the content of given url and optionally naming the file using given name or extracting the file name from the url otherwise.
Parameters:
Name | Type | Default value |
---|---|---|
url | string |
- |
Default value name |
string |
getFileName(url) |
Returns: Promise
<MagickInputFile>
▸ call(inputFiles: MagickInputFile[], command: string
[]): Promise
<CallResult>
Defined in magickApi.ts:58
Low level execution function. All the other functions like execute ends up calling this one. It accept only one command and only in the form of array of strings.
Parameters:
Name | Type |
---|---|
inputFiles | MagickInputFile[] |
command | string [] |
Returns: Promise
<CallResult>
▸ cliToArray(cliCommand: string
): Command[]
Defined in util/cli.ts:76
Generates a command in the form of string[][]
that is compatible with call from given command line string. This works for strings containing multiple commands in different lines. and also respect \
character for continue the same command in a new line. See ExecuteCommand for more information.
Parameters:
Name | Type |
---|---|
cliCommand | string |
Returns: Command[]
▸ compare(img1: * MagickFile | string
, img2: * MagickFile | string
, fuzz?: number
): Promise
<boolean
>
Defined in util/imageCompare.ts:6
Compare the two images and return true if they are equal visually. Optionally, a margin of error can be provided using fuzz
Parameters:
Name | Type | Default value |
---|---|---|
img1 | MagickFile | string |
- |
img2 | MagickFile | string |
- |
Default value fuzz |
number |
0.015 |
Returns: Promise
<boolean
>
▸ compareNumber(img1: * MagickFile | string
, img2: * MagickFile | string
): Promise
<number
>
Defined in util/imageCompare.ts:11
Parameters:
Name | Type |
---|---|
img1 | MagickFile | string |
img2 | MagickFile | string |
Returns: Promise
<number
>
▸ createImageHome(): ImageHomeImpl
Defined in imageHome.ts:81
Returns: ImageHomeImpl
▸ execute(configOrCommand: * ExecuteConfig | ExecuteCommand*): Promise
<ExecuteResult>
Defined in execute.ts:162
Execute all commands in given config serially in order. Output files from a command become available as input files in next commands. In the following example we execute two commands. Notice how the second one uses image2.png
which was the output file of the first one:
const { outputFiles, exitCode, stderr} = await execute({
inputFiles: [await buildInputFile('fn.png', 'image1.png')],
commands: `
convert image1.png -bordercolor #ffee44 -background #eeff55 +polaroid image2.png
convert image2.png -fill #997711 -tint 55 image3.jpg
`
})
if (exitCode) {
alert(`There was an error with the command: ${stderr.join('\n')}`)
}
else {
await loadImageElement(outputFiles.find(f => f.name==='image3.jpg'), document.getElementById('outputImage'))
}
See ExecuteCommand for different command syntax supported.
See ExecuteResult for details on the object returned
Parameters:
Name | Type |
---|---|
configOrCommand | ExecuteConfig | ExecuteCommand |
Returns: Promise
<ExecuteResult>
▸ executeAndReturnOutputFile(configOrCommand: * ExecuteConfig | ExecuteCommand*, outputFileName?: string
): Promise
< MagickOutputFile | undefined
>
Defined in execute.ts:107
execute()
shortcut that useful for commands that return only one output file or when only one particular output file is relevant.
Parameters:
Name | Type | Description |
---|---|---|
configOrCommand | ExecuteConfig | ExecuteCommand | |
Optional outputFileName |
string |
optionally user can give the desired output file name |
Returns: Promise
< MagickOutputFile | undefined
>
If outputFileName
is given the file with that name, the first output file otherwise or undefined
if no file match, or no output files where generated (like in an error).
▸ executeOne(configOrCommand: * ExecuteConfig | ExecuteCommand*): Promise
<ExecuteResultOne>
Defined in execute.ts:59
Execute first command in given config.
Parameters:
Name | Type |
---|---|
configOrCommand | ExecuteConfig | ExecuteCommand |
Returns: Promise
<ExecuteResultOne>
▸ extractInfo(img: * MagickFile | string
*): Promise
<ExtractInfoResult
[]>
Defined in util/imageExtractInfo.ts:8
Execute convert $IMG info.json
to extract image metadata. Returns the parsed info.json file contents
Parameters:
Name | Type | Description |
---|---|---|
img | MagickFile | string |
could be a string in case you want to extract information about built in images like `rose:` |
Returns: Promise
<ExtractInfoResult
[]>
▸ getBuiltInImage(name: string
): Promise
<MagickInputFile>
Defined in util/imageBuiltIn.ts:25
shortcut of getBuiltInImages to get a single image by name
Parameters:
Name | Type |
---|---|
name | string |
Returns: Promise
<MagickInputFile>
▸ getBuiltInImages(): Promise
<MagickInputFile[]>
Defined in util/imageBuiltIn.ts:10
Gets ImageMagick built-in images like rose:
, logo:
, etc in the form of MagickInputFiles
Returns: Promise
<MagickInputFile[]>
▸ getConfigureFolders(): Promise
<string
[]>
Defined in util/support.ts:3
Returns: Promise
<string
[]>
▸ getFileName(url: string
): string
Defined in util/file.ts:106
Parameters:
Name | Type |
---|---|
url | string |
Returns: string
▸ getFileNameExtension(filePathOrUrl: string
): string
Defined in util/file.ts:118
Parameters:
Name | Type |
---|---|
filePathOrUrl | string |
Returns: string
▸ getInputFilesFromHtmlInputElement(el: HTMLInputElement
): Promise
<MagickInputFile[]>
Defined in util/html.ts:35
Build MagickInputFile[]
from given HTMLInputElement of type=file that user may used to select several files
Parameters:
Name | Type |
---|---|
el | HTMLInputElement |
Returns: Promise
<MagickInputFile[]>
▸ getPixelColor(img: MagickFile, x: number
, y: number
): Promise
<string
>
Defined in util/image.ts:4
Parameters:
Name | Type |
---|---|
img | MagickFile |
x | number |
y | number |
Returns: Promise
<string
>
▸ isExecuteCommand(arg: any
): boolean
Defined in execute.ts:84
Parameters:
Name | Type |
---|---|
arg | any |
Returns: boolean
▸ isImage(file: MagickFile): Promise
<boolean
>
Defined in util/file.ts:49
Parameters:
Name | Type |
---|---|
file | MagickFile |
Returns: Promise
<boolean
>
▸ isInputFile(file: MagickFile): boolean
Defined in util/file.ts:26
Parameters:
Name | Type |
---|---|
file | MagickFile |
Returns: boolean
▸ isOutputFile(file: MagickFile): boolean
Defined in util/file.ts:29
Parameters:
Name | Type |
---|---|
file | MagickFile |
Returns: boolean
▸ loadImageElement(image: MagickFile, el: HTMLImageElement
, forceBrowserSupport?: boolean
): Promise
<void
>
Defined in util/html.ts:12
Will load given html img element src with the inline image content.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
image | MagickFile | - | the image to be loaded |
el | HTMLImageElement |
- | the html image element in which to load the image |
Default value forceBrowserSupport |
boolean |
false | if true and the image extension is not supported by browsers, it will convert the image to png and return that src so it can be shown in browsers |
Returns: Promise
<void
>
▸ newExecutionContext(inheritFrom?: ExecutionContext): ExecutionContext
Defined in executionContext.ts:88
Parameters:
Name | Type |
---|---|
Optional inheritFrom |
ExecutionContext |
Returns: ExecutionContext
▸ readFileAsText(file: MagickFile): Promise
<string
>
Defined in util/file.ts:40
Read files as string. Useful when files contains plain text like in the output file info.txt of convert logo: -format '%[pixel:p{0,0}]' info:info.txt
Parameters:
Name | Type |
---|---|
file | MagickFile |
Returns: Promise
<string
>