Commit 006d6458 authored by markus's avatar markus

Convert png >3MB to jpg

parent 4214196b
......@@ -8,6 +8,7 @@ verify_ssl = true
[packages]
tweepy = "*"
ffmpeg-python = "*"
pillow = "*"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "02859eb90ebc7d5cfbf1c5a9a2336ab606f1a6097691ba95830790a2c63b36e0"
"sha256": "0024b4bc5a8a7b27ffbbfa23636a42694c7d5f2a53b09148a0e19e024ca89b3c"
},
"pipfile-spec": 6,
"requires": {
......@@ -58,6 +58,55 @@
],
"version": "==3.1.0"
},
"pillow": {
"hashes": [
"sha256:0804f77cb1e9b6dbd37601cee11283bba39a8d44b9ddb053400c58e0c0d7d9de",
"sha256:0ab7c5b5d04691bcbd570658667dd1e21ca311c62dcfd315ad2255b1cd37f64f",
"sha256:0b3e6cf3ea1f8cecd625f1420b931c83ce74f00c29a0ff1ce4385f99900ac7c4",
"sha256:0c6ce6ae03a50b0306a683696234b8bc88c5b292d4181ae365b89bd90250ab08",
"sha256:1454ee7297a81c8308ad61d74c849486efa1badc543453c4b90db0bf99decc1c",
"sha256:23efd7f83f2ad6036e2b9ef27a46df7e333de1ad9087d341d87e12225d0142b2",
"sha256:365c06a45712cd723ec16fa4ceb32ce46ad201eb7bbf6d3c16b063c72b61a3ed",
"sha256:38301fbc0af865baa4752ddae1bb3cbb24b3d8f221bf2850aad96b243306fa03",
"sha256:3aef1af1a91798536bbab35d70d35750bd2884f0832c88aeb2499aa2d1ed4992",
"sha256:3c86051d41d1c8b28b9dde08ac93e73aa842991995b12771b0af28da49086bbf",
"sha256:3fe0ab49537d9330c9bba7f16a5f8b02da615b5c809cdf7124f356a0f182eccd",
"sha256:406c856e0f6fc330322a319457d9ff6162834050cda2cf1eaaaea4b771d01914",
"sha256:45a619d5c1915957449264c81c008934452e3fd3604e36809212300b2a4dab68",
"sha256:49f90f147883a0c3778fd29d3eb169d56416f25758d0f66775db9184debc8010",
"sha256:504f5334bfd974490a86fef3e3b494cd3c332a8a680d2f258ca03388b40ae230",
"sha256:51fe9cfcd32c849c6f36ca293648f279fc5097ca8dd6e518b10df3a6a9a13431",
"sha256:571b5a758baf1cb6a04233fb23d6cf1ca60b31f9f641b1700bfaab1194020555",
"sha256:5ac381e8b1259925287ccc5a87d9cf6322a2dc88ae28a97fe3e196385288413f",
"sha256:6052a9e9af4a9a2cc01da4bbee81d42d33feca2bde247c4916d8274b12bb31a4",
"sha256:6153db744a743c0c8c91b8e3b9d40e0b13a5d31dbf8a12748c6d9bfd3ddc01ad",
"sha256:6fd63afd14a16f5d6b408f623cc2142917a1f92855f0df997e09a49f0341be8a",
"sha256:70acbcaba2a638923c2d337e0edea210505708d7859b87c2bd81e8f9902ae826",
"sha256:70b1594d56ed32d56ed21a7fbb2a5c6fd7446cdb7b21e749c9791eac3a64d9e4",
"sha256:76638865c83b1bb33bcac2a61ce4d13c17dba2204969dedb9ab60ef62bede686",
"sha256:7b2ec162c87fc496aa568258ac88631a2ce0acfe681a9af40842fc55deaedc99",
"sha256:7b403ea842b70c4fa0a4969a5d8d86e932c941095b7cda077ea68f7b98ead30b",
"sha256:7be698a28175eae5354da94f5f3dc787d5efae6aca7ad1f286a781afde6a27dd",
"sha256:7cee2cef07c8d76894ebefc54e4bb707dfc7f258ad155bd61d87f6cd487a70ff",
"sha256:7d16d4498f8b374fc625c4037742fbdd7f9ac383fd50b06f4df00c81ef60e829",
"sha256:82840783842b27933cc6388800cb547f31caf436f7e23384d456bdf5fc8dfe49",
"sha256:8755e600b33f4e8c76a590b42acc35d24f4dc801a5868519ce569b9462d77598",
"sha256:9159285ab4030c6f85e001468cb5886de05e6bd9304e9e7d46b983f7d2fad0cc",
"sha256:b50bc1780681b127e28f0075dfb81d6135c3a293e0c1d0211133c75e2179b6c0",
"sha256:b5aa19f1da16b4f5e47b6930053f08cba77ceccaed68748061b0ec24860e510c",
"sha256:bd0582f831ad5bcad6ca001deba4568573a4675437db17c4031939156ff339fa",
"sha256:cdd53acd3afb9878a2289a1b55807871f9877c81174ae0d3763e52f907131d25",
"sha256:cfd40d8a4b59f7567620410f966bb1f32dc555b2b19f82a91b147fac296f645c",
"sha256:e150c5aed6e67321edc6893faa6701581ca2d393472f39142a00e551bcd249a5",
"sha256:e3ae410089de680e8f84c68b755b42bc42c0ceb8c03dbea88a5099747091d38e",
"sha256:e403b37c6a253ebca5d0f2e5624643997aaae529dc96299162418ef54e29eb70",
"sha256:e9046e559c299b395b39ac7dbf16005308821c2f24a63cae2ab173bd6aa11616",
"sha256:ef6be704ae2bc8ad0ebc5cb850ee9139493b0fc4e81abcc240fb392a63ebc808",
"sha256:f8dc19d92896558f9c4317ee365729ead9d7bbcf2052a9a19a3ef17abbb8ac5b"
],
"index": "pypi",
"version": "==6.1.0"
},
"pysocks": {
"hashes": [
"sha256:15d38914b60dbcb231d276f64882a20435c049450160e953ca7d313d1405f16f",
......
......@@ -22,6 +22,19 @@ import ffmpeg
import tempfile
import subprocess
import shutil
from PIL import Image
def execute_function_on_tempfile(func, file_content, suffix, *args, **kwargs):
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(file_content)
dirpath = tempfile.mkdtemp()
result_file = f"{dirpath}/result{suffix}"
func(tmp.name, result_file, *args, **kwargs)
with open(result_file, "rb") as tmp_result:
result = tmp_result.read()
shutil.rmtree(dirpath)
return result
def generate_wav(audio):
with tempfile.NamedTemporaryFile() as tmp_ogg:
......@@ -34,6 +47,19 @@ def generate_wav(audio):
shutil.rmtree(dirpath)
return wav
def scale_image(input_file, result_file, factor):
# FIXME: Remove or test
img = Image.open(input_file)
img = img.resize((int(img.width * factor), int(img.height * factor)), Image.ANTIALIAS)
img.save(result_file)
def convert_png_to_jpg(input_file, result_file):
im = Image.open(input_file)
rgb_im = im.convert('RGB')
rgb_im.save(result_file)
def process_noaa_image(wav, northbound = False):
with tempfile.NamedTemporaryFile() as tmp_wav:
tmp_wav.write(wav)
......@@ -58,7 +84,10 @@ def process_observation(observation, observation_data):
logger.info("Done generating wav")
logger.info("Generating colorized image")
colorized_image = process_noaa_image(wav, northbound)
logger.info("Done colorizing image")
if len(colorized_image) > 3*10**6:
logging.info(f"resizing image with size {len(colorized_image)}")
colorized_image = execute_function_on_tempfile(convert_png_to_jpg, colorized_image, ".jpg")
logger.info(f"Done colorizing image: {len(colorized_image)} Byte")
twitter_client.handle_observation(observation, observation_data, waterfall_image, [colorized_image])
else:
twitter_client.handle_observation(observation, observation_data, waterfall_image, data_images)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment