<gh_stars>0
import appex
import photos
import os
import piexif
from PIL import Image

def main():
	
	"""
	Script for iOS share extensions in Photos app to remove EXIF data from image when shared. Original image is preserved. Image with no EXIF is saved as JPEG to camera roll with creation date and time as filename.
	
	Requires piexif. Add piexif to the site_packages_3 folder or use stash to use pip
	"""
	
	if not appex.is_running_extension():
		print("This extension is designed to work with iOS share functionality, select and share photos from the Photos app")
	else:
		img = appex.get_image(image_type="pil")
		
	if img:
		
		if "exif" in img.info:
			
			exif_dict = piexif.load(img.info["exif"])
			
			if piexif.ImageIFD.Orientation in exif_dict["0th"]:
				orientation = exif_dict["0th"][piexif.ImageIFD.Orientation]
				
			if piexif.ExifIFD.DateTimeOriginal in exif_dict["Exif"]:
				date_time = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal]
				
			path = date_time.decode("utf-8").replace(' ', '')
			path = path.replace(':', '')
			path = f"{path}.jpg"
			
		else:
			path = "web_image.jpg"
			print('No EXIF data')
			
		if orientation == 2:
			img = img.transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 3:
			img = img.rotate(180)
		elif orientation == 4:
			img = img.rotate(180).transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 5:
			img = img.rotate(-90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 6:
			img = img.rotate(-90, expand=True)
		elif orientation == 7:
			img = img.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 8:
			img = img.rotate(90, expand=True)
			
		img.save(path, quality = 95)
		photos.create_image_asset(path)
		os.remove(path)

	else:
		print('No input image found')

if __name__ == '__main__':
	main()

import appex
import photos
import os
import piexif
from PIL import Image

def main():
	
	"""
	Script for iOS share extensions in Photos app to remove EXIF data from image when shared. Original image is preserved. Image with no EXIF is saved as JPEG to camera roll with creation date and time as filename.
	
	Requires piexif. Add piexif to the site_packages_3 folder or use stash to use pip
	"""
	
	if not appex.is_running_extension():
		print("This extension is designed to work with iOS share functionality, select and share photos from the Photos app")
	else:
		img = appex.get_image(image_type="pil")
		
	if img:
		
		if "exif" in img.info:
			
			exif_dict = piexif.load(img.info["exif"])
			
			if piexif.ImageIFD.Orientation in exif_dict["0th"]:
				orientation = exif_dict["0th"][piexif.ImageIFD.Orientation]
				
			if piexif.ExifIFD.DateTimeOriginal in exif_dict["Exif"]:
				date_time = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal]
				
			path = date_time.decode("utf-8").replace(' ', '')
			path = path.replace(':', '')
			path = f"{path}.jpg"
			
		else:
			path = "web_image.jpg"
			print('No EXIF data')
			
		if orientation == 2:
			img = img.transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 3:
			img = img.rotate(180)
		elif orientation == 4:
			img = img.rotate(180).transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 5:
			img = img.rotate(-90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 6:
			img = img.rotate(-90, expand=True)
		elif orientation == 7:
			img = img.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
		elif orientation == 8:
			img = img.rotate(90, expand=True)
			
		img.save(path, quality = 95)
		photos.create_image_asset(path)
		os.remove(path)

	else:
		print('No input image found')

if __name__ == '__main__':
	main()
Script for iOS share extensions in Photos app to remove EXIF data from image when shared. Original image is preserved. Image with no EXIF is saved as JPEG to camera roll with creation date and time as filename. 	 	Requires piexif. Add piexif to the site_packages_3 folder or use stash to use pip