Skip to content

Commit

Permalink
regenrate thumbnail only if parts have been blurred
Browse files Browse the repository at this point in the history
  • Loading branch information
cquest committed Jul 16, 2023
1 parent 58da3e0 commit 8268a6d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/blur/blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def blurPicture(picture, keep):
# get MCU maximum size (2^n) = 8 or 16 pixels subsamplings
hblock, vblock, sample = [(3, 3 ,'1x1'), (4, 3, '2x1'), (4, 4, '2x2'), (4, 4, '2x2'), (3, 4, '1x2')][jpeg_subsample]

blurred = False
for r in range(len(result)):
for b in range(len(result[r].boxes)):
obj = result[r].boxes[b]
Expand Down Expand Up @@ -116,6 +117,7 @@ def blurPicture(picture, keep):
for c in range(len(crops)):
if info[c]['class'] == 'sign':
continue
blurred = True
crop = open(tmpcrop,'wb')
crop.write(crops[c])
crop.close()
Expand Down Expand Up @@ -170,8 +172,12 @@ def blurPicture(picture, keep):
os.utime(dirname+cropname, (daytime, daytime))
info = { 'info': info, 'salt': salt }

# regenerate EXIF thumbnail
subprocess.run('exiftran -g -i %s' % tmp, shell=True)
if blurred:
# regenerate EXIF thumbnail
before_thumb = os.path.getsize(tmp)
subprocess.run('exiftran -g -o %s %s' % (tmp+'_tmp', tmp), shell=True)
os.replace(tmp+'_tmp', tmp)
print("after thumbnail", os.path.getsize(tmp), (100*(os.path.getsize(tmp)-before_thumb)/before_thumb))

# return result (original image if no blur needed)
with open(tmp, 'rb') as jpg:
Expand Down

0 comments on commit 8268a6d

Please sign in to comment.