class_image.rst 98 KB

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