Quickstart¶
Configuration¶
After you have installed image-diet package and external compression tools, you need to configure it.
First, you need to point image-diet to your configuration file which you do
by adding DIET_CONFIG
setting to your project’s settings. Its value is the
absolute path to the configuration file you want to use.
Configuration is stored in YAML format and is described in pyimagediet’s documentation (image-diet2 uses pyimagediet for actual processing).
An additional value you can set in image-diet2’s configuration file is
tmpdir
that should point to directory where temporary files will be created.
Its default value is /tmp
.
If you are using filesystem (Django’s default) as storage and would like to process files with image-diet2 everywhere it is used, then add to settings:
DEFAULT_FILE_STORAGE = 'image_diet.storage.DietStorage'
If you are using some other backend class that you would like to augment with
DietStorage
, then set DIET_STORAGE
setting to that storage class.
Default values¶
image-diet2 already comes with some default values so you do not have to know or type everything. It is enough to provide only changes you want to make and they will either replace previous ones or be added if they are new.
Default configuration file:
# Commands to be executed (label: path)
commands:
optipng: optipng
advpng: advpng
pngcrush: pngcrush
jpegoptim: jpegoptim
jpegtran: jpegtran
gifsicle: gifsicle
# Parameters for commands (label: parameters)
# Use same labels as in command section.
parameters:
optipng: -force -o7 '{file}'
advpng: -z4 '{file}s'
pngcrush: -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB
-rem time '{file}' '{output_file}'
jpegoptim: -f --strip-all '{file}'
jpegtran: -copy none -progressive -optimize -outfile '{output_file}' '{file}'
gifsicle: -O2 '{file}' > '{output_file}'
# Pipelines for each file type. Order of labels specifies order of execution
# Use same labels as in command section.
pipelines: {}
# Uncomment and set if you want to backup original image
# backup: orig
# By default pyimagediet returns smallest file it can make even if that is
# the original. If you don't want that (for example to reliably measure
# effectivness of tools and their parameters) then uncomment next line.
keep_processed: true
# Directory for creating temporary files. Defaults to /tmp when not set.
# tmpdir: /tmp
DietMixin¶
In case your project uses different storage backends or want to use compression
only on non-default storage backend then you should use
image_diet.storage.DietMixin
mixin.