Set Saving Settings in an Image File¶
Problem¶
You want to set the compression, the quality and the tileSize in an image file.
Solution¶
import Draft
# Read an image from file
image = Draft.Image.ReadFromFile( '//path/to/in.exr' )
# Create a Draft.ImageInfo object and set compression, quality and tileSize
imageInfo = Draft.ImageInfo()
imageInfo.compression = 'dwaa'
imageInfo.quality = 80
imageInfo.tileSize = ( 64, 64 )
# Write the image back to file
image.WriteToFile( '//path/to/out.exr', imageInfo )
Discussion¶
In the above example, we decided to set the compression, the quality and the tileSize properties in an EXR image file. The lines:
imageInfo = Draft.ImageInfo()
imageInfo.compression = 'dwaa'
imageInfo.quality = 80
imageInfo.tileSize = ( 64, 64 )
creates a ImageInfo
object and populates its fields with the desired valid values. For valid values, consult the section ImageInfo in Concepts.
Once you have created a valid ImageInfo
object, you add the imageInfo as an additional parameter when the file is written to file:
image.WriteToFile( '//path/to/out.exr', imageInfo )
Alternatively, you can retrieve the saving settings in an image file using:
imageInfo = Draft.ImageInfo()
image = Draft.Image.ReadFromFile( '//path/to/in.exr', imageInfo )
compression = imageInfo.compression
quality = imageInfo.quality
tileSize = imageInfo.tileSize
See Also¶
For more information on the import statement, ReadFromFile()
and WriteToFile()
, see the Creating an Image section of this Cookbook.
You can consult the section ImageInfo in Concepts.