HMedia实现对本地化图片的丝滑般生成缩略图
我经常使用阿里云的oss服务,我最喜欢oss的功能就是通过简单的参数,就能实现图片的缩略图与格式转换。
但是,如果图片使用本地存储时候,就没办法使用oss的生成缩略图和格式转换功能了。
所以,借着一个项目必须本地化部署的背景,我写了一个模块,让前端方便进行对应渲染。
快速开始
安装
pip install hmedia
在url.py中增加以下代码
from django.urls import re_path
from hmedia.views import hmedia
urlpatterns = [
re_path(r'^media/(?P<path>.*)$', hmedia),
]
注意,示例中urlpatterns的内容,是增加在您原有内容里,不是覆盖。
另外,media目录是在settings里配置的静态文件目录。如果你不一样,请修改,我的settings内容如下:
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
所以是media。
使用方式
前端调用时候,参考阿里云的oss语法规范,目前仅支持图片缩放、格式转换功能。
传送门:阿里云oss图片处理
也可以在oss管理中的数据处理里,配置图片处理规则,参考其设定的前端调用代码。
版本历史
1.0.0 首次发布
Metadata
Release files for hmedia 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hmedia-1.0.0.tar.gz | 4.6 kB | Without provenance | Details for hmedia-1.0.0.tar.gz |
Release files / hmedia-1.0.0.tar.gz
| Download URL | hmedia-1.0.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05d6dcfbe08fdf3dfd8db8d9266480be19d3194c72a1b603e86cd553ea8c06d2
|
|
BLAKE2b-256 checksum How to use checksums |
ff564ba241f54245a4d73923f5532e2af729ba4629d2c85288b292b3d01518b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for hmedia 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.