Copy icc_profile from source image.

This commit is contained in:
voussoir 2023-03-19 11:21:33 -07:00
parent ce0b1ae0c4
commit 9a2c6abec7
4 changed files with 8 additions and 4 deletions

View file

@ -7,6 +7,7 @@ from voussoirkit import pipeable
def crop(file, crops, *, inplace=False, quality=100):
image = PIL.Image.open(file.absolute_path)
icc_profile = image.info.get('icc_profile')
if len(crops) == 2:
crops.extend(image.size)
@ -27,7 +28,7 @@ def crop(file, crops, *, inplace=False, quality=100):
newname = file.parent.with_child(base + suffix).add_extension(file.extension)
pipeable.stdout(newname.absolute_path)
image.save(newname.absolute_path, exif=image.getexif(), quality=quality)
image.save(newname.absolute_path, exif=image.getexif(), quality=quality, icc_profile=icc_profile)
def crop_argparse(args):
patterns = pipeable.input(args.pattern, skip_blank=True, strip=True)

View file

@ -54,6 +54,7 @@ def rejpg_argparse(args):
for filename in files:
log.info('Processing %s.', filename)
image = PIL.Image.open(filename)
icc_profile = image.info.get('icc_profile')
(image, exif) = imagetools.rotate_by_exif(image)
@ -62,7 +63,7 @@ def rejpg_argparse(args):
bytesio = compress_to_filesize(image, target_size, exif=exif)
else:
bytesio = io.BytesIO()
image.save(bytesio, format='jpeg', exif=exif, quality=args.quality)
image.save(bytesio, format='jpeg', exif=exif, quality=args.quality, icc_profile=icc_profile)
bytesio.seek(0)
new_bytes = bytesio.read()

View file

@ -32,6 +32,7 @@ def resize(
file = pathclass.Path(filename)
image = PIL.Image.open(file.absolute_path)
icc_profile = image.info.get('icc_profile')
(image, exif) = imagetools.rotate_by_exif(image)
(image_width, image_height) = image.size
@ -110,7 +111,7 @@ def resize(
if output_file.extension == '.jpg':
image = image.convert('RGB')
image.save(output_file.absolute_path, exif=exif, quality=quality)
image.save(output_file.absolute_path, exif=exif, quality=quality, icc_profile=icc_profile)
return output_file
def resize_argparse(args):

View file

@ -19,6 +19,7 @@ def rotate_argparse(args):
for file in files:
image = PIL.Image.open(file.absolute_path)
icc_profile = image.info.get('icc_profile')
if args.exif:
(new_image, exif) = imagetools.rotate_by_exif(image)
@ -43,7 +44,7 @@ def rotate_argparse(args):
newname = file.parent.with_child(newname).add_extension(file.extension)
pipeable.stdout(newname.absolute_path)
image.save(newname.absolute_path, exif=exif, quality=args.quality)
image.save(newname.absolute_path, exif=exif, quality=args.quality, icc_profile=icc_profile)
@vlogging.main_decorator
def main(argv):