Skip to main content

Python support for ImgProxy

Project description

ImgProxy

ImgProxy -- Python library to build ImgProxy URLs

Tests Status PYPI Version Python Versions


Features

  • Support for advanced urls
  • Support for signing urls
  • URL's Factories with predefined params

Table of Contents

Requirements

  • python >= 3.7

Installation

imgproxy should be installed using pip:

$ pip install imgproxy

Usage

    from imgproxy import ImgProxy

    # Create ImgProxy object with required params
    url = ImgProxy('https://picsum.photos/1000', proxy_host='https://imgproxy.com', width=800, height=400)

    # Convert the obj to string to get imgproxy URL
    cover: str = str(url)

    # or just call it to get imgproxy URL
    cover: str = url()

    assert cover == 'https://imgproxy.com/insecure/g:ce/rs:auto:800:400:0/aHR0cHM6Ly9waWNzdW0ucGhvdG9zLzEwMDA'

    # Call the object with different params to customize the url
    cover_small: str = url(width=400, height=200, resizing_type='fill')

    assert cover_small == 'https://imgproxy.com/insecure/g:ce/rs:fill:400:200:0/aHR0cHM6Ly9waWNzdW0ucGhvdG9zLzEwMDA'

    # Call it with advanced params to get an URL
    cover_with_border = url('pd:10:10:10:10', 'bg:F00')
    assert cover_with_border == 'https://imgproxy.com/insecure/pd:10:10:10:10/bg:F00/g:ce/rs:auto:0:0:0/aHR0cHM6Ly9waWNzdW0ucGhvdG9zLzEwMDA'

Signed URLs

Imgproxy allows you to sign your URLs with key and salt, so an attacker won’t be able to cause a denial-of-service attack by requesting multiple different image resizes.

    from imgproxy import ImgProxy

    url = ImgProxy('https://picsum.photos/1000', proxy_host='https://imgproxy.com', key="aa396160c50ea766910eab53", salt="b3fb8f215827bda5d0e7313d")

    assert str(url) == 'https://imgproxy.com/FrH21u_5bXmv-OJ0APMayxZ0F3982xx437gCpqcQ0BM/g:ce/rs:auto:600:0:0/aHR0cHM6Ly9waWNzdW0ucGhvdG9zLzEwMDA'

If you need a random key/salt pair real fast, you can quickly generate it using, for example, the following snippet:

    echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')

Image factories

Usually imgproxy host and signature params are common for a project. The library supports a method to generate a factory with predefined params:

    from imgproxy import ImgProxy

    img_factory = ImgProxy.factory(proxy_host='https://imgproxy.com', key="aa396160c50ea766910eab53", salt="b3fb8f215827bda5d0e7313d")

    # ...

    # Generate image URL
    url = img_factory('https://picsum.photos/1000', width=600)
    assert str(url) == 'https://imgproxy.com/FrH21u_5bXmv-OJ0APMayxZ0F3982xx437gCpqcQ0BM/g:ce/rs:auto:600:0:0/aHR0cHM6Ly9waWNzdW0ucGhvdG9zLzEwMDA'

Users able to predifine any basic params:

    thumbnail_factory = ImgProxy.factory(proxy_host='https://imgproxy.com', width=300, height=200)
    preview_factory = ImgProxy.factory(proxy_host='https://imgproxy.com', width=500, resizing_type='fit')

    # and etc

Changelog

  • 2021-09-14: [0.4.0]

    • Support python 3.7
    • Basic format has been removed (it's depricated in ImgProxy)
  • 2021-04-02: [0.2.3] Stable release

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/imgproxy/issues

Contributing

Development of the project happens at: https://github.com/klen/imgproxy

License

Licensed under a MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imgproxy-0.4.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

imgproxy-0.4.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file imgproxy-0.4.1.tar.gz.

File metadata

  • Download URL: imgproxy-0.4.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for imgproxy-0.4.1.tar.gz
Algorithm Hash digest
SHA256 589db93c38b1d246d0f0ab45aa8d4eb223c37e6aa392b6f47469a1caca0cf1c6
MD5 47128b244642f958ff53f07c5c4b4a58
BLAKE2b-256 a96389f406e8be99f4d4213be89d719fbe9dc39985d5035276f7fed4be4ee61f

See more details on using hashes here.

File details

Details for the file imgproxy-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: imgproxy-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for imgproxy-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc3a31233fd2bde4f0d1896521de7dfad788766f05937a425d47448e4ade5226
MD5 669bf3d36f4190752b5642db4fbdb10e
BLAKE2b-256 7a09501cad60e97640fc1360c2074443cff2235bf0671852a4a866eaa9c10426

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page