Skip to content

ElectronNativeImage

Unofficial

Electron NativeImage for handling tray, dock, and application images.

Import:

import type { ElectronNativeImage } from '@obsidian-typings/obsidian-catalyst-latest';

Signature:

export interface ElectronNativeImage

Properties

PropertyTypeDescription
isMacTemplateImagebooleanA boolean property that determines whether the image is considered a template image. Only has an effect on macOS.

Methods

MethodReturnsDescription
addRepresentation(options)voidAdds an image representation for a specific scale factor. This can be used to explicitly add different scale factor representations to an image. This can be called on empty images.
crop(rect)ElectronNativeImageReturns a cropped copy of the image.
getAspectRatio(scaleFactor?)numberReturns the image's aspect ratio. If scaleFactor is passed, this returns the aspect ratio corresponding to the image representation most closely matching the passed value.
getBitmap(options?)BufferReturns a buffer that contains the image's raw bitmap pixel data. The difference between getBitmap() and toBitmap() is that getBitmap() does not copy the bitmap data, so the returned buffer must be used immediately in the current event loop tick; otherwise the data might be changed or destroyed.
getNativeHandle()BufferReturns a buffer that stores the C pointer to the underlying native handle of the image. On macOS, a pointer to an NSImage instance is returned. The returned pointer is a weak pointer to the underlying native image, so the associated nativeImage instance must be kept around. Only available on macOS.
getScaleFactors()number[]Returns an array of all scale factors corresponding to representations for a given native image.
getSize(scaleFactor?)ElectronNativeImageSizeReturns the size of the image. If scaleFactor is passed, this returns the size corresponding to the image representation most closely matching the passed value.
isEmpty()booleanReturns whether the image is empty.
isTemplateImage()booleanReturns whether the image is a template image.
resize(options)ElectronNativeImageReturns a resized copy of the image. If only the height or the width is specified then the current aspect ratio is preserved in the resized image.
setTemplateImage(option)voidMarks the image as a template image.
toBitmap(options?)BufferReturns a buffer that contains a copy of the image's raw bitmap pixel data.
toDataURL(options?)stringReturns the data URL of the image.
toJPEG(quality)BufferReturns a buffer that contains the image's JPEG encoded data.
toPNG(options?)BufferReturns a buffer that contains the image's PNG encoded data.

Links to this page: