The name of the image, or null if not set.
The size of the image. Setting this resizes the image in place to the exact dimensions.
Whether the image is a template image.
Template images are tinted by the system to match the appearance context (e.g. menu bar icons).
Create a cropped copy of the image
The crop area is measured from the top left corner of the image, like the frames of screens and windows, so a screen snapshot can be cropped to a window's frame (after subtracting the screen's origin).
HSRect defining the crop area (x, y, w, h), with y measured down from the top of the image
A new cropped HSImage, or null if the rect falls outside the image bounds
Save the image to a file. The file is written atomically, so anything reading it sees either the previous contents or the complete new image, never a partial write.
Destination file path (extension determines format: png, jpg, tiff, bmp, gif)
true if saved successfully, false otherwise
Replace this image's content.
If this image is bound to a UI element, the canvas re-renders automatically.
A file path string (~ is expanded) or another HSImage object
Encode the image and return it as a base64 data: URL, without writing anything to disk.
This is useful for handing an image to anything that accepts data URLs, such as web views or JSON messages sent to other programs.
Optionaltype: string | null
The image format, case-insensitive: "png" (the default), "jpeg"/"jpg", "tiff"/"tif", "bmp" or "gif"
A string such as "data:image/png;base64,iVBOR...", or null if the format is unknown or the image couldn't be encoded
Encode the image and return its bytes as a Uint8Array, without writing anything to disk.
The bytes are the same as saveToFile() would write for that format, so they can be sent over
a socket, used as an HTTP body, stored in a database, and so on.
Optionaltype: string | null
The image format, case-insensitive: "png" (the default), "jpeg"/"jpg", "tiff"/"tif", "bmp" or "gif"
The encoded image bytes, or null if the format is unknown or the image couldn't be encoded
StaticfromLoad an app's icon by bundle identifier
Bundle identifier of the application
OptionalwithFallbackSymbol: string
The name of an SF Symbol to use if no bundle image could be loaded. Defaults to questionmark.circle
An HSImage object, or null if the app couldn't be found
StaticfromLoad a system image by name
Name of the system image (e.g., "NSComputer", "NSFolder")
An HSImage object, or null if the image couldn't be found
StaticfromLoad an image from a file path
Path to the image file
An HSImage object, or null if the file couldn't be loaded
StaticfromLoad a system symbol by name
Name of the symbol (e.g., "hammer", "questionmark.circle")
An HSImage object, or null if the symbol couldn't be found
StaticfromDecode an image from encoded bytes in memory, without going through the disk.
This is the counterpart to toUint8Array(), accepting a Uint8Array, any other typed
array, or an ArrayBuffer holding PNG, JPEG, TIFF, GIF, BMP, HEIC, or any other format
supported by NSImage.
The encoded image bytes
An HSImage object, or null if the input isn't a typed array/ArrayBuffer or couldn't be decoded as an image
StaticfromLoad an image from a URL (asynchronous)
URL string of the image
A Promise that resolves to the loaded image, or rejects on error
StaticiconGet the icon for a file
Path to the file
An HSImage object representing the file's icon
StaticiconGet the icon for a file type
File extension or UTI (e.g., "png", "public.png")
An HSImage object representing the file type's icon
Bridge type for working with images in JavaScript
HSImage provides a comprehensive API for loading, manipulating, and saving images. It supports various image sources including files, system icons, app bundles, and URLs.
Loading Images
Image Manipulation