class_image.rst 92 KB

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