Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
If the specified format *fformat* is not know to satpy (and PIL), we
will try to import module *fformat* and call the method `fformat.save`.
.. _geotiff: http://trac.osgeo.org/geotiff/
"""
file_tuple = os.path.splitext(filename)
fformat = fformat or file_tuple[1][1:]
if fformat.lower() in ('tif', 'tiff'):
return self.geotiff_save(filename, compression, tags,
gdal_options, blocksize, **kwargs)
try:
# Let image.pil_save it ?
Image.save(self, filename, compression, fformat=fformat)
except UnknownImageFormat:
# No ... last resort, try to import an external module.
logger.info("Importing image writer module '%s'" % fformat)
try:
saver = __import__(fformat, globals(), locals(), ['save'])
except ImportError:
raise UnknownImageFormat(
"Unknown image format '%s'" % fformat)
saver.save(self, filename, **kwargs)
writer_options[write_opts.WR_OPT_BLOCKSIZE] = blocksize
if writer_options.get(write_opts.WR_OPT_NBITS, None):
tags['NBITS'] = writer_options[write_opts.WR_OPT_NBITS]
elif tags.get('NBITS') is not None:
writer_options[write_opts.WR_OPT_NBITS] = tags.get('NBITS')
if fformat.lower() in ('tif', 'tiff'):
kwargs = kwargs or {}
kwargs['writer_options'] = writer_options
return self.geotiff_save(filename, compression, tags,
gdal_options, blocksize,
**kwargs)
try:
# Let image.pil_save it ?
Image.save(self, filename, compression, fformat=fformat)
except UnknownImageFormat:
# No ... last resort, try to import an external module.
logger.info("Importing image writer module '%s'" % fformat)
try:
saver = __import__(fformat, globals(), locals(), ['save'])
except ImportError:
raise UnknownImageFormat(
"Unknown image format '%s'" % fformat)
kwargs = kwargs or {}
kwargs['writer_options'] = writer_options
saver.save(self, filename, **kwargs)