72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
import os
|
|
from PIL import Image, ImageChops, ImageStat
|
|
|
|
def get_gimp_export_path():
|
|
# Path to GIMP's configuration file. This example assumes GIMP version 2.10.
|
|
# You need to adjust the path according to the GIMP version and user's file system.
|
|
gimp_config_file = os.path.expanduser("~/.config/GIMP/2.10/gimprc")
|
|
|
|
try:
|
|
# Open and read the configuration file
|
|
with open(gimp_config_file, 'r') as file:
|
|
for line in file:
|
|
# Search for the default export path setting
|
|
if "default-export-path" in line:
|
|
# Extract the current path from the line (assuming it's enclosed in quotes)
|
|
current_path = line.split('"')[1]
|
|
# Compare the current path with the expected path
|
|
return current_path
|
|
except FileNotFoundError:
|
|
# Handle the case where the configuration file is not found
|
|
print("GIMP configuration file not found")
|
|
return False
|
|
|
|
def increase_saturation(image1_path: str, image2_path: str) -> float:
|
|
def calculate_saturation(image):
|
|
# convert the image to HSV mode
|
|
hsv_image = image.convert("HSV")
|
|
|
|
saturation_channel = hsv_image.split()[1]
|
|
|
|
# calculate the mean saturation level
|
|
stat = ImageStat.Stat(saturation_channel)
|
|
mean_saturation = stat.mean[0]
|
|
|
|
return mean_saturation
|
|
|
|
image1 = Image.open(image1_path)
|
|
image2 = Image.open(image2_path)
|
|
|
|
# calculate the saturation level of each image
|
|
saturation1 = calculate_saturation(image1)
|
|
saturation2 = calculate_saturation(image2)
|
|
|
|
return 1 if saturation1 < saturation2 else 0
|
|
|
|
def decrease_brightness(image1_path: str, image2_path: str) -> float:
|
|
def calculate_brightness(image):
|
|
# Convert the image to grayscale mode
|
|
grayscale_image = image.convert("L")
|
|
|
|
# Get the image data
|
|
pixels = list(grayscale_image.getdata())
|
|
|
|
brightness = sum(pixels) / len(pixels)
|
|
return brightness
|
|
|
|
image1 = Image.open(image1_path)
|
|
image2 = Image.open(image2_path)
|
|
|
|
brightness1 = calculate_brightness(image1)
|
|
brightness2 = calculate_brightness(image2)
|
|
|
|
return 1 if brightness1 > brightness2 else 0
|
|
|
|
if __name__ == "__main__":
|
|
image1_path = "../Downloads/1.png"
|
|
image2_path = "../Downloads/edited_darker.png"
|
|
|
|
decrease_brightness(image1_path, image2_path)
|
|
|
|
increase_saturation(image1_path, image2_path)
|