You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.4 KiB
Plaintext
61 lines
1.4 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "5fbf751c-841f-4089-8ef0-5267356a069b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from PIL import Image\n",
|
|
"import os\n",
|
|
"UPLOAD_FOLDER = os.path.join(os.getcwd(), 'static/uploads/annotation-compass/')\n",
|
|
"\n",
|
|
"def thumbnail(image):\n",
|
|
" try:\n",
|
|
" img = Image.open(image)\n",
|
|
" img.thumbnail((128,128))\n",
|
|
" name = image.rsplit('.', 1)[0]\n",
|
|
" ext = image.rsplit('.', 1)[1]\n",
|
|
" img.save(f'{name}_thumb.{ext}')\n",
|
|
" except IOError:\n",
|
|
" pass\n",
|
|
" \n",
|
|
"files = os.listdir(UPLOAD_FOLDER)\n",
|
|
"\n",
|
|
"for file in files:\n",
|
|
" thumbnail(os.path.join(UPLOAD_FOLDER, file))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b65ddab7-a74d-4c32-8f70-ab9e21388a55",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.7.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|