Image
Inherits:Resource<RefCounted<Object
Image datatype.
Description
Native image datatype. Contains image data which can be converted to anImageTexture and provides commonly usedimage processing methods. The maximum width and height for anImage areMAX_WIDTH andMAX_HEIGHT.
AnImage cannot be assigned to a texture property of an object directly (such asSprite2D.texture), and has to be converted manually to anImageTexture first.
Note: The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
Tutorials
Properties
|
Methods
Enumerations
enumFormat:🔗
FormatFORMAT_L8 =0
Texture format with a single 8-bit depth representing luminance.
FormatFORMAT_LA8 =1
OpenGL texture format with two values, luminance and alpha each stored with 8 bits.
FormatFORMAT_R8 =2
OpenGL texture formatRED with a single component and a bitdepth of 8.
FormatFORMAT_RG8 =3
OpenGL texture formatRG with two components and a bitdepth of 8 for each.
FormatFORMAT_RGB8 =4
OpenGL texture formatRGB with three components, each with a bitdepth of 8.
Note: When creating anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_RGBA8 =5
OpenGL texture formatRGBA with four components, each with a bitdepth of 8.
Note: When creating anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_RGBA4444 =6
OpenGL texture formatRGBA with four components, each with a bitdepth of 4.
FormatFORMAT_RGB565 =7
OpenGL texture formatRGB with three components. Red and blue have a bitdepth of 5, and green has a bitdepth of 6.
FormatFORMAT_RF =8
OpenGL texture formatGL_R32F where there's one component, a 32-bit floating-point value.
FormatFORMAT_RGF =9
OpenGL texture formatGL_RG32F where there are two components, each a 32-bit floating-point values.
FormatFORMAT_RGBF =10
OpenGL texture formatGL_RGB32F where there are three components, each a 32-bit floating-point values.
FormatFORMAT_RGBAF =11
OpenGL texture formatGL_RGBA32F where there are four components, each a 32-bit floating-point values.
FormatFORMAT_RH =12
OpenGL texture formatGL_R16F where there's one component, a 16-bit "half-precision" floating-point value.
FormatFORMAT_RGH =13
OpenGL texture formatGL_RG16F where there are two components, each a 16-bit "half-precision" floating-point value.
FormatFORMAT_RGBH =14
OpenGL texture formatGL_RGB16F where there are three components, each a 16-bit "half-precision" floating-point value.
FormatFORMAT_RGBAH =15
OpenGL texture formatGL_RGBA16F where there are four components, each a 16-bit "half-precision" floating-point value.
FormatFORMAT_RGBE9995 =16
A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent.
FormatFORMAT_DXT1 =17
TheS3TC 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 anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_DXT3 =18
TheS3TC 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 anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_DXT5 =19
TheS3TC 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 anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_RGTC_R =20
Texture format that usesRed Green Texture Compression, normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel.
FormatFORMAT_RGTC_RG =21
Texture format that usesRed Green Texture Compression, normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel.
FormatFORMAT_BPTC_RGBA =22
Texture format that usesBPTC compression with unsigned normalized RGBA components.
Note: When creating anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_BPTC_RGBF =23
Texture format that usesBPTC compression with signed floating-point RGB components.
FormatFORMAT_BPTC_RGBFU =24
Texture format that usesBPTC compression with unsigned floating-point RGB components.
FormatFORMAT_ETC =25
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.
FormatFORMAT_ETC2_R11 =26
Ericsson Texture Compression format 2 (R11_EAC variant), which provides one channel of unsigned data.
FormatFORMAT_ETC2_R11S =27
Ericsson Texture Compression format 2 (SIGNED_R11_EAC variant), which provides one channel of signed data.
FormatFORMAT_ETC2_RG11 =28
Ericsson Texture Compression format 2 (RG11_EAC variant), which provides two channels of unsigned data.
FormatFORMAT_ETC2_RG11S =29
Ericsson Texture Compression format 2 (SIGNED_RG11_EAC variant), which provides two channels of signed data.
FormatFORMAT_ETC2_RGB8 =30
Ericsson Texture Compression format 2 (RGB8 variant), which is a follow-up of ETC1 and compresses RGB888 data.
Note: When creating anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_ETC2_RGBA8 =31
Ericsson Texture Compression format 2 (RGBA8variant), which compresses RGBA8888 data with full alpha support.
Note: When creating anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_ETC2_RGB8A1 =32
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 anImageTexture, an sRGB to linear color space conversion is performed.
FormatFORMAT_ETC2_RA_AS_RG =33
Ericsson Texture Compression format 2 (RGBA8 variant), which compresses RA data and interprets it as two channels (red and green). See alsoFORMAT_ETC2_RGBA8.
FormatFORMAT_DXT5_RA_AS_RG =34
TheS3TC texture format also known as Block Compression 3 or BC3, which compresses RA data and interprets it as two channels (red and green). See alsoFORMAT_DXT5.
FormatFORMAT_ASTC_4x4 =35
Adaptive Scalable Texture Compression. This implements the 4×4 (high quality) mode.
FormatFORMAT_ASTC_4x4_HDR =36
Same format asFORMAT_ASTC_4x4, but with the hint to let the GPU know it is used for HDR.
FormatFORMAT_ASTC_8x8 =37
Adaptive Scalable Texture Compression. This implements the 8×8 (low quality) mode.
FormatFORMAT_ASTC_8x8_HDR =38
Same format asFORMAT_ASTC_8x8, but with the hint to let the GPU know it is used for HDR.
FormatFORMAT_MAX =39
Represents the size of theFormat enum.
enumInterpolation:🔗
InterpolationINTERPOLATE_NEAREST =0
Performs nearest-neighbor interpolation. If the image is resized, it will be pixelated.
InterpolationINTERPOLATE_BILINEAR =1
Performs bilinear interpolation. If the image is resized, it will be blurry. This mode is faster thanINTERPOLATE_CUBIC, but it results in lower quality.
InterpolationINTERPOLATE_CUBIC =2
Performs cubic interpolation. If the image is resized, it will be blurry. This mode often gives better results compared toINTERPOLATE_BILINEAR, at the cost of being slower.
InterpolationINTERPOLATE_TRILINEAR =3
Performs bilinear separately on the two most-suited mipmap levels, then linearly interpolates between them.
It's slower thanINTERPOLATE_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 callgenerate_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.
InterpolationINTERPOLATE_LANCZOS =4
Performs Lanczos interpolation. This is the slowest image resizing mode, but it typically gives the best results, especially when downscaling images.
enumAlphaMode:🔗
AlphaModeALPHA_NONE =0
Image does not have alpha.
AlphaModeALPHA_BIT =1
Image stores alpha in a single bit.
AlphaModeALPHA_BLEND =2
Image uses alpha.
enumCompressMode:🔗
CompressModeCOMPRESS_S3TC =0
Use S3TC compression.
CompressModeCOMPRESS_ETC =1
Use ETC compression.
CompressModeCOMPRESS_ETC2 =2
Use ETC2 compression.
CompressModeCOMPRESS_BPTC =3
Use BPTC compression.
CompressModeCOMPRESS_ASTC =4
Use ASTC compression.
CompressModeCOMPRESS_MAX =5
Represents the size of theCompressMode enum.
enumUsedChannels:🔗
UsedChannelsUSED_CHANNELS_L =0
The image only uses one channel for luminance (grayscale).
UsedChannelsUSED_CHANNELS_LA =1
The image uses two channels for luminance and alpha, respectively.
UsedChannelsUSED_CHANNELS_R =2
The image only uses the red channel.
UsedChannelsUSED_CHANNELS_RG =3
The image uses two channels for red and green.
UsedChannelsUSED_CHANNELS_RGB =4
The image uses three channels for red, green, and blue.
UsedChannelsUSED_CHANNELS_RGBA =5
The image uses four channels for red, green, blue, and alpha.
enumCompressSource:🔗
CompressSourceCOMPRESS_SOURCE_GENERIC =0
Source texture (before compression) is a regular texture. Default for all textures.
CompressSourceCOMPRESS_SOURCE_SRGB =1
Source texture (before compression) is in sRGB space.
CompressSourceCOMPRESS_SOURCE_NORMAL =2
Source texture (before compression) is a normal texture (e.g. it can be compressed into two channels).
enumASTCFormat:🔗
ASTCFormatASTC_FORMAT_4x4 =0
Hint to indicate that the high quality 4×4 ASTC compression format should be used.
ASTCFormatASTC_FORMAT_8x8 =1
Hint to indicate that the low quality 8×8 ASTC compression format should be used.
Constants
MAX_WIDTH =16777216🔗
The maximal width allowed forImage resources.
MAX_HEIGHT =16777216🔗
The maximal height allowed forImage resources.
Property Descriptions
Dictionarydata ={"data":PackedByteArray(),"format":"Lum8","height":0,"mipmaps":false,"width":0}🔗
Holds all the image's color data in a given format. SeeFormat constants.
Method Descriptions
voidadjust_bcs(brightness:float, contrast:float, saturation:float)🔗
Adjusts this image'sbrightness,contrast, andsaturation by the given values. Does not work if the image is compressed (seeis_compressed()).
voidblend_rect(src:Image, src_rect:Rect2i, dst:Vector2i)🔗
Alpha-blendssrc_rect fromsrc image to this image at coordinatesdst, clipped accordingly to both image bounds. This image andsrc imagemust have the same format.src_rect with non-positive size is treated as empty.
voidblend_rect_mask(src:Image, mask:Image, src_rect:Rect2i, dst:Vector2i)🔗
Alpha-blendssrc_rect fromsrc image to this image usingmask image at coordinatesdst, clipped accordingly to both image bounds. Alpha channels are required for bothsrc andmask.dst pixels andsrc pixels will blend if the corresponding mask pixel's alpha value is not 0. This image andsrc imagemust have the same format.src image andmask imagemust have the same size (width and height) but they can have different formats.src_rect with non-positive size is treated as empty.
voidblit_rect(src:Image, src_rect:Rect2i, dst:Vector2i)🔗
Copiessrc_rect fromsrc image to this image at coordinatesdst, clipped accordingly to both image bounds. This image andsrc imagemust have the same format.src_rect with non-positive size is treated as empty.
Note: The alpha channel data insrc will overwrite the corresponding data in this image at the target position. To blend alpha channels, useblend_rect() instead.
voidblit_rect_mask(src:Image, mask:Image, src_rect:Rect2i, dst:Vector2i)🔗
Blitssrc_rect area fromsrc image to this image at the coordinates given bydst, clipped accordingly to both image bounds.src pixel is copied ontodst if the correspondingmask pixel's alpha value is not 0. This image andsrc imagemust have the same format.src image andmask imagemust have the same size (width and height) but they can have different formats.src_rect with non-positive size is treated as empty.
voidbump_map_to_normal_map(bump_scale:float = 1.0)🔗
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.
Removes the image's mipmaps.
Errorcompress(mode:CompressMode, source:CompressSource = 0, astc_format:ASTCFormat = 0)🔗
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.
Thesource parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
For ASTC compression, theastc_format parameter must be supplied.
Errorcompress_from_channels(mode:CompressMode, channels:UsedChannels, astc_format:ASTCFormat = 0)🔗
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 tocompress() 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, theastc_format parameter must be supplied.
Dictionarycompute_image_metrics(compared_image:Image, use_luma:bool)🔗
Compute image metrics on the current image and the compared image.
The dictionary containsmax,mean,mean_squared,root_mean_squared andpeak_snr.
Converts this image's format to the givenformat.
Copiessrc image to this image.
Imagecreate(width:int, height:int, use_mipmaps:bool, format:Format)static🔗
Deprecated: Usecreate_empty().
Creates an empty image of the given size and format. Ifuse_mipmaps istrue, generates mipmaps for this image. See thegenerate_mipmaps().
Imagecreate_empty(width:int, height:int, use_mipmaps:bool, format:Format)static🔗
Creates an empty image of the given size and format. Ifuse_mipmaps istrue, generates mipmaps for this image. See thegenerate_mipmaps().
Imagecreate_from_data(width:int, height:int, use_mipmaps:bool, format:Format, data:PackedByteArray)static🔗
Creates a new image of the given size and format. Fills the image with the given raw data. Ifuse_mipmaps istrue, loads the mipmaps for this image fromdata. Seegenerate_mipmaps().
voidcrop(width:int, height:int)🔗
Crops the image to the givenwidth andheight. If the specified size is larger than the current size, the extra area is filled with black pixels.
Decompresses the image if it is VRAM compressed in a supported format. Returns@GlobalScope.OK if the format is supported, otherwise@GlobalScope.ERR_UNAVAILABLE.
Note: The following formats can be decompressed: DXT, RGTC, BPTC. The formats ETC1 and ETC2 are not supported.
ReturnsALPHA_BLEND if the image has data for alpha values. ReturnsALPHA_BIT if all the alpha values are stored in a single bit. ReturnsALPHA_NONE if no data for alpha values is found.
UsedChannelsdetect_used_channels(source:CompressSource = 0)const🔗
Returns the color channels used by this image. If the image is compressed, the originalsource must be specified.
Fills the image withcolor.
voidfill_rect(rect:Rect2i, color:Color)🔗
Fillsrect withcolor.
Blends low-alpha pixels with nearby pixels.
Flips the image horizontally.
Flips the image vertically.
Errorgenerate_mipmaps(renormalize:bool = false)🔗
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 is0. Enablingrenormalize 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 callinghas_mipmaps() orget_mipmap_count(). Callinggenerate_mipmaps() on an image that already has mipmaps will replace existing mipmaps in the image.
PackedByteArrayget_data()const🔗
Returns a copy of the image's raw data.
Returns size (in bytes) of the image's raw data.
Returns this image's format.
Returns the image's height.
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.
intget_mipmap_offset(mipmap:int)const🔗
Returns the offset where the image's mipmap with indexmipmap is stored in thedata dictionary.
Colorget_pixel(x:int, y:int)const🔗
Returns the color of the pixel at(x,y).
This is the same asget_pixelv(), but with two integer arguments instead of aVector2i argument.
Colorget_pixelv(point:Vector2i)const🔗
Returns the color of the pixel atpoint.
This is the same asget_pixel(), but with aVector2i argument instead of two integer arguments.
Imageget_region(region:Rect2i)const🔗
Returns a newImage that is a copy of thisImage's area specified withregion.
Returns the image's size (width and height).
Returns aRect2i enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
Returns the image's width.
Returnstrue if the image has generated mipmaps.
Returnstrue if the image is compressed.
Returnstrue if the image has no data.
Returnstrue if all the image's pixels have an alpha value of 0. Returnsfalse if any pixel has an alpha value higher than 0.
Converts the entire image from the linear colorspace to the sRGB colorspace. Only works on images withFORMAT_RGB8 orFORMAT_RGBA8 formats.
Loads an image from filepath. SeeSupported 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 theuser:// directory, and may not work in exported projects.
See alsoImageTexture description for usage examples.
Errorload_bmp_from_buffer(buffer:PackedByteArray)🔗
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 themodule_bmp_enabled=no SCons option.
Errorload_dds_from_buffer(buffer:PackedByteArray)🔗
Loads an image from the binary contents of a DDS file.
Note: This method is only available in engine builds with the DDS module enabled. By default, the DDS module is enabled, but it can be disabled at build-time using themodule_dds_enabled=no SCons option.
Imageload_from_file(path:String)static🔗
Creates a newImage and loads data from the specified file.
Errorload_jpg_from_buffer(buffer:PackedByteArray)🔗
Loads an image from the binary contents of a JPEG file.
Errorload_ktx_from_buffer(buffer:PackedByteArray)🔗
Loads an image from the binary contents of aKTX 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 themodule_ktx_enabled=no SCons option.
Errorload_png_from_buffer(buffer:PackedByteArray)🔗
Loads an image from the binary contents of a PNG file.
Errorload_svg_from_buffer(buffer:PackedByteArray, scale:float = 1.0)🔗
Loads an image from the UTF-8 binary contents of anuncompressed SVG file (.svg).
Note: Beware when using compressed SVG files (like.svgz), they need to bedecompressed 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 themodule_svg_enabled=no SCons option.
Errorload_svg_from_string(svg_str:String, scale:float = 1.0)🔗
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 themodule_svg_enabled=no SCons option.
Errorload_tga_from_buffer(buffer:PackedByteArray)🔗
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 themodule_tga_enabled=no SCons option.
Errorload_webp_from_buffer(buffer:PackedByteArray)🔗
Loads an image from the binary contents of a WebP file.
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.
Multiplies color values with alpha values. Resulting color values for a pixel are(color*alpha)/256. See alsoCanvasItemMaterial.blend_mode.
voidresize(width:int, height:int, interpolation:Interpolation = 1)🔗
Resizes the image to the givenwidth andheight. New pixels are calculated using theinterpolation mode defined viaInterpolation constants.
voidresize_to_po2(square:bool = false, interpolation:Interpolation = 1)🔗
Resizes the image to the nearest power of 2 for the width and height. Ifsquare istrue, sets width and height to be the same. New pixels are calculated using theinterpolation mode defined viaInterpolation constants.
Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
voidrotate_90(direction:ClockDirection)🔗
Rotates the image in the specifieddirection by90 degrees. The width and height of the image must be greater than1. If the width and height are not equal, the image will be resized.
Rotates the image by180 degrees. The width and height of the image must be greater than1.
Errorsave_dds(path:String)const🔗
Saves the image as a DDS (DirectDraw Surface) file topath. DDS is a container format that can store textures in various compression formats, such as DXT1, DXT5, or BC7. This function will return@GlobalScope.ERR_UNAVAILABLE if Godot was compiled without the DDS module.
Note: The DDS module may be disabled in certain builds, which meanssave_dds() will return@GlobalScope.ERR_UNAVAILABLE when it is called from an exported project.
PackedByteArraysave_dds_to_buffer()const🔗
Saves the image as a DDS (DirectDraw Surface) file to a byte array. DDS is a container format that can store textures in various compression formats, such as DXT1, DXT5, or BC7. This function will return an empty byte array if Godot was compiled without the DDS module.
Note: The DDS module may be disabled in certain builds, which meanssave_dds_to_buffer() will return an empty byte array when it is called from an exported project.
Errorsave_exr(path:String, grayscale:bool = false)const🔗
Saves the image as an EXR file topath. Ifgrayscale istrue and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return@GlobalScope.ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
Note: The TinyEXR module is disabled in non-editor builds, which meanssave_exr() will return@GlobalScope.ERR_UNAVAILABLE when it is called from an exported project.
PackedByteArraysave_exr_to_buffer(grayscale:bool = false)const🔗
Saves the image as an EXR file to a byte array. Ifgrayscale istrue 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 meanssave_exr_to_buffer() will return an empty byte array when it is called from an exported project.
Errorsave_jpg(path:String, quality:float = 0.75)const🔗
Saves the image as a JPEG file topath with the specifiedquality between0.01 and1.0 (inclusive). Higherquality values result in better-looking output at the cost of larger file sizes. Recommendedquality values are between0.75 and0.90. Even at quality1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If theImage contains an alpha channel, the image will still be saved, but the resulting JPEG file won't contain the alpha channel.
PackedByteArraysave_jpg_to_buffer(quality:float = 0.75)const🔗
Saves the image as a JPEG file to a byte array with the specifiedquality between0.01 and1.0 (inclusive). Higherquality values result in better-looking output at the cost of larger byte array sizes (and therefore memory usage). Recommendedquality values are between0.75 and0.90. Even at quality1.00, JPEG compression remains lossy.
Note: JPEG does not save an alpha channel. If theImage contains an alpha channel, the image will still be saved, but the resulting byte array won't contain the alpha channel.
Errorsave_png(path:String)const🔗
Saves the image as a PNG file to the file atpath.
PackedByteArraysave_png_to_buffer()const🔗
Saves the image as a PNG file to a byte array.
Errorsave_webp(path:String, lossy:bool = false, quality:float = 0.75)const🔗
Saves the image as a WebP (Web Picture) file to the file atpath. By default it will save lossless. Iflossy istrue, the image will be saved lossy, using thequality setting between0.0 and1.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.
PackedByteArraysave_webp_to_buffer(lossy:bool = false, quality:float = 0.75)const🔗
Saves the image as a WebP (Web Picture) file to a byte array. By default it will save lossless. Iflossy istrue, the image will be saved lossy, using thequality setting between0.0 and1.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.
voidset_data(width:int, height:int, use_mipmaps:bool, format:Format, data:PackedByteArray)🔗
Overwrites data of an existingImage. Non-static equivalent ofcreate_from_data().
voidset_pixel(x:int, y:int, color:Color)🔗
Sets theColor of the pixel at(x,y) tocolor.
varimg_width=10varimg_height=5varimg=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.
intimgWidth=10;intimgHeight=5;varimg=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 asset_pixelv(), but with a two integer arguments instead of aVector2i argument.
voidset_pixelv(point:Vector2i, color:Color)🔗
Sets theColor of the pixel atpoint tocolor.
varimg_width=10varimg_height=5varimg=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.
intimgWidth=10;intimgHeight=5;varimg=Image.Create(imgWidth,imgHeight,false,Image.Format.Rgba8);img.SetPixelv(newVector2I(1,2),Colors.Red);// Sets the color at (1, 2) to red.
This is the same asset_pixel(), but with aVector2i argument instead of two integer arguments.
Shrinks the image by a factor of 2 on each axis (this divides the pixel count by 4).
Converts the raw data from the sRGB colorspace to a linear scale. Only works on images withFORMAT_RGB8 orFORMAT_RGBA8 formats.