-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: init img convert & compress for gallery view #139
Conversation
- Add `pillow` dependency for image conversion and compression (by running `poetry add pillow`); - Create a new Django management commands in `download_imgs.py`. By running `python manage.py download_imgs`, it will: (1) download all original instrument images (one image for each instrument) from wikimedia urls; (2) convert original images to .png format and store them on UMIL server; (3) compress original images and store the smaller version as thumbnails on UMIL server; - Modify `import_instruments.py` command: replace the old image urls with current image path; - Add `thumbnail` field in `Instrument` model; - Update the `migrations/0001_initial.py` automatically by running `python manage.py makemigrations`; - In gallery view HTMLs, replace the old image url with current thumbnail url; Refs: #138
web-app/django/VIM/apps/instruments/management/commands/download_imgs.py
Show resolved
Hide resolved
web-app/django/VIM/apps/instruments/management/commands/download_imgs.py
Outdated
Show resolved
Hide resolved
web-app/django/VIM/apps/instruments/management/commands/download_imgs.py
Outdated
Show resolved
Hide resolved
web-app/django/VIM/apps/instruments/management/commands/download_imgs.py
Outdated
Show resolved
Hide resolved
web-app/django/VIM/apps/instruments/management/commands/download_imgs.py
Outdated
Show resolved
Hide resolved
web-app/django/VIM/apps/instruments/management/commands/download_imgs.py
Show resolved
Hide resolved
web-app/django/VIM/apps/instruments/management/commands/import_instruments.py
Outdated
Show resolved
Hide resolved
- Add `__init__.py` under `VIM/apps` directory to fix pylint error: `No name 'apps' in module 'VIM' Pylint(E0611:no-name-in-module)`; - Adjust importing order in all management commands; - In `download_imgs.py`: (1) remove class `ImageDownloader` and place all methods into `Command` class; (2) change constants into upper case; (3) add `timeout` for `requests.get`; (4) change general `Exception` into specific exception types such as `requests.RequestException` and `IOError`; (5) change all `print()` into `self.stdout.write` and `self.stderr.write`; - In `import_instruments.py`, change relative image path into absolute path; - Recover migrations file; create an additional file for thumbnail field; Refs: #138
Ok, @kunfang98927... the changes look great, but there's one more thing I realized as I was running this locally about the location of the image files. Sorry I didn't catch it earlier.
|
Thank you for the comments.
Yes I think downloading to
Sure. I'll replace the thumbnail url in template with the one using
|
- change image output dir in `download_imgs.py` command to downloading images into static volume; - change image url in `import_instruments.py` command to store relative img urls into database; - add `static` template tag in gallery view templates; Refs: #138
Please note that now before running
python manage.py import_instruments
, you should first runpython manage.py download_imgs
.There are a few changes in this pull request:
pillow
dependency for image conversion and compression (by runningpoetry add pillow
);download_imgs.py
. By runningpython manage.py download_imgs
, it will: (1) download all original instrument images (one image for each instrument) from wikimedia urls intovim-static
volume; (2) convert original images to .png format and store them on UMIL server; (3) compress original images and store the smaller version as thumbnails on UMIL server;import_instruments.py
command: replace the old image urls with current image paths;thumbnail
field inInstrument
model;migrations/0002_instrument_thumbnail.py
;static
template tag;__init__.py
underVIM/apps
directory to fix pylint error:No name 'apps' in module 'VIM' Pylint(E0611:no-name-in-module)
;Resolves: #138