class_image.rst 95 KB

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