更新 HEICFile 类以支持新特性,添加图像尺寸获取功能,重构解析逻辑,增强代码可读性和健壮性

This commit is contained in:
Nymiro
2025-10-20 12:47:47 +13:00
parent 812318c50c
commit 7715acd18b
10 changed files with 204 additions and 69 deletions
+11 -5
View File
@@ -1,22 +1,28 @@
# In main.py
# pyheic_struct/main.py
from heic_file import HEICFile
def analyze_file(filename: str):
print(f"--- Analyzing {filename} ---")
heic_file = HEICFile(filename)
# List all available items in the file
heic_file.list_items()
# Get the ID of the primary image
primary_id = heic_file.get_primary_item_id()
if primary_id:
print(f"\nThe primary item ID is: {primary_id}")
print(f"The primary item ID is: {primary_id}")
# --- Use our new feature! ---
size = heic_file.get_image_size(primary_id)
if size:
print(f"Primary image dimensions (WxH): {size[0]} x {size[1]}")
print("\n" + "="*40 + "\n")
def main():
analyze_file('apple.heic')
analyze_file('apple.HEIC')
analyze_file('samsung.heic')
if __name__ == "__main__":