def _rotate_by_jpegtran(cls, image_phys_path, rotated_image): image_phys_path_rotated = image_phys_path + "_rotated" rotation_angle = str(cls.ROTATIONS_MAP[rotated_image.orientation]) logger.info("rotating image ({} degrees): {}".format(rotation_angle, image_phys_path)) # call lossless rotation subprocess.call( ['jpegtran', '-rotate', rotation_angle, '-outfile', image_phys_path_rotated, image_phys_path]) os.rename(image_phys_path_rotated, image_phys_path) # invoke thumbnail recreation Thumbnailer.create_miniatures(image_phys_path, force_recreate=True) # reset image orientation rotated_image.orientation = 'up' # recalculate aspect radio, modification_time rotated_image.aspect_ratio = Indexer.get_image_aspect_ratio(image_phys_path) rotated_image.modification_time = get_mtime_datetime(image_phys_path) rotated_image.save()