generated from tomchen/example_pypi_package
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
__version__ = "0.9.0" | ||
__version__ = "0.9.5" | ||
|
||
from .heic2png import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from fire import Fire | ||
from pillow_heif import register_heif_opener | ||
|
||
from .heic2png import HEIC2PNG | ||
|
||
def main(input_path:str, output_path:str=None): | ||
print(f'----- Input file path is `{input_path}`') | ||
if output_path: | ||
print(f'----- Set the output path is `{output_path}`') | ||
try: | ||
heic_img = HEIC2PNG(input_path) | ||
print(f'----- Processing...') | ||
output_path = heic_img.save(output_path) | ||
print(f'----- Output file path is `{output_path}`') | ||
except FileExistsError: | ||
print('----- File has been already existed!') | ||
except ValueError: | ||
print('----- You need to check the format of image!') | ||
print('Input must be `.heic` and output must be `.png`.') | ||
except Exception as e: | ||
print(f'----- Error with {e}') | ||
print('----- Please report this issue!') | ||
|
||
register_heif_opener() | ||
Fire(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
from pathlib import Path | ||
|
||
from PIL import Image | ||
|
||
from pillow_heif import register_heif_opener | ||
register_heif_opener() | ||
|
||
class HEIC2PNG: | ||
def __init__(self, image_file_path:str): | ||
self.__opener = register_heif_opener() | ||
self.image_file_path = Path(image_file_path) | ||
if self.image_file_path.suffix.lower() != '.heic': | ||
raise ValueError | ||
|
||
self.image = Image.open(self.image_file_path) | ||
|
||
def save(self, output_image_file_path=None, extension='.png'): | ||
def save(self, output_image_file_path=None, extension='.png') -> Path: | ||
if output_image_file_path: | ||
output_path = Path(output_image_file_path) | ||
if output_path.suffix.lower() != extension: | ||
raise ValueError | ||
else: | ||
output_path = self.image_file_path.with_name(f"{self.image_file_path.stem}{extension}") | ||
if output_path.exists(): | ||
raise FileExistsError | ||
self.image.save(output_image_file_path) | ||
self.image.save(output_path) | ||
return output_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters