class_image.rst 91 KB

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