Translated by Google:
HMedia realizes smooth thumbnail generation for localized images
I often use Alibaba Cloud’s OSS service. My favorite feature of OSS is that it can realize thumbnail and format conversion of images through simple parameters.
However, if the image is stored locally, there is no way to use OSS’s thumbnail generation and format conversion functions.
Therefore, taking advantage of the background that a project must be deployed locally, I wrote a module to facilitate the corresponding rendering of the front end.
Quick Start
Installation
pip install hmedia
Add the following code in url.py
from django.urls import re_path
from hmedia.views import hmedia
urlpatterns = [
re_path(r’^media/(?P.*)$', hmedia),
]
Note that the content of urlpatterns in the example is added to your original content, not overwritten.
In addition, the media directory is the static file directory configured in settings. If your settings are different, please modify them. My settings are as follows:
MEDIA_URL = ‘media/’
MEDIA_ROOT = os.path.join(BASE_DIR, ‘media/’)
So it is media.
Usage
When calling the front end, refer to Alibaba Cloud’s OSS syntax specifications. Currently, only image scaling and format conversion functions are supported.
Portal: Alibaba Cloud OSS Image Processing (https://help.aliyun.com/zh/oss/user-guide/resize-images-4?spm=a2c4g.11186623.0.i1
)
You can also configure image processing rules in the data processing in OSS management, and refer to the front-end call code set by it.
Version history
1.0.0 First release
Source code address
https://github.com/spirits001/python-HMedia