Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

依赖包升级和一些逻辑修复 #69

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ layout:
color: '#757575'
is_bold: false
name: Datetime
value: Photo by NONE
right_top:
color: '#212121'
is_bold: true
Expand Down Expand Up @@ -85,6 +84,9 @@ logo:
ricoh:
id: RICOH
path: ./logos/ricoh.png
samsung:
id: SAMSUNG
path: ./logos/samsung.png
sony:
id: SONY
path: ./logos/sony.png
5 changes: 3 additions & 2 deletions entity/image_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_focal_length(exif):


class ImageContainer(object):
def __init__(self, path: Path):
def __init__(self, path: Path, use_equivalent_focal_length: bool = True):
self.path: Path = path
self.target_path: Path | None = None
self.img: Image.Image = Image.open(path)
Expand All @@ -90,7 +90,7 @@ def __init__(self, path: Path):
self.iso: str = extract_attribute(self.exif, ExifId.ISO.value, default_value=DEFAULT_VALUE)

# 是否使用等效焦距
self.use_equivalent_focal_length: bool = False
self.use_equivalent_focal_length: bool = use_equivalent_focal_length

# 修正图像方向
self.orientation = self.exif[ExifId.ORIENTATION.value] if ExifId.ORIENTATION.value in self.exif else 1
Expand All @@ -113,6 +113,7 @@ def __init__(self, path: Path):
self.watermark_img = None

self._param_dict[MODEL_VALUE] = self.model
# 此处需要获取use_equivalent_focal_length属性,因此需要从config里面初始化
self._param_dict[PARAM_VALUE] = self.get_param_str()
self._param_dict[MAKE_VALUE] = self.make
self._param_dict[DATETIME_VALUE] = self._parse_datetime()
Expand Down
21 changes: 10 additions & 11 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# 下载文件
Invoke-WebRequest -Uri https://exiftool.org/Image-ExifTool-12.60.tar.gz -OutFile Image-ExifTool-12.60.tar.gz
# Download file
Invoke-WebRequest -Uri "https://exiftool.org/exiftool-12.69.zip" -OutFile exiftool.zip

# 创建目录
mkdir exiftool
# Create directory and extract the archive.
$null = New-Item -Path . -Name "exiftool" -ItemType "directory"
Expand-Archive -Path exiftool.zip -DestinationPath exiftool -Force

# 解压文件
Expand-Archive -Path Image-ExifTool-12.60.tar.gz -DestinationPath exiftool -Force
# Delete the archive
Remove-Item exiftool.zip
Rename-Item -Path ".\exiftool\exiftool(-k).exe" -NewName "exiftool.exe"

# 删除压缩包
Remove-Item Image-ExifTool-12.60.tar.gz

# 下载 python 依赖
pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# Install Python dependencies
python3 -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Binary file modified logos/apple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logos/samsung.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logos/samsung_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ def processing():

for source_path in tqdm(file_list):
# 打开图片
container = ImageContainer(source_path)

# 使用等效焦距
container.is_use_equivalent_focal_length(config.use_equivalent_focal_length())
# 等效焦距的处理在类初始化的时候进行,避免生成的图片显示参数焦距不一致
container = ImageContainer(source_path, config.use_equivalent_focal_length())

# 处理图片
try:
Expand All @@ -65,7 +63,7 @@ def processing():
raise e

# 保存图片
target_path = Path(config.get_output_dir(), encoding=ENCODING).joinpath(source_path.name)
target_path = Path(config.get_output_dir()).joinpath(source_path.name)

container.save(target_path, quality=config.get_quality())
container.close()
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pillow==9.3.0
pyyaml==6.0
tqdm~=4.64.1
pillow~=10.0.0
pyyaml~=6.0.1
tqdm~=4.66.1
python-dateutil~=2.8.2
requests~=2.31.0
requests~=2.31.0
12 changes: 7 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def resize_image_with_height(image, height, auto_close=True):
new_width = round(width * scale)

# 进行等比缩放
resized_image = image.resize((new_width, height), Image.ANTIALIAS)
resized_image = image.resize((new_width, height), Image.LANCZOS)

# 关闭图片对象
if auto_close:
Expand All @@ -247,7 +247,7 @@ def resize_image_with_width(image, width, auto_close=True):
new_height = round(height * scale)

# 进行等比缩放
resized_image = image.resize((width, new_height), Image.ANTIALIAS)
resized_image = image.resize((width, new_height), Image.LANCZOS)

# 关闭图片对象
if auto_close:
Expand Down Expand Up @@ -302,10 +302,12 @@ def text_to_image(content, font, bold_font, is_bold=False, fill='black') -> Imag
font = bold_font
if content == '':
content = ' '
text_width, text_height = font.getsize(content)
image = Image.new('RGBA', (text_width, text_height), color=TRANSPARENT)
# 新版本的Pillow删除了font.getsize()方法,改用font.font.getsize()功能一致
size, offset = font.font.getsize(content)
image = Image.new('RGBA', (size[0], size[1] + offset[1]), color=TRANSPARENT)
draw = ImageDraw.Draw(image)
draw.text((0, 0), content, fill=fill, font=font)
# 生成的字体图片位置贴着底边,上方的空白部分高度即为offset[1],此处将字体图片上移一半字体高度,使其居中
draw.text((0, -(offset[1] // 2)), content, fill=fill, font=font)
return image


Expand Down