Skip to main content

A Python module to create and apply filters to images.

Project description

FImage

A Python module to apply and create multiples filters to images.

You need to be using Python 3.7 or greater to be able to use FImage.

Installation

pip install fimage

Example

A Simple filter

Create a file app.py with:

from fimage import FImage
from fimage.filters import Sepia


def main():
    # replace 'my_picture.jpg' with the path to your image
    image = FImage('my_picture.jpg')

    # apply the Sepia filter to the image
    image.apply(Sepia(90))

    # save the image with the applied filter
    image.save('my_picture_sepia.jpg')


if __name__ == "__main__":
    main()

Now, just run it :

python app.py

This is my_picture.jpg before the filter was applied

my_picture.jpg

And this is how new image my_picture_sepia.jpg looks like after the filter was applied

my_picture_sepia.jpg

Note: 90 represents the adjustment value we want to use for applying a sepia tone to this picture, lower values will result an image with less sepia tone while higher values will give us an image with a notorious sepia tone.

Most of the filters FImage offers will need an adjustment value to be passed.

Applying multiple filters

FImage offers more filters besides the Sepia one, even you can combine multiples filters to give a better look to your picture.

Modify the file app.py to import more filters from FImage

from fimage import FImage
from fimage.filters import Contrast, Brightness, Saturation


def main():
    image = FImage('my_picture.jpg')

    # apply the mutiple filters to the image
    image.apply(
        Saturation(20),
        Contrast(25),
        Brightness(15)
    )

    # save the image with the applied filter
    image.save('my_picture_mixed.jpg')


if __name__ == "__main__":
    main()

We run it by

python app.py

And our new my_picture_mixed.jpg looks like

my_picture_mixed.jpg

The order in which the filters are passed to the apply function matters, this is because the filters are applied in a sequential manner, so the next filter will be applied over the resultant image from the previous one.

Currently FImage supports the following filters:

  • FillColor
  • Sepia
  • Contrast
  • Brightness
  • Saturation
  • Vibrance
  • Grayscale
  • Hue
  • Colorize
  • Invert
  • Gamma
  • Noise
  • Clip
  • Exposure

Presets

Presets are just the combinations of multiple filters with already defined adjustment values.

Let’s change our app.py one more time to use the Presets

from fimage import FImage
from fimage.presets import SinCity


def main():
    # replace 'my_picture.jpg' with the path to your image
    image = FImage('my_picture.jpg')

    # apply the SinCity preset to the image
    image.apply(SinCity())

    # save the image with the applied preset
    image.save('my_picture_sincity.jpg')


if __name__ == "__main__":
    main()

After we run it, we get our new my_picture_sincity.jpg

my_picture_sincity.jpg

Currently supported Presets:

  • SinCity
  • OrangePeel
  • Love

Custom Presets

If you like the look your picture got after testing different filters and want to store this combination for applying it to more pictures, you can create your own Preset by just extending the Preset Class and specifying these filters and their adjust values in it.

In our app.py let’s do

from fimage import FImage
from fimage.presets import Preset
from fimage.filters import Contrast, Brightness, Saturation


# Create my custom preset and specify the filters to apply
class MyOwnPreset(Preset):
    transformations = [
        Contrast(30),
        Saturation(50),
        Brightness(10),
    ]


def main():
    # replace 'my_picture.jpg' with the path to your image
    image = FImage('my_picture.jpg')

    # apply MyOwnPreset to the image
    image.apply(MyOwnPreset())

    # save the image with the applied preset
    image.save('my_picture_custom.jpg')


if __name__ == "__main__":
    main()

The new my_picture_custom.jpg

my_picture_custom.jpg

Now, in this way MyOwnPreset has the combination of filters you like and you can use to modify more pictures.

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

fimage-0.1.7.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fimage-0.1.7-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file fimage-0.1.7.tar.gz.

File metadata

  • Download URL: fimage-0.1.7.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.0 Windows/10

File hashes

Hashes for fimage-0.1.7.tar.gz
Algorithm Hash digest
SHA256 84233afb0bae522a5306405ba500eacc19375cf457ec2f6cf50a92780f00e86e
MD5 6ef60ed8688bc47e9d8a0f50ef50185e
BLAKE2b-256 f74b4af94a1d812e0f1f1fd761bf5f5e2d60a7b5dde4af45080cae66c3573a92

See more details on using hashes here.

File details

Details for the file fimage-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: fimage-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.0 Windows/10

File hashes

Hashes for fimage-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e09668a790d35b5c4108f1e8f99b7902ed64da4c40a9cac576344d95cdbbee5b
MD5 9c5199c88d71d1d8c34061deea0e63ec
BLAKE2b-256 6e1856efe8caed3382ddead8c0f6b9de4192f3d49eccad26513b09e398eed0fe

See more details on using hashes here.

Supported by

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