class_image.rst 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Image.xml.
  6. .. _class_Image:
  7. Image
  8. =====
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Image datatype.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Native image datatype. Contains image data which can be converted to an :ref:`ImageTexture<class_ImageTexture>` and provides commonly used *image processing* methods. The maximum width and height for an **Image** are :ref:`MAX_WIDTH<class_Image_constant_MAX_WIDTH>` and :ref:`MAX_HEIGHT<class_Image_constant_MAX_HEIGHT>`.
  15. An **Image** cannot be assigned to a ``texture`` property of an object directly (such as :ref:`Sprite2D<class_Sprite2D>`), and has to be converted manually to an :ref:`ImageTexture<class_ImageTexture>` first.
  16. \ **Note:** The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Importing images <../tutorials/assets_pipeline/importing_images>`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +-------------------------------------+----------------------------------------+------------------------------------------------------------------------------------------------+
  27. | :ref:`Dictionary<class_Dictionary>` | :ref:`data<class_Image_property_data>` | ``{ "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 }`` |
  28. +-------------------------------------+----------------------------------------+------------------------------------------------------------------------------------------------+
  29. .. rst-class:: classref-reftable-group
  30. Methods
  31. -------
  32. .. table::
  33. :widths: auto
  34. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`adjust_bcs<class_Image_method_adjust_bcs>` **(** :ref:`float<class_float>` brightness, :ref:`float<class_float>` contrast, :ref:`float<class_float>` saturation **)** |
  36. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`blend_rect<class_Image_method_blend_rect>` **(** :ref:`Image<class_Image>` src, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)** |
  38. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`blend_rect_mask<class_Image_method_blend_rect_mask>` **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)** |
  40. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`blit_rect<class_Image_method_blit_rect>` **(** :ref:`Image<class_Image>` src, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)** |
  42. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`blit_rect_mask<class_Image_method_blit_rect_mask>` **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)** |
  44. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`bump_map_to_normal_map<class_Image_method_bump_map_to_normal_map>` **(** :ref:`float<class_float>` bump_scale=1.0 **)** |
  46. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`clear_mipmaps<class_Image_method_clear_mipmaps>` **(** **)** |
  48. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`compress<class_Image_method_compress>` **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`CompressSource<enum_Image_CompressSource>` source=0, :ref:`ASTCFormat<enum_Image_ASTCFormat>` astc_format=0 **)** |
  50. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`compress_from_channels<class_Image_method_compress_from_channels>` **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`UsedChannels<enum_Image_UsedChannels>` channels, :ref:`ASTCFormat<enum_Image_ASTCFormat>` astc_format=0 **)** |
  52. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Dictionary<class_Dictionary>` | :ref:`compute_image_metrics<class_Image_method_compute_image_metrics>` **(** :ref:`Image<class_Image>` compared_image, :ref:`bool<class_bool>` use_luma **)** |
  54. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`convert<class_Image_method_convert>` **(** :ref:`Format<enum_Image_Format>` format **)** |
  56. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`copy_from<class_Image_method_copy_from>` **(** :ref:`Image<class_Image>` src **)** |
  58. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Image<class_Image>` | :ref:`create<class_Image_method_create>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format **)** |static| |
  60. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Image<class_Image>` | :ref:`create_from_data<class_Image_method_create_from_data>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format, :ref:`PackedByteArray<class_PackedByteArray>` data **)** |static| |
  62. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`crop<class_Image_method_crop>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height **)** |
  64. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`decompress<class_Image_method_decompress>` **(** **)** |
  66. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`AlphaMode<enum_Image_AlphaMode>` | :ref:`detect_alpha<class_Image_method_detect_alpha>` **(** **)** |const| |
  68. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`UsedChannels<enum_Image_UsedChannels>` | :ref:`detect_used_channels<class_Image_method_detect_used_channels>` **(** :ref:`CompressSource<enum_Image_CompressSource>` source=0 **)** |const| |
  70. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`fill<class_Image_method_fill>` **(** :ref:`Color<class_Color>` color **)** |
  72. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`fill_rect<class_Image_method_fill_rect>` **(** :ref:`Rect2i<class_Rect2i>` rect, :ref:`Color<class_Color>` color **)** |
  74. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`fix_alpha_edges<class_Image_method_fix_alpha_edges>` **(** **)** |
  76. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`flip_x<class_Image_method_flip_x>` **(** **)** |
  78. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`flip_y<class_Image_method_flip_y>` **(** **)** |
  80. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>` **(** :ref:`bool<class_bool>` renormalize=false **)** |
  82. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_data<class_Image_method_get_data>` **(** **)** |const| |
  84. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_Image_method_get_format>` **(** **)** |const| |
  86. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`int<class_int>` | :ref:`get_height<class_Image_method_get_height>` **(** **)** |const| |
  88. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`int<class_int>` | :ref:`get_mipmap_offset<class_Image_method_get_mipmap_offset>` **(** :ref:`int<class_int>` mipmap **)** |const| |
  90. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Color<class_Color>` | :ref:`get_pixel<class_Image_method_get_pixel>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  92. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Color<class_Color>` | :ref:`get_pixelv<class_Image_method_get_pixelv>` **(** :ref:`Vector2i<class_Vector2i>` point **)** |const| |
  94. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`Image<class_Image>` | :ref:`get_region<class_Image_method_get_region>` **(** :ref:`Rect2i<class_Rect2i>` region **)** |const| |
  96. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`Vector2i<class_Vector2i>` | :ref:`get_size<class_Image_method_get_size>` **(** **)** |const| |
  98. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`Rect2i<class_Rect2i>` | :ref:`get_used_rect<class_Image_method_get_used_rect>` **(** **)** |const| |
  100. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`int<class_int>` | :ref:`get_width<class_Image_method_get_width>` **(** **)** |const| |
  102. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`has_mipmaps<class_Image_method_has_mipmaps>` **(** **)** |const| |
  104. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`is_compressed<class_Image_method_is_compressed>` **(** **)** |const| |
  106. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`is_empty<class_Image_method_is_empty>` **(** **)** |const| |
  108. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`bool<class_bool>` | :ref:`is_invisible<class_Image_method_is_invisible>` **(** **)** |const| |
  110. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load<class_Image_method_load>` **(** :ref:`String<class_String>` path **)** |
  112. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_bmp_from_buffer<class_Image_method_load_bmp_from_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)** |
  114. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`Image<class_Image>` | :ref:`load_from_file<class_Image_method_load_from_file>` **(** :ref:`String<class_String>` path **)** |static| |
  116. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_jpg_from_buffer<class_Image_method_load_jpg_from_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)** |
  118. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_png_from_buffer<class_Image_method_load_png_from_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)** |
  120. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_tga_from_buffer<class_Image_method_load_tga_from_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)** |
  122. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_webp_from_buffer<class_Image_method_load_webp_from_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)** |
  124. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | void | :ref:`normal_map_to_xy<class_Image_method_normal_map_to_xy>` **(** **)** |
  126. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | void | :ref:`premultiply_alpha<class_Image_method_premultiply_alpha>` **(** **)** |
  128. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | void | :ref:`resize<class_Image_method_resize>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)** |
  130. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | void | :ref:`resize_to_po2<class_Image_method_resize_to_po2>` **(** :ref:`bool<class_bool>` square=false, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)** |
  132. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | :ref:`Image<class_Image>` | :ref:`rgbe_to_srgb<class_Image_method_rgbe_to_srgb>` **(** **)** |
  134. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | void | :ref:`rotate_180<class_Image_method_rotate_180>` **(** **)** |
  136. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | void | :ref:`rotate_90<class_Image_method_rotate_90>` **(** :ref:`ClockDirection<enum_@GlobalScope_ClockDirection>` direction **)** |
  138. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_exr<class_Image_method_save_exr>` **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` grayscale=false **)** |const| |
  140. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_exr_to_buffer<class_Image_method_save_exr_to_buffer>` **(** :ref:`bool<class_bool>` grayscale=false **)** |const| |
  142. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_jpg<class_Image_method_save_jpg>` **(** :ref:`String<class_String>` path, :ref:`float<class_float>` quality=0.75 **)** |const| |
  144. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_jpg_to_buffer<class_Image_method_save_jpg_to_buffer>` **(** :ref:`float<class_float>` quality=0.75 **)** |const| |
  146. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  147. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_png<class_Image_method_save_png>` **(** :ref:`String<class_String>` path **)** |const| |
  148. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  149. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_png_to_buffer<class_Image_method_save_png_to_buffer>` **(** **)** |const| |
  150. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  151. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_webp<class_Image_method_save_webp>` **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` lossy=false, :ref:`float<class_float>` quality=0.75 **)** |const| |
  152. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  153. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_webp_to_buffer<class_Image_method_save_webp_to_buffer>` **(** :ref:`bool<class_bool>` lossy=false, :ref:`float<class_float>` quality=0.75 **)** |const| |
  154. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  155. | void | :ref:`set_data<class_Image_method_set_data>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format, :ref:`PackedByteArray<class_PackedByteArray>` data **)** |
  156. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  157. | void | :ref:`set_pixel<class_Image_method_set_pixel>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`Color<class_Color>` color **)** |
  158. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  159. | void | :ref:`set_pixelv<class_Image_method_set_pixelv>` **(** :ref:`Vector2i<class_Vector2i>` point, :ref:`Color<class_Color>` color **)** |
  160. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  161. | void | :ref:`shrink_x2<class_Image_method_shrink_x2>` **(** **)** |
  162. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  163. | void | :ref:`srgb_to_linear<class_Image_method_srgb_to_linear>` **(** **)** |
  164. +-----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  165. .. rst-class:: classref-section-separator
  166. ----
  167. .. rst-class:: classref-descriptions-group
  168. Enumerations
  169. ------------
  170. .. _enum_Image_Format:
  171. .. rst-class:: classref-enumeration
  172. enum **Format**:
  173. .. _class_Image_constant_FORMAT_L8:
  174. .. rst-class:: classref-enumeration-constant
  175. :ref:`Format<enum_Image_Format>` **FORMAT_L8** = ``0``
  176. Texture format with a single 8-bit depth representing luminance.
  177. .. _class_Image_constant_FORMAT_LA8:
  178. .. rst-class:: classref-enumeration-constant
  179. :ref:`Format<enum_Image_Format>` **FORMAT_LA8** = ``1``
  180. OpenGL texture format with two values, luminance and alpha each stored with 8 bits.
  181. .. _class_Image_constant_FORMAT_R8:
  182. .. rst-class:: classref-enumeration-constant
  183. :ref:`Format<enum_Image_Format>` **FORMAT_R8** = ``2``
  184. OpenGL texture format ``RED`` with a single component and a bitdepth of 8.
  185. .. _class_Image_constant_FORMAT_RG8:
  186. .. rst-class:: classref-enumeration-constant
  187. :ref:`Format<enum_Image_Format>` **FORMAT_RG8** = ``3``
  188. OpenGL texture format ``RG`` with two components and a bitdepth of 8 for each.
  189. .. _class_Image_constant_FORMAT_RGB8:
  190. .. rst-class:: classref-enumeration-constant
  191. :ref:`Format<enum_Image_Format>` **FORMAT_RGB8** = ``4``
  192. OpenGL texture format ``RGB`` with three components, each with a bitdepth of 8.
  193. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  194. .. _class_Image_constant_FORMAT_RGBA8:
  195. .. rst-class:: classref-enumeration-constant
  196. :ref:`Format<enum_Image_Format>` **FORMAT_RGBA8** = ``5``
  197. OpenGL texture format ``RGBA`` with four components, each with a bitdepth of 8.
  198. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  199. .. _class_Image_constant_FORMAT_RGBA4444:
  200. .. rst-class:: classref-enumeration-constant
  201. :ref:`Format<enum_Image_Format>` **FORMAT_RGBA4444** = ``6``
  202. OpenGL texture format ``RGBA`` with four components, each with a bitdepth of 4.
  203. .. _class_Image_constant_FORMAT_RGB565:
  204. .. rst-class:: classref-enumeration-constant
  205. :ref:`Format<enum_Image_Format>` **FORMAT_RGB565** = ``7``
  206. .. _class_Image_constant_FORMAT_RF:
  207. .. rst-class:: classref-enumeration-constant
  208. :ref:`Format<enum_Image_Format>` **FORMAT_RF** = ``8``
  209. OpenGL texture format ``GL_R32F`` where there's one component, a 32-bit floating-point value.
  210. .. _class_Image_constant_FORMAT_RGF:
  211. .. rst-class:: classref-enumeration-constant
  212. :ref:`Format<enum_Image_Format>` **FORMAT_RGF** = ``9``
  213. OpenGL texture format ``GL_RG32F`` where there are two components, each a 32-bit floating-point values.
  214. .. _class_Image_constant_FORMAT_RGBF:
  215. .. rst-class:: classref-enumeration-constant
  216. :ref:`Format<enum_Image_Format>` **FORMAT_RGBF** = ``10``
  217. OpenGL texture format ``GL_RGB32F`` where there are three components, each a 32-bit floating-point values.
  218. .. _class_Image_constant_FORMAT_RGBAF:
  219. .. rst-class:: classref-enumeration-constant
  220. :ref:`Format<enum_Image_Format>` **FORMAT_RGBAF** = ``11``
  221. OpenGL texture format ``GL_RGBA32F`` where there are four components, each a 32-bit floating-point values.
  222. .. _class_Image_constant_FORMAT_RH:
  223. .. rst-class:: classref-enumeration-constant
  224. :ref:`Format<enum_Image_Format>` **FORMAT_RH** = ``12``
  225. OpenGL texture format ``GL_R32F`` where there's one component, a 16-bit "half-precision" floating-point value.
  226. .. _class_Image_constant_FORMAT_RGH:
  227. .. rst-class:: classref-enumeration-constant
  228. :ref:`Format<enum_Image_Format>` **FORMAT_RGH** = ``13``
  229. OpenGL texture format ``GL_RG32F`` where there are two components, each a 16-bit "half-precision" floating-point value.
  230. .. _class_Image_constant_FORMAT_RGBH:
  231. .. rst-class:: classref-enumeration-constant
  232. :ref:`Format<enum_Image_Format>` **FORMAT_RGBH** = ``14``
  233. OpenGL texture format ``GL_RGB32F`` where there are three components, each a 16-bit "half-precision" floating-point value.
  234. .. _class_Image_constant_FORMAT_RGBAH:
  235. .. rst-class:: classref-enumeration-constant
  236. :ref:`Format<enum_Image_Format>` **FORMAT_RGBAH** = ``15``
  237. OpenGL texture format ``GL_RGBA32F`` where there are four components, each a 16-bit "half-precision" floating-point value.
  238. .. _class_Image_constant_FORMAT_RGBE9995:
  239. .. rst-class:: classref-enumeration-constant
  240. :ref:`Format<enum_Image_Format>` **FORMAT_RGBE9995** = ``16``
  241. A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent.
  242. .. _class_Image_constant_FORMAT_DXT1:
  243. .. rst-class:: classref-enumeration-constant
  244. :ref:`Format<enum_Image_Format>` **FORMAT_DXT1** = ``17``
  245. The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 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.
  246. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  247. .. _class_Image_constant_FORMAT_DXT3:
  248. .. rst-class:: classref-enumeration-constant
  249. :ref:`Format<enum_Image_Format>` **FORMAT_DXT3** = ``18``
  250. The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 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.
  251. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  252. .. _class_Image_constant_FORMAT_DXT5:
  253. .. rst-class:: classref-enumeration-constant
  254. :ref:`Format<enum_Image_Format>` **FORMAT_DXT5** = ``19``
  255. The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 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.
  256. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  257. .. _class_Image_constant_FORMAT_RGTC_R:
  258. .. rst-class:: classref-enumeration-constant
  259. :ref:`Format<enum_Image_Format>` **FORMAT_RGTC_R** = ``20``
  260. Texture format that uses `Red Green Texture Compression <https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression>`__, normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel.
  261. .. _class_Image_constant_FORMAT_RGTC_RG:
  262. .. rst-class:: classref-enumeration-constant
  263. :ref:`Format<enum_Image_Format>` **FORMAT_RGTC_RG** = ``21``
  264. Texture format that uses `Red Green Texture Compression <https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression>`__, normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel.
  265. .. _class_Image_constant_FORMAT_BPTC_RGBA:
  266. .. rst-class:: classref-enumeration-constant
  267. :ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBA** = ``22``
  268. Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with unsigned normalized RGBA components.
  269. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  270. .. _class_Image_constant_FORMAT_BPTC_RGBF:
  271. .. rst-class:: classref-enumeration-constant
  272. :ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBF** = ``23``
  273. Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with signed floating-point RGB components.
  274. .. _class_Image_constant_FORMAT_BPTC_RGBFU:
  275. .. rst-class:: classref-enumeration-constant
  276. :ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBFU** = ``24``
  277. Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with unsigned floating-point RGB components.
  278. .. _class_Image_constant_FORMAT_ETC:
  279. .. rst-class:: classref-enumeration-constant
  280. :ref:`Format<enum_Image_Format>` **FORMAT_ETC** = ``25``
  281. `Ericsson Texture Compression format 1 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC1>`__, also referred to as "ETC1", and is part of the OpenGL ES graphics standard. This format cannot store an alpha channel.
  282. .. _class_Image_constant_FORMAT_ETC2_R11:
  283. .. rst-class:: classref-enumeration-constant
  284. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_R11** = ``26``
  285. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``R11_EAC`` variant), which provides one channel of unsigned data.
  286. .. _class_Image_constant_FORMAT_ETC2_R11S:
  287. .. rst-class:: classref-enumeration-constant
  288. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_R11S** = ``27``
  289. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``SIGNED_R11_EAC`` variant), which provides one channel of signed data.
  290. .. _class_Image_constant_FORMAT_ETC2_RG11:
  291. .. rst-class:: classref-enumeration-constant
  292. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RG11** = ``28``
  293. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RG11_EAC`` variant), which provides two channels of unsigned data.
  294. .. _class_Image_constant_FORMAT_ETC2_RG11S:
  295. .. rst-class:: classref-enumeration-constant
  296. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RG11S** = ``29``
  297. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``SIGNED_RG11_EAC`` variant), which provides two channels of signed data.
  298. .. _class_Image_constant_FORMAT_ETC2_RGB8:
  299. .. rst-class:: classref-enumeration-constant
  300. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGB8** = ``30``
  301. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGB8`` variant), which is a follow-up of ETC1 and compresses RGB888 data.
  302. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  303. .. _class_Image_constant_FORMAT_ETC2_RGBA8:
  304. .. rst-class:: classref-enumeration-constant
  305. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGBA8** = ``31``
  306. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGBA8``\ variant), which compresses RGBA8888 data with full alpha support.
  307. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  308. .. _class_Image_constant_FORMAT_ETC2_RGB8A1:
  309. .. rst-class:: classref-enumeration-constant
  310. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGB8A1** = ``32``
  311. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGB8_PUNCHTHROUGH_ALPHA1`` variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
  312. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  313. .. _class_Image_constant_FORMAT_ETC2_RA_AS_RG:
  314. .. rst-class:: classref-enumeration-constant
  315. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RA_AS_RG** = ``33``
  316. .. _class_Image_constant_FORMAT_DXT5_RA_AS_RG:
  317. .. rst-class:: classref-enumeration-constant
  318. :ref:`Format<enum_Image_Format>` **FORMAT_DXT5_RA_AS_RG** = ``34``
  319. .. _class_Image_constant_FORMAT_ASTC_4x4:
  320. .. rst-class:: classref-enumeration-constant
  321. :ref:`Format<enum_Image_Format>` **FORMAT_ASTC_4x4** = ``35``
  322. `Adaptive Scalable Texutre Compression <https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression>`__. This implements the 4x4 (high quality) mode.
  323. .. _class_Image_constant_FORMAT_ASTC_4x4_HDR:
  324. .. rst-class:: classref-enumeration-constant
  325. :ref:`Format<enum_Image_Format>` **FORMAT_ASTC_4x4_HDR** = ``36``
  326. Same format as :ref:`FORMAT_ASTC_4x4<class_Image_constant_FORMAT_ASTC_4x4>`, but with the hint to let the GPU know it is used for HDR.
  327. .. _class_Image_constant_FORMAT_ASTC_8x8:
  328. .. rst-class:: classref-enumeration-constant
  329. :ref:`Format<enum_Image_Format>` **FORMAT_ASTC_8x8** = ``37``
  330. `Adaptive Scalable Texutre Compression <https://en.wikipedia.org/wiki/Adaptive_scalable_texture_compression>`__. This implements the 8x8 (low quality) mode.
  331. .. _class_Image_constant_FORMAT_ASTC_8x8_HDR:
  332. .. rst-class:: classref-enumeration-constant
  333. :ref:`Format<enum_Image_Format>` **FORMAT_ASTC_8x8_HDR** = ``38``
  334. Same format as :ref:`FORMAT_ASTC_8x8<class_Image_constant_FORMAT_ASTC_8x8>`, but with the hint to let the GPU know it is used for HDR.
  335. .. _class_Image_constant_FORMAT_MAX:
  336. .. rst-class:: classref-enumeration-constant
  337. :ref:`Format<enum_Image_Format>` **FORMAT_MAX** = ``39``
  338. Represents the size of the :ref:`Format<enum_Image_Format>` enum.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _enum_Image_Interpolation:
  342. .. rst-class:: classref-enumeration
  343. enum **Interpolation**:
  344. .. _class_Image_constant_INTERPOLATE_NEAREST:
  345. .. rst-class:: classref-enumeration-constant
  346. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_NEAREST** = ``0``
  347. Performs nearest-neighbor interpolation. If the image is resized, it will be pixelated.
  348. .. _class_Image_constant_INTERPOLATE_BILINEAR:
  349. .. rst-class:: classref-enumeration-constant
  350. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_BILINEAR** = ``1``
  351. Performs bilinear interpolation. If the image is resized, it will be blurry. This mode is faster than :ref:`INTERPOLATE_CUBIC<class_Image_constant_INTERPOLATE_CUBIC>`, but it results in lower quality.
  352. .. _class_Image_constant_INTERPOLATE_CUBIC:
  353. .. rst-class:: classref-enumeration-constant
  354. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_CUBIC** = ``2``
  355. Performs cubic interpolation. If the image is resized, it will be blurry. This mode often gives better results compared to :ref:`INTERPOLATE_BILINEAR<class_Image_constant_INTERPOLATE_BILINEAR>`, at the cost of being slower.
  356. .. _class_Image_constant_INTERPOLATE_TRILINEAR:
  357. .. rst-class:: classref-enumeration-constant
  358. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_TRILINEAR** = ``3``
  359. Performs bilinear separately on the two most-suited mipmap levels, then linearly interpolates between them.
  360. It's slower than :ref:`INTERPOLATE_BILINEAR<class_Image_constant_INTERPOLATE_BILINEAR>`, but produces higher-quality results with far fewer aliasing artifacts.
  361. If the image does not have mipmaps, they will be generated and used internally, but no mipmaps will be generated on the resulting image.
  362. \ **Note:** If you intend to scale multiple copies of the original image, it's better to call :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`] on it in advance, to avoid wasting processing power in generating them again and again.
  363. 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.
  364. .. _class_Image_constant_INTERPOLATE_LANCZOS:
  365. .. rst-class:: classref-enumeration-constant
  366. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_LANCZOS** = ``4``
  367. Performs Lanczos interpolation. This is the slowest image resizing mode, but it typically gives the best results, especially when downscalng images.
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _enum_Image_AlphaMode:
  371. .. rst-class:: classref-enumeration
  372. enum **AlphaMode**:
  373. .. _class_Image_constant_ALPHA_NONE:
  374. .. rst-class:: classref-enumeration-constant
  375. :ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_NONE** = ``0``
  376. Image does not have alpha.
  377. .. _class_Image_constant_ALPHA_BIT:
  378. .. rst-class:: classref-enumeration-constant
  379. :ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_BIT** = ``1``
  380. Image stores alpha in a single bit.
  381. .. _class_Image_constant_ALPHA_BLEND:
  382. .. rst-class:: classref-enumeration-constant
  383. :ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_BLEND** = ``2``
  384. Image uses alpha.
  385. .. rst-class:: classref-item-separator
  386. ----
  387. .. _enum_Image_CompressMode:
  388. .. rst-class:: classref-enumeration
  389. enum **CompressMode**:
  390. .. _class_Image_constant_COMPRESS_S3TC:
  391. .. rst-class:: classref-enumeration-constant
  392. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_S3TC** = ``0``
  393. Use S3TC compression.
  394. .. _class_Image_constant_COMPRESS_ETC:
  395. .. rst-class:: classref-enumeration-constant
  396. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ETC** = ``1``
  397. Use ETC compression.
  398. .. _class_Image_constant_COMPRESS_ETC2:
  399. .. rst-class:: classref-enumeration-constant
  400. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ETC2** = ``2``
  401. Use ETC2 compression.
  402. .. _class_Image_constant_COMPRESS_BPTC:
  403. .. rst-class:: classref-enumeration-constant
  404. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_BPTC** = ``3``
  405. Use BPTC compression.
  406. .. rst-class:: classref-item-separator
  407. ----
  408. .. _enum_Image_UsedChannels:
  409. .. rst-class:: classref-enumeration
  410. enum **UsedChannels**:
  411. .. _class_Image_constant_USED_CHANNELS_L:
  412. .. rst-class:: classref-enumeration-constant
  413. :ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_L** = ``0``
  414. .. _class_Image_constant_USED_CHANNELS_LA:
  415. .. rst-class:: classref-enumeration-constant
  416. :ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_LA** = ``1``
  417. .. _class_Image_constant_USED_CHANNELS_R:
  418. .. rst-class:: classref-enumeration-constant
  419. :ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_R** = ``2``
  420. .. _class_Image_constant_USED_CHANNELS_RG:
  421. .. rst-class:: classref-enumeration-constant
  422. :ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_RG** = ``3``
  423. .. _class_Image_constant_USED_CHANNELS_RGB:
  424. .. rst-class:: classref-enumeration-constant
  425. :ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_RGB** = ``4``
  426. .. _class_Image_constant_USED_CHANNELS_RGBA:
  427. .. rst-class:: classref-enumeration-constant
  428. :ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_RGBA** = ``5``
  429. .. rst-class:: classref-item-separator
  430. ----
  431. .. _enum_Image_CompressSource:
  432. .. rst-class:: classref-enumeration
  433. enum **CompressSource**:
  434. .. _class_Image_constant_COMPRESS_SOURCE_GENERIC:
  435. .. rst-class:: classref-enumeration-constant
  436. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_GENERIC** = ``0``
  437. Source texture (before compression) is a regular texture. Default for all textures.
  438. .. _class_Image_constant_COMPRESS_SOURCE_SRGB:
  439. .. rst-class:: classref-enumeration-constant
  440. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_SRGB** = ``1``
  441. Source texture (before compression) is in sRGB space.
  442. .. _class_Image_constant_COMPRESS_SOURCE_NORMAL:
  443. .. rst-class:: classref-enumeration-constant
  444. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_NORMAL** = ``2``
  445. Source texture (before compression) is a normal texture (e.g. it can be compressed into two channels).
  446. .. rst-class:: classref-item-separator
  447. ----
  448. .. _enum_Image_ASTCFormat:
  449. .. rst-class:: classref-enumeration
  450. enum **ASTCFormat**:
  451. .. _class_Image_constant_ASTC_FORMAT_4x4:
  452. .. rst-class:: classref-enumeration-constant
  453. :ref:`ASTCFormat<enum_Image_ASTCFormat>` **ASTC_FORMAT_4x4** = ``0``
  454. Hint to indicate that the high quality 4x4 ASTC compression format should be used.
  455. .. _class_Image_constant_ASTC_FORMAT_8x8:
  456. .. rst-class:: classref-enumeration-constant
  457. :ref:`ASTCFormat<enum_Image_ASTCFormat>` **ASTC_FORMAT_8x8** = ``1``
  458. Hint to indicate that the low quality 8x8 ASTC compression format should be used.
  459. .. rst-class:: classref-section-separator
  460. ----
  461. .. rst-class:: classref-descriptions-group
  462. Constants
  463. ---------
  464. .. _class_Image_constant_MAX_WIDTH:
  465. .. rst-class:: classref-constant
  466. **MAX_WIDTH** = ``16777216``
  467. The maximal width allowed for **Image** resources.
  468. .. _class_Image_constant_MAX_HEIGHT:
  469. .. rst-class:: classref-constant
  470. **MAX_HEIGHT** = ``16777216``
  471. The maximal height allowed for **Image** resources.
  472. .. rst-class:: classref-section-separator
  473. ----
  474. .. rst-class:: classref-descriptions-group
  475. Property Descriptions
  476. ---------------------
  477. .. _class_Image_property_data:
  478. .. rst-class:: classref-property
  479. :ref:`Dictionary<class_Dictionary>` **data** = ``{ "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 }``
  480. Holds all the image's color data in a given format. See :ref:`Format<enum_Image_Format>` constants.
  481. .. rst-class:: classref-section-separator
  482. ----
  483. .. rst-class:: classref-descriptions-group
  484. Method Descriptions
  485. -------------------
  486. .. _class_Image_method_adjust_bcs:
  487. .. rst-class:: classref-method
  488. void **adjust_bcs** **(** :ref:`float<class_float>` brightness, :ref:`float<class_float>` contrast, :ref:`float<class_float>` saturation **)**
  489. .. container:: contribute
  490. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  491. .. rst-class:: classref-item-separator
  492. ----
  493. .. _class_Image_method_blend_rect:
  494. .. rst-class:: classref-method
  495. void **blend_rect** **(** :ref:`Image<class_Image>` src, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)**
  496. 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.
  497. .. rst-class:: classref-item-separator
  498. ----
  499. .. _class_Image_method_blend_rect_mask:
  500. .. rst-class:: classref-method
  501. void **blend_rect_mask** **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)**
  502. 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.
  503. .. rst-class:: classref-item-separator
  504. ----
  505. .. _class_Image_method_blit_rect:
  506. .. rst-class:: classref-method
  507. void **blit_rect** **(** :ref:`Image<class_Image>` src, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)**
  508. 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.
  509. .. rst-class:: classref-item-separator
  510. ----
  511. .. _class_Image_method_blit_rect_mask:
  512. .. rst-class:: classref-method
  513. void **blit_rect_mask** **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2i<class_Rect2i>` src_rect, :ref:`Vector2i<class_Vector2i>` dst **)**
  514. 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.
  515. .. rst-class:: classref-item-separator
  516. ----
  517. .. _class_Image_method_bump_map_to_normal_map:
  518. .. rst-class:: classref-method
  519. void **bump_map_to_normal_map** **(** :ref:`float<class_float>` bump_scale=1.0 **)**
  520. 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.
  521. .. rst-class:: classref-item-separator
  522. ----
  523. .. _class_Image_method_clear_mipmaps:
  524. .. rst-class:: classref-method
  525. void **clear_mipmaps** **(** **)**
  526. Removes the image's mipmaps.
  527. .. rst-class:: classref-item-separator
  528. ----
  529. .. _class_Image_method_compress:
  530. .. rst-class:: classref-method
  531. :ref:`Error<enum_@GlobalScope_Error>` **compress** **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`CompressSource<enum_Image_CompressSource>` source=0, :ref:`ASTCFormat<enum_Image_ASTCFormat>` astc_format=0 **)**
  532. 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.
  533. The ``mode`` parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
  534. For ASTC compression, the ``astc_format`` parameter must be supplied.
  535. .. rst-class:: classref-item-separator
  536. ----
  537. .. _class_Image_method_compress_from_channels:
  538. .. rst-class:: classref-method
  539. :ref:`Error<enum_@GlobalScope_Error>` **compress_from_channels** **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`UsedChannels<enum_Image_UsedChannels>` channels, :ref:`ASTCFormat<enum_Image_ASTCFormat>` astc_format=0 **)**
  540. 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.
  541. This is an alternative to :ref:`compress<class_Image_method_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.
  542. For ASTC compression, the ``astc_format`` parameter must be supplied.
  543. .. rst-class:: classref-item-separator
  544. ----
  545. .. _class_Image_method_compute_image_metrics:
  546. .. rst-class:: classref-method
  547. :ref:`Dictionary<class_Dictionary>` **compute_image_metrics** **(** :ref:`Image<class_Image>` compared_image, :ref:`bool<class_bool>` use_luma **)**
  548. Compute image metrics on the current image and the compared image.
  549. The dictionary contains ``max``, ``mean``, ``mean_squared``, ``root_mean_squared`` and ``peak_snr``.
  550. .. rst-class:: classref-item-separator
  551. ----
  552. .. _class_Image_method_convert:
  553. .. rst-class:: classref-method
  554. void **convert** **(** :ref:`Format<enum_Image_Format>` format **)**
  555. Converts the image's format. See :ref:`Format<enum_Image_Format>` constants.
  556. .. rst-class:: classref-item-separator
  557. ----
  558. .. _class_Image_method_copy_from:
  559. .. rst-class:: classref-method
  560. void **copy_from** **(** :ref:`Image<class_Image>` src **)**
  561. Copies ``src`` image to this image.
  562. .. rst-class:: classref-item-separator
  563. ----
  564. .. _class_Image_method_create:
  565. .. rst-class:: classref-method
  566. :ref:`Image<class_Image>` **create** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format **)** |static|
  567. Creates an empty image of given size and format. See :ref:`Format<enum_Image_Format>` constants. If ``use_mipmaps`` is ``true``, then generate mipmaps for this image. See the :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`.
  568. .. rst-class:: classref-item-separator
  569. ----
  570. .. _class_Image_method_create_from_data:
  571. .. rst-class:: classref-method
  572. :ref:`Image<class_Image>` **create_from_data** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format, :ref:`PackedByteArray<class_PackedByteArray>` data **)** |static|
  573. Creates a new image of given size and format. See :ref:`Format<enum_Image_Format>` constants. Fills the image with the given raw data. If ``use_mipmaps`` is ``true`` then loads mipmaps for this image from ``data``. See :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`.
  574. .. rst-class:: classref-item-separator
  575. ----
  576. .. _class_Image_method_crop:
  577. .. rst-class:: classref-method
  578. void **crop** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height **)**
  579. 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.
  580. .. rst-class:: classref-item-separator
  581. ----
  582. .. _class_Image_method_decompress:
  583. .. rst-class:: classref-method
  584. :ref:`Error<enum_@GlobalScope_Error>` **decompress** **(** **)**
  585. Decompresses the image if it is VRAM compressed in a supported format. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` if the format is supported, otherwise :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`.
  586. \ **Note:** The following formats can be decompressed: DXT, RGTC, BPTC. The formats ETC1 and ETC2 are not supported.
  587. .. rst-class:: classref-item-separator
  588. ----
  589. .. _class_Image_method_detect_alpha:
  590. .. rst-class:: classref-method
  591. :ref:`AlphaMode<enum_Image_AlphaMode>` **detect_alpha** **(** **)** |const|
  592. Returns :ref:`ALPHA_BLEND<class_Image_constant_ALPHA_BLEND>` if the image has data for alpha values. Returns :ref:`ALPHA_BIT<class_Image_constant_ALPHA_BIT>` if all the alpha values are stored in a single bit. Returns :ref:`ALPHA_NONE<class_Image_constant_ALPHA_NONE>` if no data for alpha values is found.
  593. .. rst-class:: classref-item-separator
  594. ----
  595. .. _class_Image_method_detect_used_channels:
  596. .. rst-class:: classref-method
  597. :ref:`UsedChannels<enum_Image_UsedChannels>` **detect_used_channels** **(** :ref:`CompressSource<enum_Image_CompressSource>` source=0 **)** |const|
  598. .. container:: contribute
  599. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  600. .. rst-class:: classref-item-separator
  601. ----
  602. .. _class_Image_method_fill:
  603. .. rst-class:: classref-method
  604. void **fill** **(** :ref:`Color<class_Color>` color **)**
  605. Fills the image with ``color``.
  606. .. rst-class:: classref-item-separator
  607. ----
  608. .. _class_Image_method_fill_rect:
  609. .. rst-class:: classref-method
  610. void **fill_rect** **(** :ref:`Rect2i<class_Rect2i>` rect, :ref:`Color<class_Color>` color **)**
  611. Fills ``rect`` with ``color``.
  612. .. rst-class:: classref-item-separator
  613. ----
  614. .. _class_Image_method_fix_alpha_edges:
  615. .. rst-class:: classref-method
  616. void **fix_alpha_edges** **(** **)**
  617. Blends low-alpha pixels with nearby pixels.
  618. .. rst-class:: classref-item-separator
  619. ----
  620. .. _class_Image_method_flip_x:
  621. .. rst-class:: classref-method
  622. void **flip_x** **(** **)**
  623. Flips the image horizontally.
  624. .. rst-class:: classref-item-separator
  625. ----
  626. .. _class_Image_method_flip_y:
  627. .. rst-class:: classref-method
  628. void **flip_y** **(** **)**
  629. Flips the image vertically.
  630. .. rst-class:: classref-item-separator
  631. ----
  632. .. _class_Image_method_generate_mipmaps:
  633. .. rst-class:: classref-method
  634. :ref:`Error<enum_@GlobalScope_Error>` **generate_mipmaps** **(** :ref:`bool<class_bool>` renormalize=false **)**
  635. 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``.
  636. .. rst-class:: classref-item-separator
  637. ----
  638. .. _class_Image_method_get_data:
  639. .. rst-class:: classref-method
  640. :ref:`PackedByteArray<class_PackedByteArray>` **get_data** **(** **)** |const|
  641. Returns a copy of the image's raw data.
  642. .. rst-class:: classref-item-separator
  643. ----
  644. .. _class_Image_method_get_format:
  645. .. rst-class:: classref-method
  646. :ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
  647. Returns the image's format. See :ref:`Format<enum_Image_Format>` constants.
  648. .. rst-class:: classref-item-separator
  649. ----
  650. .. _class_Image_method_get_height:
  651. .. rst-class:: classref-method
  652. :ref:`int<class_int>` **get_height** **(** **)** |const|
  653. Returns the image's height.
  654. .. rst-class:: classref-item-separator
  655. ----
  656. .. _class_Image_method_get_mipmap_offset:
  657. .. rst-class:: classref-method
  658. :ref:`int<class_int>` **get_mipmap_offset** **(** :ref:`int<class_int>` mipmap **)** |const|
  659. Returns the offset where the image's mipmap with index ``mipmap`` is stored in the ``data`` dictionary.
  660. .. rst-class:: classref-item-separator
  661. ----
  662. .. _class_Image_method_get_pixel:
  663. .. rst-class:: classref-method
  664. :ref:`Color<class_Color>` **get_pixel** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  665. Returns the color of the pixel at ``(x, y)``.
  666. This is the same as :ref:`get_pixelv<class_Image_method_get_pixelv>`, but with two integer arguments instead of a :ref:`Vector2i<class_Vector2i>` argument.
  667. .. rst-class:: classref-item-separator
  668. ----
  669. .. _class_Image_method_get_pixelv:
  670. .. rst-class:: classref-method
  671. :ref:`Color<class_Color>` **get_pixelv** **(** :ref:`Vector2i<class_Vector2i>` point **)** |const|
  672. Returns the color of the pixel at ``point``.
  673. This is the same as :ref:`get_pixel<class_Image_method_get_pixel>`, but with a :ref:`Vector2i<class_Vector2i>` argument instead of two integer arguments.
  674. .. rst-class:: classref-item-separator
  675. ----
  676. .. _class_Image_method_get_region:
  677. .. rst-class:: classref-method
  678. :ref:`Image<class_Image>` **get_region** **(** :ref:`Rect2i<class_Rect2i>` region **)** |const|
  679. Returns a new **Image** that is a copy of this **Image**'s area specified with ``region``.
  680. .. rst-class:: classref-item-separator
  681. ----
  682. .. _class_Image_method_get_size:
  683. .. rst-class:: classref-method
  684. :ref:`Vector2i<class_Vector2i>` **get_size** **(** **)** |const|
  685. Returns the image's size (width and height).
  686. .. rst-class:: classref-item-separator
  687. ----
  688. .. _class_Image_method_get_used_rect:
  689. .. rst-class:: classref-method
  690. :ref:`Rect2i<class_Rect2i>` **get_used_rect** **(** **)** |const|
  691. Returns a :ref:`Rect2i<class_Rect2i>` enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
  692. .. rst-class:: classref-item-separator
  693. ----
  694. .. _class_Image_method_get_width:
  695. .. rst-class:: classref-method
  696. :ref:`int<class_int>` **get_width** **(** **)** |const|
  697. Returns the image's width.
  698. .. rst-class:: classref-item-separator
  699. ----
  700. .. _class_Image_method_has_mipmaps:
  701. .. rst-class:: classref-method
  702. :ref:`bool<class_bool>` **has_mipmaps** **(** **)** |const|
  703. Returns ``true`` if the image has generated mipmaps.
  704. .. rst-class:: classref-item-separator
  705. ----
  706. .. _class_Image_method_is_compressed:
  707. .. rst-class:: classref-method
  708. :ref:`bool<class_bool>` **is_compressed** **(** **)** |const|
  709. Returns ``true`` if the image is compressed.
  710. .. rst-class:: classref-item-separator
  711. ----
  712. .. _class_Image_method_is_empty:
  713. .. rst-class:: classref-method
  714. :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  715. Returns ``true`` if the image has no data.
  716. .. rst-class:: classref-item-separator
  717. ----
  718. .. _class_Image_method_is_invisible:
  719. .. rst-class:: classref-method
  720. :ref:`bool<class_bool>` **is_invisible** **(** **)** |const|
  721. 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.
  722. .. rst-class:: classref-item-separator
  723. ----
  724. .. _class_Image_method_load:
  725. .. rst-class:: classref-method
  726. :ref:`Error<enum_@GlobalScope_Error>` **load** **(** :ref:`String<class_String>` path **)**
  727. Loads an image from file ``path``. See `Supported image formats <../tutorials/assets_pipeline/importing_images.html#supported-image-formats>`__ for a list of supported image formats and limitations.
  728. \ **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.
  729. See also :ref:`ImageTexture<class_ImageTexture>` description for usage examples.
  730. .. rst-class:: classref-item-separator
  731. ----
  732. .. _class_Image_method_load_bmp_from_buffer:
  733. .. rst-class:: classref-method
  734. :ref:`Error<enum_@GlobalScope_Error>` **load_bmp_from_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)**
  735. Loads an image from the binary contents of a BMP file.
  736. \ **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.
  737. .. rst-class:: classref-item-separator
  738. ----
  739. .. _class_Image_method_load_from_file:
  740. .. rst-class:: classref-method
  741. :ref:`Image<class_Image>` **load_from_file** **(** :ref:`String<class_String>` path **)** |static|
  742. Creates a new **Image** and loads data from the specified file.
  743. .. rst-class:: classref-item-separator
  744. ----
  745. .. _class_Image_method_load_jpg_from_buffer:
  746. .. rst-class:: classref-method
  747. :ref:`Error<enum_@GlobalScope_Error>` **load_jpg_from_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)**
  748. Loads an image from the binary contents of a JPEG file.
  749. .. rst-class:: classref-item-separator
  750. ----
  751. .. _class_Image_method_load_png_from_buffer:
  752. .. rst-class:: classref-method
  753. :ref:`Error<enum_@GlobalScope_Error>` **load_png_from_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)**
  754. Loads an image from the binary contents of a PNG file.
  755. .. rst-class:: classref-item-separator
  756. ----
  757. .. _class_Image_method_load_tga_from_buffer:
  758. .. rst-class:: classref-method
  759. :ref:`Error<enum_@GlobalScope_Error>` **load_tga_from_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)**
  760. Loads an image from the binary contents of a TGA file.
  761. .. rst-class:: classref-item-separator
  762. ----
  763. .. _class_Image_method_load_webp_from_buffer:
  764. .. rst-class:: classref-method
  765. :ref:`Error<enum_@GlobalScope_Error>` **load_webp_from_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)**
  766. Loads an image from the binary contents of a WebP file.
  767. .. rst-class:: classref-item-separator
  768. ----
  769. .. _class_Image_method_normal_map_to_xy:
  770. .. rst-class:: classref-method
  771. void **normal_map_to_xy** **(** **)**
  772. 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.
  773. .. rst-class:: classref-item-separator
  774. ----
  775. .. _class_Image_method_premultiply_alpha:
  776. .. rst-class:: classref-method
  777. void **premultiply_alpha** **(** **)**
  778. Multiplies color values with alpha values. Resulting color values for a pixel are ``(color * alpha)/256``.
  779. .. rst-class:: classref-item-separator
  780. ----
  781. .. _class_Image_method_resize:
  782. .. rst-class:: classref-method
  783. void **resize** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)**
  784. Resizes the image to the given ``width`` and ``height``. New pixels are calculated using the ``interpolation`` mode defined via :ref:`Interpolation<enum_Image_Interpolation>` constants.
  785. .. rst-class:: classref-item-separator
  786. ----
  787. .. _class_Image_method_resize_to_po2:
  788. .. rst-class:: classref-method
  789. void **resize_to_po2** **(** :ref:`bool<class_bool>` square=false, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)**
  790. 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 :ref:`Interpolation<enum_Image_Interpolation>` constants.
  791. .. rst-class:: classref-item-separator
  792. ----
  793. .. _class_Image_method_rgbe_to_srgb:
  794. .. rst-class:: classref-method
  795. :ref:`Image<class_Image>` **rgbe_to_srgb** **(** **)**
  796. Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
  797. .. rst-class:: classref-item-separator
  798. ----
  799. .. _class_Image_method_rotate_180:
  800. .. rst-class:: classref-method
  801. void **rotate_180** **(** **)**
  802. Rotates the image by ``180`` degrees. The width and height of the image must be greater than ``1``.
  803. .. rst-class:: classref-item-separator
  804. ----
  805. .. _class_Image_method_rotate_90:
  806. .. rst-class:: classref-method
  807. void **rotate_90** **(** :ref:`ClockDirection<enum_@GlobalScope_ClockDirection>` direction **)**
  808. 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.
  809. .. rst-class:: classref-item-separator
  810. ----
  811. .. _class_Image_method_save_exr:
  812. .. rst-class:: classref-method
  813. :ref:`Error<enum_@GlobalScope_Error>` **save_exr** **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` grayscale=false **)** |const|
  814. 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 :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` if Godot was compiled without the TinyEXR module.
  815. \ **Note:** The TinyEXR module is disabled in non-editor builds, which means :ref:`save_exr<class_Image_method_save_exr>` will return :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` when it is called from an exported project.
  816. .. rst-class:: classref-item-separator
  817. ----
  818. .. _class_Image_method_save_exr_to_buffer:
  819. .. rst-class:: classref-method
  820. :ref:`PackedByteArray<class_PackedByteArray>` **save_exr_to_buffer** **(** :ref:`bool<class_bool>` grayscale=false **)** |const|
  821. 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.
  822. \ **Note:** The TinyEXR module is disabled in non-editor builds, which means :ref:`save_exr<class_Image_method_save_exr>` will return an empty byte array when it is called from an exported project.
  823. .. rst-class:: classref-item-separator
  824. ----
  825. .. _class_Image_method_save_jpg:
  826. .. rst-class:: classref-method
  827. :ref:`Error<enum_@GlobalScope_Error>` **save_jpg** **(** :ref:`String<class_String>` path, :ref:`float<class_float>` quality=0.75 **)** |const|
  828. 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.
  829. \ **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.
  830. .. rst-class:: classref-item-separator
  831. ----
  832. .. _class_Image_method_save_jpg_to_buffer:
  833. .. rst-class:: classref-method
  834. :ref:`PackedByteArray<class_PackedByteArray>` **save_jpg_to_buffer** **(** :ref:`float<class_float>` quality=0.75 **)** |const|
  835. 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.
  836. \ **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.
  837. .. rst-class:: classref-item-separator
  838. ----
  839. .. _class_Image_method_save_png:
  840. .. rst-class:: classref-method
  841. :ref:`Error<enum_@GlobalScope_Error>` **save_png** **(** :ref:`String<class_String>` path **)** |const|
  842. Saves the image as a PNG file to the file at ``path``.
  843. .. rst-class:: classref-item-separator
  844. ----
  845. .. _class_Image_method_save_png_to_buffer:
  846. .. rst-class:: classref-method
  847. :ref:`PackedByteArray<class_PackedByteArray>` **save_png_to_buffer** **(** **)** |const|
  848. Saves the image as a PNG file to a byte array.
  849. .. rst-class:: classref-item-separator
  850. ----
  851. .. _class_Image_method_save_webp:
  852. .. rst-class:: classref-method
  853. :ref:`Error<enum_@GlobalScope_Error>` **save_webp** **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` lossy=false, :ref:`float<class_float>` quality=0.75 **)** |const|
  854. 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).
  855. .. rst-class:: classref-item-separator
  856. ----
  857. .. _class_Image_method_save_webp_to_buffer:
  858. .. rst-class:: classref-method
  859. :ref:`PackedByteArray<class_PackedByteArray>` **save_webp_to_buffer** **(** :ref:`bool<class_bool>` lossy=false, :ref:`float<class_float>` quality=0.75 **)** |const|
  860. 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).
  861. .. rst-class:: classref-item-separator
  862. ----
  863. .. _class_Image_method_set_data:
  864. .. rst-class:: classref-method
  865. void **set_data** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format, :ref:`PackedByteArray<class_PackedByteArray>` data **)**
  866. Overwrites data of an existing **Image**. Non-static equivalent of :ref:`create_from_data<class_Image_method_create_from_data>`.
  867. .. rst-class:: classref-item-separator
  868. ----
  869. .. _class_Image_method_set_pixel:
  870. .. rst-class:: classref-method
  871. void **set_pixel** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`Color<class_Color>` color **)**
  872. Sets the :ref:`Color<class_Color>` of the pixel at ``(x, y)`` to ``color``.
  873. \ **Example:**\
  874. .. tabs::
  875. .. code-tab:: gdscript
  876. var img_width = 10
  877. var img_height = 5
  878. var img = Image.new()
  879. img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
  880. img.set_pixel(1, 2, Color.RED) # Sets the color at (1, 2) to red.
  881. .. code-tab:: csharp
  882. int imgWidth = 10;
  883. int imgHeight = 5;
  884. var img = new Image();
  885. img.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
  886. img.SetPixel(1, 2, Colors.Red); // Sets the color at (1, 2) to red.
  887. This is the same as :ref:`set_pixelv<class_Image_method_set_pixelv>`, but with a two integer arguments instead of a :ref:`Vector2i<class_Vector2i>` argument.
  888. .. rst-class:: classref-item-separator
  889. ----
  890. .. _class_Image_method_set_pixelv:
  891. .. rst-class:: classref-method
  892. void **set_pixelv** **(** :ref:`Vector2i<class_Vector2i>` point, :ref:`Color<class_Color>` color **)**
  893. Sets the :ref:`Color<class_Color>` of the pixel at ``point`` to ``color``.
  894. \ **Example:**\
  895. .. tabs::
  896. .. code-tab:: gdscript
  897. var img_width = 10
  898. var img_height = 5
  899. var img = Image.new()
  900. img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
  901. img.set_pixelv(Vector2i(1, 2), Color.RED) # Sets the color at (1, 2) to red.
  902. .. code-tab:: csharp
  903. int imgWidth = 10;
  904. int imgHeight = 5;
  905. var img = new Image();
  906. img.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
  907. img.SetPixelv(new Vector2I(1, 2), Colors.Red); // Sets the color at (1, 2) to red.
  908. This is the same as :ref:`set_pixel<class_Image_method_set_pixel>`, but with a :ref:`Vector2i<class_Vector2i>` argument instead of two integer arguments.
  909. .. rst-class:: classref-item-separator
  910. ----
  911. .. _class_Image_method_shrink_x2:
  912. .. rst-class:: classref-method
  913. void **shrink_x2** **(** **)**
  914. Shrinks the image by a factor of 2.
  915. .. rst-class:: classref-item-separator
  916. ----
  917. .. _class_Image_method_srgb_to_linear:
  918. .. rst-class:: classref-method
  919. void **srgb_to_linear** **(** **)**
  920. Converts the raw data from the sRGB colorspace to a linear scale.
  921. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  922. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  923. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  924. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  925. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  926. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`