2023-09-17 15:08:55 +02:00
|
|
|
import { Rectangle } from "./types";
|
2023-09-17 12:40:50 +02:00
|
|
|
export interface Implementation {
|
|
|
|
nativeImage: any;
|
|
|
|
}
|
|
|
|
export interface CreateFromBufferOptions {
|
|
|
|
width?: number;
|
|
|
|
height?: number;
|
|
|
|
scaleFactor?: number;
|
|
|
|
}
|
|
|
|
export interface ResizeOptions {
|
|
|
|
width?: number;
|
|
|
|
height?: number;
|
|
|
|
quality?: 'good' | 'better' | 'best';
|
|
|
|
}
|
|
|
|
export type Handle = string;
|
|
|
|
/**
|
|
|
|
* Provides imaging functions to resize or process images. You create an image
|
|
|
|
* using one of the `createFrom` functions, then use the other functions to
|
|
|
|
* process the image.
|
|
|
|
*
|
|
|
|
* Images are associated with a handle which is what will be available to the
|
|
|
|
* plugin. Once you are done with an image, free it using the `free()` function.
|
|
|
|
*
|
|
|
|
* [View the
|
|
|
|
* example](https://github.com/laurent22/joplin/blob/dev/packages/app-cli/tests/support/plugins/imaging/src/index.ts)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export default class JoplinImaging {
|
|
|
|
private implementation_;
|
|
|
|
private images_;
|
|
|
|
constructor(implementation: Implementation);
|
|
|
|
private createImageHandle;
|
|
|
|
private imageByHandle;
|
|
|
|
private cacheImage;
|
2023-09-17 15:08:55 +02:00
|
|
|
/**
|
|
|
|
* Create an image from a buffer - however only use this for very small
|
|
|
|
* images. It requires transferring the full image data from the plugin to
|
|
|
|
* the app, which is extremely slow and will freeze the app. Instead, use
|
|
|
|
* `createFromPath` or `createFromResource`, which will manipulate the image
|
|
|
|
* data directly from the main process.
|
|
|
|
*/
|
2023-09-17 12:40:50 +02:00
|
|
|
createFromBuffer(buffer: any, options?: CreateFromBufferOptions): Promise<Handle>;
|
2023-09-17 15:08:55 +02:00
|
|
|
createFromPath(filePath: string): Promise<Handle>;
|
|
|
|
createFromResource(resourceId: string): Promise<Handle>;
|
|
|
|
getSize(handle: Handle): Promise<any>;
|
2023-09-17 12:40:50 +02:00
|
|
|
resize(handle: Handle, options?: ResizeOptions): Promise<string>;
|
2023-09-17 15:08:55 +02:00
|
|
|
crop(handle: Handle, rectange: Rectangle): Promise<string>;
|
|
|
|
/**
|
|
|
|
* Warnings: requires transferring the complete image from the app to the
|
|
|
|
* plugin which may freeze the app. Consider using one of the `toXxxFile()`
|
|
|
|
* or `toXxxResource()` methods instead.
|
|
|
|
*/
|
2023-09-17 12:40:50 +02:00
|
|
|
toDataUrl(handle: Handle): Promise<string>;
|
2023-09-17 15:08:55 +02:00
|
|
|
/**
|
|
|
|
* Warnings: requires transferring the complete image from the app to the
|
|
|
|
* plugin which may freeze the app. Consider using one of the `toXxxFile()`
|
|
|
|
* or `toXxxResource()` methods instead.
|
|
|
|
*/
|
2023-09-17 12:40:50 +02:00
|
|
|
toBase64(handle: Handle): Promise<string>;
|
2023-09-17 15:08:55 +02:00
|
|
|
toPngFile(handle: Handle, filePath: string): Promise<void>;
|
|
|
|
/**
|
|
|
|
* Quality is between 0 and 100
|
|
|
|
*/
|
|
|
|
toJpgFile(handle: Handle, filePath: string, quality?: number): Promise<void>;
|
|
|
|
private tempFilePath;
|
|
|
|
/**
|
|
|
|
* Creates a new Joplin resource from the image data. The image will be
|
|
|
|
* first converted to a JPEG.
|
|
|
|
*/
|
|
|
|
toJpgResource(handle: Handle, resourceProps: any, quality?: number): Promise<import("../../database/types").ResourceEntity>;
|
|
|
|
/**
|
|
|
|
* Creates a new Joplin resource from the image data. The image will be
|
|
|
|
* first converted to a PNG.
|
|
|
|
*/
|
|
|
|
toPngResource(handle: Handle, resourceProps: any): Promise<import("../../database/types").ResourceEntity>;
|
2023-09-17 12:40:50 +02:00
|
|
|
/**
|
|
|
|
* Image data is not automatically deleted by Joplin so make sure you call
|
|
|
|
* this method on the handle once you are done.
|
|
|
|
*/
|
|
|
|
free(handle: Handle): Promise<void>;
|
|
|
|
}
|