Encodes the ImageData and optionally writes it to the [[love.filesystem|save directory]].

== Function ==
{{newin|[[0.10.0]]|100|type=variant}}
=== Synopsis ===
<source lang="lua">
filedata = ImageData:encode( format, filename )
</source>
=== Arguments ===
{{param|ImageFormat|format|The format to encode the image as.}}
{{param|string|filename (nil)|The filename to write the file to. If nil, no file will be written but the FileData will still be returned.}}
=== Returns ===
{{param|FileData|filedata|The encoded image as a new FileData object.}}

== Function ==
{{newinoldin|[[0.8.0]]|080|[[0.10.0]]|100|type=variant}}
=== Synopsis ===
<source lang="lua">
ImageData:encode( outFile )
</source>
=== Arguments ===
{{param|string|outFile|Name of a file to write encoded data to. The format will be automatically deduced from the file extension.}}
=== Returns ===
Nothing.

== Function ==
{{newinoldin|[[0.8.0]]|080|[[0.10.0]]|100|type=variant}}
=== Synopsis ===
<source lang="lua">
ImageData:encode( outFile, format )
</source>
=== Arguments ===
{{param|string|outFile|Name of a file to write encoded data to.}}
{{param|ImageFormat|format|The format to encode the image in.}}
=== Returns ===
Nothing.

== Function ==
{{oldin|[[0.8.0]]|080|type=variant}}
=== Synopsis ===
<source lang="lua">
data = ImageData:encode( format )
</source>
=== Arguments ===
{{param|ImageFormat|format|The format to encode the image in.}}
=== Returns ===
{{param|Data|data|The encoded image data.}}

== See Also ==
* [[parent::ImageData]]
[[Category:Functions]]
{{#set:Description=Encodes ImageData.}}
{{#set:Since=000}}

== User Notes ==
* If you want the file to have an extension when saved add it in the file name. Example : <source lang="lua">image:encode("png","aPngImage.png")</source>

== Other Languages ==
{{i18n|ImageData:encode}}