使用 django-imagekit 调整上传时的图像大小

发布于 2024-09-01 13:26:42 字数 106 浏览 2 评论 0原文

我正在使用 imagekit 来处理上传图像的自定义尺寸。虽然它可以很好地创建自定义尺寸的图像,但我想使用 imagekit 在上传时调整原始图像的大小。这可能吗?

I am using imagekit to handle custom size of uploaded images. While it works fine for creating custom size images with this, I'd like to use imagekit to resize the original image on upload. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ˇ宁静的妩媚 2024-09-08 13:26:42

请点击上面的链接。

  • 根据需要为原始图像创建处理器(调整大小、增强等)。查看 imagekit wiki 的示例

    class ResizeOriginal(processors.Resize): 
        宽度=640 
        高度 = 480
    
  • 使用以前的处理器为此原始图像创建 ImageSpec。将 pre_cache 保留为默认值(false)

    类原始(ImageSpec): 
        处理器 = [调整原始大小] 
    
  • 将该 ImageSpec 添加到您的 IKoptions ImageModel 预处理器中。

    preprocessor_spec = Original

follow the link above.

  • Create processors as you like for original image (resize, enhance, etc). Look imagekit wiki for examples

    class ResizeOriginal(processors.Resize): 
        width = 640 
        height = 480
    
  • Create your ImageSpec for this original image with those previously processors. Leave pre_cache as default (false)

    class Original(ImageSpec): 
        processors = [ResizeOriginal] 
    
  • Add that ImageSpec to your IKoptions ImageModel preprocessor.

    preprocessor_spec = Original

故事灯 2024-09-08 13:26:42

我相信更新的答案是 ProcessedImageField

参考资料取自@matthew

I believe the updated answer is ProcessedImageField.

Reference taken from @matthew.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文