Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
- Animation
- AnimationLibrary
- AnimationNode (6)
- AnimationNodeStateMachinePlayback
- AnimationNodeStateMachineTransition
- AudioBusLayout
- AudioEffect (17)
- AudioStream (10)
- BitMap
- BoneMap
- ButtonGroup
- CameraAttributes (2)
- ColorPalette
- Compositor
- CompositorEffect
- CryptoKey
- Curve
- Curve2D
- Curve3D
- EditorNode3DGizmoPlugin
- EditorSettings
- Environment
- Font (3)
- GDExtension
- GLTFAccessor
- GLTFAnimation
- GLTFBufferView
- GLTFCamera
- GLTFDocument (1)
- GLTFDocumentExtension (1)
- GLTFLight
- GLTFMesh
- GLTFNode
- GLTFPhysicsBody
- GLTFPhysicsShape
- GLTFSkeleton
- GLTFSkin
- GLTFSpecGloss
- GLTFState (1)
- GLTFTexture
- GLTFTextureSampler
- Gradient
- Image
- ImporterMesh
- InputEvent (6)
- JSON
- LabelSettings
- LightmapGIData
- Material (9)
- Mesh (4)
- MeshLibrary
- MissingResource
- MultiMesh
- NavigationMesh
- NavigationMeshSourceGeometryData2D
- NavigationMeshSourceGeometryData3D
- NavigationPolygon
- Noise (1)
- Occluder3D (5)
- OccluderPolygon2D
- OggPacketSequence
- OpenXRAction
- OpenXRActionMap
- OpenXRActionSet
- OpenXRBindingModifier (2)
- OpenXRHapticBase (1)
- OpenXRIPBinding
- OpenXRInteractionProfile
- PackedDataContainer
- PackedScene
- PhysicsMaterial
- PolygonPathFinder
- RDShaderFile
- RDShaderSPIRV
- RichTextEffect
- SceneReplicationConfig
- Script (3)
- Shader (1)
- ShaderInclude
- Shape2D (8)
- Shape3D (9)
- Shortcut
- SkeletonModification2D (7)
- SkeletonModificationStack2D
- SkeletonProfile (1)
- Skin
- Sky
- SpriteFrames
- StyleBox (4)
- SyntaxHighlighter (2)
- Texture (3)
- Theme
- TileMapPattern
- TileSet
- TileSetSource (2)
- Translation (1)
- VideoStream (1)
- VideoStreamPlayback
- VisualShaderNode (62)
- VoxelGIData
- World2D
- World3D
- X509Certificate
Table of contents
-
var data: Dictionary = { "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 } -
func adjust_bcs(saturation: float) -> void -
func blend_rect(dst: Vector2i) -> void -
func blend_rect_mask(dst: Vector2i) -> void -
func blit_rect(dst: Vector2i) -> void -
func blit_rect_mask(dst: Vector2i) -> void -
func bump_map_to_normal_map(bump_scale: float = 1.0) -> void -
func clear_mipmaps() -> void -
func compress(astc_format: int = 0 enumImage.ASTCFormat) -> intError -
func compress_from_channels(astc_format: int = 0 enumImage.ASTCFormat) -> intError -
func compute_image_metrics(use_luma: bool) -> Dictionary -
func convert(format: int enumImage.Format) -> void -
func copy_from(src: Image) -> void -
static func create(format: int enumImage.Format) -> Image -
static func create_empty(format: int enumImage.Format) -> Image -
static func create_from_data(data: PackedByteArray) -> Image -
func crop(height: int) -> void -
func decompress() -> intError -
const func detect_alpha() -> intImage.AlphaMode -
const func detect_used_channels(source: int = 0 enumImage.CompressSource) -> intImage.UsedChannels -
func fill(color: Color) -> void -
func fill_rect(color: Color) -> void -
func fix_alpha_edges() -> void -
func flip_x() -> void -
func flip_y() -> void -
func generate_mipmaps(renormalize: bool = false) -> intError -
const func get_data() -> PackedByteArray -
const func get_data_size() -> int -
const func get_format() -> intImage.Format -
const func get_height() -> int -
const func get_mipmap_count() -> int -
const func get_mipmap_offset(mipmap: int) -> int -
const func get_pixel(y: int) -> Color -
const func get_pixelv(point: Vector2i) -> Color -
const func get_region(region: Rect2i) -> Image -
const func get_size() -> Vector2i -
const func get_used_rect() -> Rect2i -
const func get_width() -> int -
const func has_mipmaps() -> bool -
const func is_compressed() -> bool -
const func is_empty() -> bool -
const func is_invisible() -> bool -
func linear_to_srgb() -> void -
func load(path: String) -> intError -
func load_bmp_from_buffer(buffer: PackedByteArray) -> intError -
static func load_from_file(path: String) -> Image -
func load_jpg_from_buffer(buffer: PackedByteArray) -> intError -
func load_ktx_from_buffer(buffer: PackedByteArray) -> intError -
func load_png_from_buffer(buffer: PackedByteArray) -> intError -
func load_svg_from_buffer(scale: float = 1.0) -> intError -
func load_svg_from_string(scale: float = 1.0) -> intError -
func load_tga_from_buffer(buffer: PackedByteArray) -> intError -
func load_webp_from_buffer(buffer: PackedByteArray) -> intError -
func normal_map_to_xy() -> void -
func premultiply_alpha() -> void -
func resize(interpolation: int = 1 enumImage.Interpolation) -> void -
func resize_to_po2(interpolation: int = 1 enumImage.Interpolation) -> void -
func rgbe_to_srgb() -> Image -
func rotate_90(direction: int enumClockDirection) -> void -
func rotate_180() -> void -
const func save_exr(grayscale: bool = false) -> intError -
const func save_exr_to_buffer(grayscale: bool = false) -> PackedByteArray -
const func save_jpg(quality: float = 0.75) -> intError -
const func save_jpg_to_buffer(quality: float = 0.75) -> PackedByteArray -
const func save_png(path: String) -> intError -
const func save_png_to_buffer() -> PackedByteArray -
const func save_webp(quality: float = 0.75) -> intError -
const func save_webp_to_buffer(quality: float = 0.75) -> PackedByteArray -
func set_data(data: PackedByteArray) -> void -
func set_pixel(color: Color) -> void -
func set_pixelv(color: Color) -> void -
func shrink_x2() -> void -
func srgb_to_linear() -> void -
const MAX_WIDTH = 16777216 -
const MAX_HEIGHT = 16777216 -
const FORMAT_L8 = 0 enum Format -
const FORMAT_LA8 = 1 enum Format -
const FORMAT_R8 = 2 enum Format -
const FORMAT_RG8 = 3 enum Format -
const FORMAT_RGB8 = 4 enum Format -
const FORMAT_RGBA8 = 5 enum Format -
const FORMAT_RGBA4444 = 6 enum Format -
const FORMAT_RGB565 = 7 enum Format -
const FORMAT_RF = 8 enum Format -
const FORMAT_RGF = 9 enum Format -
const FORMAT_RGBF = 10 enum Format -
const FORMAT_RGBAF = 11 enum Format -
const FORMAT_RH = 12 enum Format -
const FORMAT_RGH = 13 enum Format -
const FORMAT_RGBH = 14 enum Format -
const FORMAT_RGBAH = 15 enum Format -
const FORMAT_RGBE9995 = 16 enum Format -
const FORMAT_DXT1 = 17 enum Format -
const FORMAT_DXT3 = 18 enum Format -
const FORMAT_DXT5 = 19 enum Format -
const FORMAT_RGTC_R = 20 enum Format -
const FORMAT_RGTC_RG = 21 enum Format -
const FORMAT_BPTC_RGBA = 22 enum Format -
const FORMAT_BPTC_RGBF = 23 enum Format -
const FORMAT_BPTC_RGBFU = 24 enum Format -
const FORMAT_ETC = 25 enum Format -
const FORMAT_ETC2_R11 = 26 enum Format -
const FORMAT_ETC2_R11S = 27 enum Format -
const FORMAT_ETC2_RG11 = 28 enum Format -
const FORMAT_ETC2_RG11S = 29 enum Format -
const FORMAT_ETC2_RGB8 = 30 enum Format -
const FORMAT_ETC2_RGBA8 = 31 enum Format -
const FORMAT_ETC2_RGB8A1 = 32 enum Format -
const FORMAT_ETC2_RA_AS_RG = 33 enum Format -
const FORMAT_DXT5_RA_AS_RG = 34 enum Format -
const FORMAT_ASTC_4x4 = 35 enum Format -
const FORMAT_ASTC_4x4_HDR = 36 enum Format -
const FORMAT_ASTC_8x8 = 37 enum Format -
const FORMAT_ASTC_8x8_HDR = 38 enum Format -
const FORMAT_MAX = 39 enum Format -
const INTERPOLATE_NEAREST = 0 enum Interpolation -
const INTERPOLATE_BILINEAR = 1 enum Interpolation -
const INTERPOLATE_CUBIC = 2 enum Interpolation -
const INTERPOLATE_TRILINEAR = 3 enum Interpolation -
const INTERPOLATE_LANCZOS = 4 enum Interpolation -
const ALPHA_NONE = 0 enum AlphaMode -
const ALPHA_BIT = 1 enum AlphaMode -
const ALPHA_BLEND = 2 enum AlphaMode -
const COMPRESS_S3TC = 0 enum CompressMode -
const COMPRESS_ETC = 1 enum CompressMode -
const COMPRESS_ETC2 = 2 enum CompressMode -
const COMPRESS_BPTC = 3 enum CompressMode -
const COMPRESS_ASTC = 4 enum CompressMode -
const COMPRESS_MAX = 5 enum CompressMode -
const USED_CHANNELS_L = 0 enum UsedChannels -
const USED_CHANNELS_LA = 1 enum UsedChannels -
const USED_CHANNELS_R = 2 enum UsedChannels -
const USED_CHANNELS_RG = 3 enum UsedChannels -
const USED_CHANNELS_RGB = 4 enum UsedChannels -
const USED_CHANNELS_RGBA = 5 enum UsedChannels -
const COMPRESS_SOURCE_GENERIC = 0 enum CompressSource -
const COMPRESS_SOURCE_SRGB = 1 enum CompressSource -
const COMPRESS_SOURCE_NORMAL = 2 enum CompressSource -
const ASTC_FORMAT_4x4 = 0 enum ASTCFormat -
const ASTC_FORMAT_8x8 = 1 enum ASTCFormat -
enum Format -
enum Interpolation -
enum AlphaMode -
enum CompressMode -
enum UsedChannels -
enum CompressSource -
enum ASTCFormat
Image #
is_refcounted, is_instantiable, resource, core, not_builtin_classes
Image datatype.
Native image datatype. Contains image data which can be converted to an ImageTexture and provides commonly used image processing methods. The maximum width and height for an Image are MAX_WIDTH and MAX_HEIGHT.
An Image cannot be assigned to a texture property of an object directly (such as Sprite2D.texture), and has to be converted manually to an ImageTexture first.
Note: The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
Members #
var data: Dictionary = { "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 }#
Holds all the image's color data in a given format. See Format constants.
Methods #
func adjust_bcs(saturation: float) -> void#
Adjusts this image's brightness, contrast, and saturation by the given values. Does not work if the image is compressed (see is_compressed).
func blend_rect(dst: Vector2i) -> void#
Alpha-blends src_rect from src image to this image at coordinates dst, clipped accordingly to both image bounds. This image and src image must have the same format. src_rect with non-positive size is treated as empty.
func blend_rect_mask(dst: Vector2i) -> void#
Alpha-blends src_rect from src image to this image using mask image at coordinates dst, clipped accordingly to both image bounds. Alpha channels are required for both src and mask. dst pixels and src pixels will blend if the corresponding mask pixel's alpha value is not 0. This image and src image must have the same format. src image and mask image must have the same size (width and height) but they can have different formats. src_rect with non-positive size is treated as empty.
func blit_rect(dst: Vector2i) -> void#
Copies src_rect from src image to this image at coordinates dst, clipped accordingly to both image bounds. This image and src image must have the same format. src_rect with non-positive size is treated as empty.
Note: The alpha channel data in src will overwrite the corresponding data in this image at the target position. To blend alpha channels, use blend_rect instead.
func blit_rect_mask(dst: Vector2i) -> void#
Blits src_rect area from src image to this image at the coordinates given by dst, clipped accordingly to both image bounds. src pixel is copied onto dst if the corresponding mask pixel's alpha value is not 0. This image and src image must have the same format. src image and mask image must have the same size (width and height) but they can have different formats. src_rect with non-positive size is treated as empty.
func bump_map_to_normal_map(bump_scale: float = 1.0) -> void#
Converts a bump map to a normal map. A bump map provides a height offset per-pixel, while a normal map provides a normal direction per pixel.
func clear_mipmaps() -> void#
Removes the image's mipmaps.
func compress(astc_format: int = 0 enumImage.ASTCFormat) -> intError#
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
The source parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
For ASTC compression, the astc_format parameter must be supplied.
func compress_from_channels(astc_format: int = 0 enumImage.ASTCFormat) -> intError#
Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available.
This is an alternative to compress that lets the user supply the channels used in order for the compressor to pick the best DXT and ETC2 formats. For other formats (non DXT or ETC2), this argument is ignored.
For ASTC compression, the astc_format parameter must be supplied.
func compute_image_metrics(use_luma: bool) -> Dictionary#
Compute image metrics on the current image and the compared image.
The dictionary contains max, mean, mean_squared, root_mean_squared and peak_snr.
func convert(format: int enumImage.Format) -> void#
Converts the image's format. See Format constants.
func copy_from(src: Image) -> void#
Copies src image to this image.
static func create(format: int enumImage.Format) -> Image#
Creates an empty image of given size and format. See Format constants. If use_mipmaps is true, then generate mipmaps for this image. See the generate_mipmaps.
static func create_empty(format: int enumImage.Format) -> Image#
Creates an empty image of given size and format. See Format constants. If use_mipmaps is true, then generate mipmaps for this image. See the generate_mipmaps.
static func create_from_data(data: PackedByteArray) -> Image#
Creates a new image of given size and format. See Format constants. Fills the image with the given raw data. If use_mipmaps is true then loads mipmaps for this image from data. See generate_mipmaps.
func crop(height: int) -> void#
Crops the image to the given width and height. If the specified size is larger than the current size, the extra area is filled with black pixels.
func decompress() -> intError#
Decompresses the image if it is VRAM compressed in a supported format. Returns OK if the format is supported, otherwise ERR_UNAVAILABLE.
Note: The following formats can be decompressed: DXT, RGTC, BPTC. The formats ETC1 and ETC2 are not supported.
const func detect_alpha() -> intImage.AlphaMode#
Returns ALPHA_BLEND if the image has data for alpha values. Returns ALPHA_BIT if all the alpha values are stored in a single bit. Returns ALPHA_NONE if no data for alpha values is found.
const func detect_used_channels(source: int = 0 enumImage.CompressSource) -> intImage.UsedChannels#
Returns the color channels used by this image, as one of the UsedChannels constants. If the image is compressed, the original source must be specified.
func fill(color: Color) -> void#
Fills the image with color.
func fill_rect(color: Color) -> void#
Fills rect with color.
func fix_alpha_edges() -> void#
Blends low-alpha pixels with nearby pixels.
func flip_x() -> void#
Flips the image horizontally.
func flip_y() -> void#
Flips the image vertically.
func generate_mipmaps(renormalize: bool = false) -> intError#
Generates mipmaps for the image. Mipmaps are precalculated lower-resolution copies of the image that are automatically used if the image needs to be scaled down when rendered. They help improve image quality and performance when rendering. This method returns an error if the image is compressed, in a custom format, or if the image's width/height is 0. Enabling renormalize when generating mipmaps for normal map textures will make sure all resulting vector values are normalized.
It is possible to check if the image has mipmaps by calling has_mipmaps or get_mipmap_count. Calling generate_mipmaps on an image that already has mipmaps will replace existing mipmaps in the image.
const func get_data() -> PackedByteArray#
Returns a copy of the image's raw data.
const func get_data_size() -> int#
Returns size (in bytes) of the image's raw data.
const func get_height() -> int#
Returns the image's height.
const func get_mipmap_count() -> int#
Returns the number of mipmap levels or 0 if the image has no mipmaps. The largest main level image is not counted as a mipmap level by this method, so if you want to include it you can add 1 to this count.
const func get_mipmap_offset(mipmap: int) -> int#
Returns the offset where the image's mipmap with index mipmap is stored in the data dictionary.
const func get_pixel(y: int) -> Color#
Returns the color of the pixel at (x, y).
This is the same as get_pixelv, but with two integer arguments instead of a Vector2i argument.
const func get_pixelv(point: Vector2i) -> Color#
Returns the color of the pixel at point.
This is the same as get_pixel, but with a Vector2i argument instead of two integer arguments.
const func get_region(region: Rect2i) -> Image#
Returns a new Image that is a copy of this Image's area specified with region.
const func get_size() -> Vector2i#
Returns the image's size (width and height).
const func get_used_rect() -> Rect2i#
Returns a Rect2i enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
const func get_width() -> int#
Returns the image's width.
const func has_mipmaps() -> bool#
Returns true if the image has generated mipmaps.
const func is_compressed() -> bool#
Returns true if the image is compressed.
const func is_empty() -> bool#
Returns true if the image has no data.
const func is_invisible() -> bool#
Returns true if all the image's pixels have an alpha value of 0. Returns false if any pixel has an alpha value higher than 0.
func linear_to_srgb() -> void#
Converts the entire image from the linear colorspace to the sRGB colorspace. Only works on images with FORMAT_RGB8 or FORMAT_RGBA8 formats.
func load(path: String) -> intError#
Loads an image from file path. See Supported image formats for a list of supported image formats and limitations.
Warning: This method should only be used in the editor or in cases when you need to load external images at run-time, such as images located at the user:// directory, and may not work in exported projects.
See also ImageTexture description for usage examples.
func load_bmp_from_buffer(buffer: PackedByteArray) -> intError#
Loads an image from the binary contents of a BMP file.
Note: Godot's BMP module doesn't support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
Note: This method is only available in engine builds with the BMP module enabled. By default, the BMP module is enabled, but it can be disabled at build-time using the module_bmp_enabled=no SCons option.
static func load_from_file(path: String) -> Image#
Creates a new Image and loads data from the specified file.
func load_jpg_from_buffer(buffer: PackedByteArray) -> intError#
Loads an image from the binary contents of a JPEG file.
func load_ktx_from_buffer(buffer: PackedByteArray) -> intError#
Loads an image from the binary contents of a KTX file. Unlike most image formats, KTX can store VRAM-compressed data and embed mipmaps.
Note: Godot's libktx implementation only supports 2D images. Cubemaps, texture arrays, and de-padding are not supported.
Note: This method is only available in engine builds with the KTX module enabled. By default, the KTX module is enabled, but it can be disabled at build-time using the module_ktx_enabled=no SCons option.
func load_png_from_buffer(buffer: PackedByteArray) -> intError#
Loads an image from the binary contents of a PNG file.
func load_svg_from_buffer(scale: float = 1.0) -> intError#
Loads an image from the UTF-8 binary contents of an uncompressed SVG file (.svg).
Note: Beware when using compressed SVG files (like .svgz), they need to be decompressed before loading.
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
func load_svg_from_string(scale: float = 1.0) -> intError#
Loads an image from the string contents of an SVG file (.svg).
Note: This method is only available in engine builds with the SVG module enabled. By default, the SVG module is enabled, but it can be disabled at build-time using the module_svg_enabled=no SCons option.
func load_tga_from_buffer(buffer: PackedByteArray) -> intError#
Loads an image from the binary contents of a TGA file.
Note: This method is only available in engine builds with the TGA module enabled. By default, the TGA module is enabled, but it can be disabled at build-time using the module_tga_enabled=no SCons option.
func load_webp_from_buffer(buffer: PackedByteArray) -> intError#
Loads an image from the binary contents of a WebP file.
func normal_map_to_xy() -> void#
Converts the image's data to represent coordinates on a 3D plane. This is used when the image represents a normal map. A normal map can add lots of detail to a 3D surface without increasing the polygon count.
func premultiply_alpha() -> void#
Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256. See also CanvasItemMaterial.blend_mode.
func resize(interpolation: int = 1 enumImage.Interpolation) -> void#
Resizes the image to the given width and height. New pixels are calculated using the interpolation mode defined via Interpolation constants.
func resize_to_po2(interpolation: int = 1 enumImage.Interpolation) -> void#
Resizes the image to the nearest power of 2 for the width and height. If square is true then set width and height to be the same. New pixels are calculated using the interpolation mode defined via Interpolation constants.
func rgbe_to_srgb() -> Image#
Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
func rotate_90(direction: int enumClockDirection) -> void#
Rotates the image in the specified direction by 90 degrees. The width and height of the image must be greater than 1. If the width and height are not equal, the image will be resized.
func rotate_180() -> void#
Rotates the image by 180 degrees. The width and height of the image must be greater than 1.
const func save_exr(grayscale: bool = false) -> intError#
Saves the image as an EXR file to path. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which means save_exr will return ERR_UNAVAILABLE when it is called from an exported project.
const func save_exr_to_buffer(grayscale: bool = false) -> PackedByteArray#
Saves the image as an EXR file to a byte array. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which means save_exr will return an empty byte array when it is called from an exported project.
const func save_jpg(quality: float = 0.75) -> intError#
Saves the image as a JPEG file to path with the specified quality between 0.01 and 1.0 (inclusive). Higher quality values result in better-looking output at the cost of larger file sizes. Recommended quality values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the Image contains an alpha channel, the image will still be saved, but the resulting JPEG file won't contain the alpha channel.
const func save_jpg_to_buffer(quality: float = 0.75) -> PackedByteArray#
Saves the image as a JPEG file to a byte array with the specified quality between 0.01 and 1.0 (inclusive). Higher quality values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommended quality values are between 0.75 and 0.90. Even at quality 1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If the Image contains an alpha channel, the image will still be saved, but the resulting byte array won't contain the alpha channel.
const func save_png(path: String) -> intError#
Saves the image as a PNG file to the file at path.
const func save_png_to_buffer() -> PackedByteArray#
Saves the image as a PNG file to a byte array.
const func save_webp(quality: float = 0.75) -> intError#
Saves the image as a WebP (Web Picture) file to the file at path. By default it will save lossless. If lossy is true, the image will be saved lossy, using the quality setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
const func save_webp_to_buffer(quality: float = 0.75) -> PackedByteArray#
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. If lossy is true, the image will be saved lossy, using the quality setting between 0.0 and 1.0 (inclusive). Lossless WebP offers more efficient compression than PNG.
Note: The WebP format is limited to a size of 16383×16383 pixels, while PNG can save larger images.
func set_data(data: PackedByteArray) -> void#
Overwrites data of an existing Image. Non-static equivalent of create_from_data.
func set_pixel(color: Color) -> void#
Sets the Color of the pixel at (x, y) to color.
GDScript
var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.set_pixel(1, 2, Color.RED) # Sets the color at (1, 2) to red.C#
int imgWidth = 10;
int imgHeight = 5;
var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
img.SetPixel(1, 2, Colors.Red); // Sets the color at (1, 2) to red.This is the same as set_pixelv, but with a two integer arguments instead of a Vector2i argument.
func set_pixelv(color: Color) -> void#
Sets the Color of the pixel at point to color.
GDScript
var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.set_pixelv(Vector2i(1, 2), Color.RED) # Sets the color at (1, 2) to red.C#
int imgWidth = 10;
int imgHeight = 5;
var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
img.SetPixelv(new Vector2I(1, 2), Colors.Red); // Sets the color at (1, 2) to red.This is the same as set_pixel, but with a Vector2i argument instead of two integer arguments.
func shrink_x2() -> void#
Shrinks the image by a factor of 2 on each axis (this divides the pixel count by 4).
func srgb_to_linear() -> void#
Converts the raw data from the sRGB colorspace to a linear scale. Only works on images with FORMAT_RGB8 or FORMAT_RGBA8 formats.
Annotations #
Constants #
const MAX_WIDTH = 16777216#
The maximal width allowed for Image resources.
const MAX_HEIGHT = 16777216#
The maximal height allowed for Image resources.
const FORMAT_L8 = 0 enum Format#
Texture format with a single 8-bit depth representing luminance.
const FORMAT_LA8 = 1 enum Format#
OpenGL texture format with two values, luminance and alpha each stored with 8 bits.
const FORMAT_R8 = 2 enum Format#
OpenGL texture format RED with a single component and a bitdepth of 8.
const FORMAT_RG8 = 3 enum Format#
OpenGL texture format RG with two components and a bitdepth of 8 for each.
const FORMAT_RGB8 = 4 enum Format#
OpenGL texture format RGB with three components, each with a bitdepth of 8.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_RGBA8 = 5 enum Format#
OpenGL texture format RGBA with four components, each with a bitdepth of 8.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_RGBA4444 = 6 enum Format#
OpenGL texture format RGBA with four components, each with a bitdepth of 4.
const FORMAT_RGB565 = 7 enum Format#
OpenGL texture format RGB with three components. Red and blue have a bitdepth of 5, and green has a bitdepth of 6.
const FORMAT_RF = 8 enum Format#
OpenGL texture format GL_R32F where there's one component, a 32-bit floating-point value.
const FORMAT_RGF = 9 enum Format#
OpenGL texture format GL_RG32F where there are two components, each a 32-bit floating-point values.
const FORMAT_RGBF = 10 enum Format#
OpenGL texture format GL_RGB32F where there are three components, each a 32-bit floating-point values.
const FORMAT_RGBAF = 11 enum Format#
OpenGL texture format GL_RGBA32F where there are four components, each a 32-bit floating-point values.
const FORMAT_RH = 12 enum Format#
OpenGL texture format GL_R16F where there's one component, a 16-bit "half-precision" floating-point value.
const FORMAT_RGH = 13 enum Format#
OpenGL texture format GL_RG16F where there are two components, each a 16-bit "half-precision" floating-point value.
const FORMAT_RGBH = 14 enum Format#
OpenGL texture format GL_RGB16F where there are three components, each a 16-bit "half-precision" floating-point value.
const FORMAT_RGBAH = 15 enum Format#
OpenGL texture format GL_RGBA16F where there are four components, each a 16-bit "half-precision" floating-point value.
const FORMAT_RGBE9995 = 16 enum Format#
A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent.
const FORMAT_DXT1 = 17 enum Format#
The S3TC texture format that uses Block Compression 1, and is the smallest variation of S3TC, only providing 1 bit of alpha and color data being premultiplied with alpha.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_DXT3 = 18 enum Format#
The S3TC texture format that uses Block Compression 2, and color data is interpreted as not having been premultiplied by alpha. Well suited for images with sharp alpha transitions between translucent and opaque areas.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_DXT5 = 19 enum Format#
The S3TC texture format also known as Block Compression 3 or BC3 that contains 64 bits of alpha channel data followed by 64 bits of DXT1-encoded color data. Color data is not premultiplied by alpha, same as DXT3. DXT5 generally produces superior results for transparent gradients compared to DXT3.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_RGTC_R = 20 enum Format#
Texture format that uses Red Green Texture Compression, normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel.
const FORMAT_RGTC_RG = 21 enum Format#
Texture format that uses Red Green Texture Compression, normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel.
const FORMAT_BPTC_RGBA = 22 enum Format#
Texture format that uses BPTC compression with unsigned normalized RGBA components.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_BPTC_RGBF = 23 enum Format#
Texture format that uses BPTC compression with signed floating-point RGB components.
const FORMAT_BPTC_RGBFU = 24 enum Format#
Texture format that uses BPTC compression with unsigned floating-point RGB components.
const FORMAT_ETC = 25 enum Format#
Ericsson Texture Compression format 1, also referred to as "ETC1", and is part of the OpenGL ES graphics standard. This format cannot store an alpha channel.
const FORMAT_ETC2_R11 = 26 enum Format#
Ericsson Texture Compression format 2 (R11_EAC variant), which provides one channel of unsigned data.
const FORMAT_ETC2_R11S = 27 enum Format#
Ericsson Texture Compression format 2 (SIGNED_R11_EAC variant), which provides one channel of signed data.
const FORMAT_ETC2_RG11 = 28 enum Format#
Ericsson Texture Compression format 2 (RG11_EAC variant), which provides two channels of unsigned data.
const FORMAT_ETC2_RG11S = 29 enum Format#
Ericsson Texture Compression format 2 (SIGNED_RG11_EAC variant), which provides two channels of signed data.
const FORMAT_ETC2_RGB8 = 30 enum Format#
Ericsson Texture Compression format 2 (RGB8 variant), which is a follow-up of ETC1 and compresses RGB888 data.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_ETC2_RGBA8 = 31 enum Format#
Ericsson Texture Compression format 2 (RGBA8variant), which compresses RGBA8888 data with full alpha support.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_ETC2_RGB8A1 = 32 enum Format#
Ericsson Texture Compression format 2 (RGB8_PUNCHTHROUGH_ALPHA1 variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
const FORMAT_ETC2_RA_AS_RG = 33 enum Format#
Ericsson Texture Compression format 2 (RGBA8 variant), which compresses RA data and interprets it as two channels (red and green). See also FORMAT_ETC2_RGBA8.
const FORMAT_DXT5_RA_AS_RG = 34 enum Format#
The S3TC texture format also known as Block Compression 3 or BC3, which compresses RA data and interprets it as two channels (red and green). See also FORMAT_DXT5.
const FORMAT_ASTC_4x4 = 35 enum Format#
Adaptive Scalable Texture Compression. This implements the 4×4 (high quality) mode.
const FORMAT_ASTC_4x4_HDR = 36 enum Format#
Same format as FORMAT_ASTC_4x4, but with the hint to let the GPU know it is used for HDR.
const FORMAT_ASTC_8x8 = 37 enum Format#
Adaptive Scalable Texture Compression. This implements the 8×8 (low quality) mode.
const FORMAT_ASTC_8x8_HDR = 38 enum Format#
Same format as FORMAT_ASTC_8x8, but with the hint to let the GPU know it is used for HDR.
const FORMAT_MAX = 39 enum Format#
Represents the size of the Format enum.
const INTERPOLATE_NEAREST = 0 enum Interpolation#
Performs nearest-neighbor interpolation. If the image is resized, it will be pixelated.
const INTERPOLATE_BILINEAR = 1 enum Interpolation#
Performs bilinear interpolation. If the image is resized, it will be blurry. This mode is faster than INTERPOLATE_CUBIC, but it results in lower quality.
const INTERPOLATE_CUBIC = 2 enum Interpolation#
Performs cubic interpolation. If the image is resized, it will be blurry. This mode often gives better results compared to INTERPOLATE_BILINEAR, at the cost of being slower.
const INTERPOLATE_TRILINEAR = 3 enum Interpolation#
Performs bilinear separately on the two most-suited mipmap levels, then linearly interpolates between them.
It's slower than INTERPOLATE_BILINEAR, but produces higher-quality results with far fewer aliasing artifacts.
If the image does not have mipmaps, they will be generated and used internally, but no mipmaps will be generated on the resulting image.
Note: If you intend to scale multiple copies of the original image, it's better to call generate_mipmaps] on it in advance, to avoid wasting processing power in generating them again and again.
On the other hand, if the image already has mipmaps, they will be used, and a new set will be generated for the resulting image.
const INTERPOLATE_LANCZOS = 4 enum Interpolation#
Performs Lanczos interpolation. This is the slowest image resizing mode, but it typically gives the best results, especially when downscaling images.
const ALPHA_NONE = 0 enum AlphaMode#
Image does not have alpha.
const ALPHA_BIT = 1 enum AlphaMode#
Image stores alpha in a single bit.
const ALPHA_BLEND = 2 enum AlphaMode#
Image uses alpha.
const COMPRESS_S3TC = 0 enum CompressMode#
Use S3TC compression.
const COMPRESS_ETC = 1 enum CompressMode#
Use ETC compression.
const COMPRESS_ETC2 = 2 enum CompressMode#
Use ETC2 compression.
const COMPRESS_BPTC = 3 enum CompressMode#
Use BPTC compression.
const COMPRESS_ASTC = 4 enum CompressMode#
Use ASTC compression.
const COMPRESS_MAX = 5 enum CompressMode#
Represents the size of the CompressMode enum.
const USED_CHANNELS_L = 0 enum UsedChannels#
The image only uses one channel for luminance (grayscale).
const USED_CHANNELS_LA = 1 enum UsedChannels#
The image uses two channels for luminance and alpha, respectively.
const USED_CHANNELS_R = 2 enum UsedChannels#
The image only uses the red channel.
const USED_CHANNELS_RG = 3 enum UsedChannels#
The image uses two channels for red and green.
const USED_CHANNELS_RGB = 4 enum UsedChannels#
The image uses three channels for red, green, and blue.
const USED_CHANNELS_RGBA = 5 enum UsedChannels#
The image uses four channels for red, green, blue, and alpha.
const COMPRESS_SOURCE_GENERIC = 0 enum CompressSource#
Source texture (before compression) is a regular texture. Default for all textures.
const COMPRESS_SOURCE_SRGB = 1 enum CompressSource#
Source texture (before compression) is in sRGB space.
const COMPRESS_SOURCE_NORMAL = 2 enum CompressSource#
Source texture (before compression) is a normal texture (e.g. it can be compressed into two channels).
const ASTC_FORMAT_4x4 = 0 enum ASTCFormat#
Hint to indicate that the high quality 4×4 ASTC compression format should be used.
const ASTC_FORMAT_8x8 = 1 enum ASTCFormat#
Hint to indicate that the low quality 8×8 ASTC compression format should be used.
Constructors #
Enums #
Format#
enum Format {
FORMAT_L8 = 0,
FORMAT_LA8 = 1,
FORMAT_R8 = 2,
FORMAT_RG8 = 3,
FORMAT_RGB8 = 4,
FORMAT_RGBA8 = 5,
FORMAT_RGBA4444 = 6,
FORMAT_RGB565 = 7,
FORMAT_RF = 8,
FORMAT_RGF = 9,
FORMAT_RGBF = 10,
FORMAT_RGBAF = 11,
FORMAT_RH = 12,
FORMAT_RGH = 13,
FORMAT_RGBH = 14,
FORMAT_RGBAH = 15,
FORMAT_RGBE9995 = 16,
FORMAT_DXT1 = 17,
FORMAT_DXT3 = 18,
FORMAT_DXT5 = 19,
FORMAT_RGTC_R = 20,
FORMAT_RGTC_RG = 21,
FORMAT_BPTC_RGBA = 22,
FORMAT_BPTC_RGBF = 23,
FORMAT_BPTC_RGBFU = 24,
FORMAT_ETC = 25,
FORMAT_ETC2_R11 = 26,
FORMAT_ETC2_R11S = 27,
FORMAT_ETC2_RG11 = 28,
FORMAT_ETC2_RG11S = 29,
FORMAT_ETC2_RGB8 = 30,
FORMAT_ETC2_RGBA8 = 31,
FORMAT_ETC2_RGB8A1 = 32,
FORMAT_ETC2_RA_AS_RG = 33,
FORMAT_DXT5_RA_AS_RG = 34,
FORMAT_ASTC_4x4 = 35,
FORMAT_ASTC_4x4_HDR = 36,
FORMAT_ASTC_8x8 = 37,
FORMAT_ASTC_8x8_HDR = 38,
FORMAT_MAX = 39,
}Interpolation#
enum Interpolation {
INTERPOLATE_NEAREST = 0,
INTERPOLATE_BILINEAR = 1,
INTERPOLATE_CUBIC = 2,
INTERPOLATE_TRILINEAR = 3,
INTERPOLATE_LANCZOS = 4,
}AlphaMode#
enum AlphaMode {
ALPHA_NONE = 0,
ALPHA_BIT = 1,
ALPHA_BLEND = 2,
}CompressMode#
enum CompressMode {
COMPRESS_S3TC = 0,
COMPRESS_ETC = 1,
COMPRESS_ETC2 = 2,
COMPRESS_BPTC = 3,
COMPRESS_ASTC = 4,
COMPRESS_MAX = 5,
}UsedChannels#
enum UsedChannels {
USED_CHANNELS_L = 0,
USED_CHANNELS_LA = 1,
USED_CHANNELS_R = 2,
USED_CHANNELS_RG = 3,
USED_CHANNELS_RGB = 4,
USED_CHANNELS_RGBA = 5,
}CompressSource#
enum CompressSource {
COMPRESS_SOURCE_GENERIC = 0,
COMPRESS_SOURCE_SRGB = 1,
COMPRESS_SOURCE_NORMAL = 2,
}ASTCFormat#
enum ASTCFormat {
ASTC_FORMAT_4x4 = 0,
ASTC_FORMAT_8x8 = 1,
} Notifications#
enum {
MAX_WIDTH = 16777216,
MAX_HEIGHT = 16777216,
}