Skip to content

ElectronNativeImage

Unofficial

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

Import:

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

Signature:

export interface ElectronNativeImage

Properties

Property Type Description
isMacTemplateImage boolean A boolean property that determines whether the image is considered a template image. Only has an effect on macOS.

Methods

Method Returns Description
addRepresentation(options) void Adds 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) ElectronNativeImage Returns a cropped copy of the image.
getAspectRatio(scaleFactor?) number Returns 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?) Buffer Returns 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() Buffer Returns 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?) ElectronNativeImageSize Returns 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() boolean Returns whether the image is empty.
isTemplateImage() boolean Returns whether the image is a template image.
resize(options) ElectronNativeImage Returns 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) void Marks the image as a template image.
toBitmap(options?) Buffer Returns a buffer that contains a copy of the image's raw bitmap pixel data.
toDataURL(options?) string Returns the data URL of the image.
toJPEG(quality) Buffer Returns a buffer that contains the image's JPEG encoded data.
toPNG(options?) Buffer Returns a buffer that contains the image's PNG encoded data.

Links to this page: