basic processing done
This commit is contained in:
BIN
image-converter/src/assets/100740-1471947265.jpg
Normal file
BIN
image-converter/src/assets/100740-1471947265.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 248 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 20 MiB After Width: | Height: | Size: 27 MiB |
BIN
image-converter/src/assets/foo.png
Normal file
BIN
image-converter/src/assets/foo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
@@ -2,5 +2,5 @@ from modules.raw_parser import (parse_raw_image)
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parse_raw_image("./assets/foo.CR2", 2000)
|
parse_raw_image("./src/assets/foo.CR2", 1900, "png")
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
import math
|
||||||
|
|
||||||
def parse_raw_image(src,target_width, target_height):
|
def parse_raw_image(src: str, max_size_px: int, target_extension: str):
|
||||||
rawImage = Image.open(src)
|
rawImage = Image.open(src)
|
||||||
# Use the PIL raw decoder to read the data.
|
|
||||||
# the 'F;16' informs the raw decoder that we are reading
|
if (rawImage.height > rawImage.width):
|
||||||
# a little endian, unsigned integer 16 bit data.
|
target_height = max_size_px
|
||||||
# img = Image.fromstring('L', imgSize, rawData, 'raw', 'F;16')
|
target_width = math.ceil(rawImage.width * max_size_px / rawImage.height)
|
||||||
rawImage.save("foo.png")
|
else:
|
||||||
|
target_width = max_size_px
|
||||||
|
target_height = math.ceil(rawImage.height * max_size_px / rawImage.width)
|
||||||
|
rawImage = rawImage.resize((target_width, target_height))
|
||||||
|
|
||||||
|
last_dot = src.rfind(".")
|
||||||
|
result_path = src[:last_dot]
|
||||||
|
rawImage.save(result_path + "." + target_extension)
|
||||||
|
|||||||
Reference in New Issue
Block a user