Skip to content

Commit

Permalink
Add copynone option to crop_multiple #68 (#69)
Browse files Browse the repository at this point in the history
* Add copynone option to crop_multiple (#68)
Allows to avoid copy of EXIF data when generating multiples crops.
---------
Co-authored-by: Christian Quest <github@cquest.org>
  • Loading branch information
lilohuang authored Apr 2, 2023
1 parent 3ad63af commit db62383
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2022 Lilo Huang <kuso.cc@gmail.com>
Copyright (c) 2018-2023 Lilo Huang <kuso.cc@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages
setup(
name='PyTurboJPEG',
version='1.7.0',
version='1.7.1',
description='A Python wrapper of libjpeg-turbo for decoding and encoding JPEG image.',
author='Lilo Huang',
author_email='kuso.cc@gmail.com',
Expand Down
12 changes: 7 additions & 5 deletions turbojpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# PyTurboJPEG - A Python wrapper of libjpeg-turbo for decoding and encoding JPEG image.
#
# Copyright (c) 2018-2022, Lilo Huang. All rights reserved.
# Copyright (c) 2018-2023, Lilo Huang. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,7 +23,7 @@
# SOFTWARE.

__author__ = 'Lilo Huang <kuso.cc@gmail.com>'
__version__ = '1.7.0'
__version__ = '1.7.1'

from ctypes import *
from ctypes.util import find_library
Expand Down Expand Up @@ -587,7 +587,7 @@ def crop(self, jpeg_buf, x, y, w, h, preserve=False, gray=False):
finally:
self.__destroy(handle)

def crop_multiple(self, jpeg_buf, crop_parameters, background_luminance=1.0, gray=False):
def crop_multiple(self, jpeg_buf, crop_parameters, background_luminance=1.0, gray=False, copynone=False):
"""Lossless crop and/or extension operations on jpeg image.
Crop origin(s) needs be divisable by the MCU block size and inside
the input image, or OSError: Invalid crop request is raised.
Expand All @@ -604,6 +604,8 @@ def crop_multiple(self, jpeg_buf, crop_parameters, background_luminance=1.0, gra
Default to 1, resulting in white background.
gray: bool
Produce greyscale output
copynone: bool
True = do not copy EXIF data (False by default)
Returns
----------
Expand Down Expand Up @@ -659,15 +661,15 @@ def crop_multiple(self, jpeg_buf, crop_parameters, background_luminance=1.0, gra
crop_transforms[i] = TransformStruct(
crop_region,
TJXOP_NONE,
TJXOPT_PERFECT | TJXOPT_CROP | (gray and TJXOPT_GRAY),
TJXOPT_PERFECT | TJXOPT_CROP | (gray and TJXOPT_GRAY) | (copynone and TJXOPT_COPYNONE),
pointer(callback_data),
callback
)
else:
crop_transforms[i] = TransformStruct(
crop_region,
TJXOP_NONE,
TJXOPT_PERFECT | TJXOPT_CROP | (gray and TJXOPT_GRAY)
TJXOPT_PERFECT | TJXOPT_CROP | (gray and TJXOPT_GRAY) | (copynone and TJXOPT_COPYNONE)
)

# Pointers to output image buffers and buffer size
Expand Down

0 comments on commit db62383

Please sign in to comment.