Copy icc_profile from source image.
This commit is contained in:
parent
ce0b1ae0c4
commit
9a2c6abec7
4 changed files with 8 additions and 4 deletions
3
crop.py
3
crop.py
|
@ -7,6 +7,7 @@ from voussoirkit import pipeable
|
||||||
|
|
||||||
def crop(file, crops, *, inplace=False, quality=100):
|
def crop(file, crops, *, inplace=False, quality=100):
|
||||||
image = PIL.Image.open(file.absolute_path)
|
image = PIL.Image.open(file.absolute_path)
|
||||||
|
icc_profile = image.info.get('icc_profile')
|
||||||
if len(crops) == 2:
|
if len(crops) == 2:
|
||||||
crops.extend(image.size)
|
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)
|
newname = file.parent.with_child(base + suffix).add_extension(file.extension)
|
||||||
|
|
||||||
pipeable.stdout(newname.absolute_path)
|
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):
|
def crop_argparse(args):
|
||||||
patterns = pipeable.input(args.pattern, skip_blank=True, strip=True)
|
patterns = pipeable.input(args.pattern, skip_blank=True, strip=True)
|
||||||
|
|
3
rejpg.py
3
rejpg.py
|
@ -54,6 +54,7 @@ def rejpg_argparse(args):
|
||||||
for filename in files:
|
for filename in files:
|
||||||
log.info('Processing %s.', filename)
|
log.info('Processing %s.', filename)
|
||||||
image = PIL.Image.open(filename)
|
image = PIL.Image.open(filename)
|
||||||
|
icc_profile = image.info.get('icc_profile')
|
||||||
|
|
||||||
(image, exif) = imagetools.rotate_by_exif(image)
|
(image, exif) = imagetools.rotate_by_exif(image)
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ def rejpg_argparse(args):
|
||||||
bytesio = compress_to_filesize(image, target_size, exif=exif)
|
bytesio = compress_to_filesize(image, target_size, exif=exif)
|
||||||
else:
|
else:
|
||||||
bytesio = io.BytesIO()
|
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)
|
bytesio.seek(0)
|
||||||
new_bytes = bytesio.read()
|
new_bytes = bytesio.read()
|
||||||
|
|
|
@ -32,6 +32,7 @@ def resize(
|
||||||
|
|
||||||
file = pathclass.Path(filename)
|
file = pathclass.Path(filename)
|
||||||
image = PIL.Image.open(file.absolute_path)
|
image = PIL.Image.open(file.absolute_path)
|
||||||
|
icc_profile = image.info.get('icc_profile')
|
||||||
(image, exif) = imagetools.rotate_by_exif(image)
|
(image, exif) = imagetools.rotate_by_exif(image)
|
||||||
|
|
||||||
(image_width, image_height) = image.size
|
(image_width, image_height) = image.size
|
||||||
|
@ -110,7 +111,7 @@ def resize(
|
||||||
if output_file.extension == '.jpg':
|
if output_file.extension == '.jpg':
|
||||||
image = image.convert('RGB')
|
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
|
return output_file
|
||||||
|
|
||||||
def resize_argparse(args):
|
def resize_argparse(args):
|
||||||
|
|
|
@ -19,6 +19,7 @@ def rotate_argparse(args):
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
image = PIL.Image.open(file.absolute_path)
|
image = PIL.Image.open(file.absolute_path)
|
||||||
|
icc_profile = image.info.get('icc_profile')
|
||||||
|
|
||||||
if args.exif:
|
if args.exif:
|
||||||
(new_image, exif) = imagetools.rotate_by_exif(image)
|
(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)
|
newname = file.parent.with_child(newname).add_extension(file.extension)
|
||||||
|
|
||||||
pipeable.stdout(newname.absolute_path)
|
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
|
@vlogging.main_decorator
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
|
Loading…
Reference in a new issue