Public Member Functions | |
def | __init__ |
def | add_dir |
def | add_file |
def | init_dirs |
def | process_args |
def | process_file_list |
def | process_files |
def | try_tempdir |
Public Attributes | |
FileList | |
Height | |
ProcMult | |
RecursiveDirs | |
Stretch | |
UseGIF | |
UseJPG | |
UsePNG | |
UseStats | |
Width |
The main class of IMGCrush. Handles input and high-level commands to other modules.
Definition at line 50 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.__init__ | ( | self, | ||
argv | ||||
) |
Constructor. Initializes the optimizer and its modules and processes input. Data members: Files and directories: SaveDir : Directory to save output files. FileList : Addresses of all input files. Resizing: By default, resizing preserves aspect ratio, therefore Width and Height are maximum bounds of the resized image. If only one bound is specified, e.g. Width, the image is resized to fill the given bound and the other is resized accordingly to preserve aspect ratio. If no bounds are specified or are 0, resizing is turned off. Other members modify resizing behavior. NOTE: Resizing options are deprecated! Width : Maximum width of resized output. Height : Maximum height of resized output. Stretch : If given bounds aren't filled by resized image, stretch the image to fill them. File format modules: UseJPG : Use the JPG module? I.e. consider JPG output for optimization. UsePNG : Use the PNG module? I.e. consider PNG output for optimization. UseGIF : Use the GIF module? I.e. consider GIF output for optimization. Other: ProcMult : Multiplier of the number of processes used when processing files. Number of processes actually depends on number of formats used as every format is processed in a separate process. E.g. if ProcMult==2 and we're using JPG and GIF, the actual number of processes is 4
Definition at line 55 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.add_dir | ( | self, | ||
dirname | ||||
) |
Adds all image files in a directory to the list of files to process. Does not add files in subdirectories. Arguments: dirname : Name of the directory to add files from.
Definition at line 149 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.add_file | ( | self, | ||
f, | ||||
prependdir = None | ||||
) |
Adds an input file to the list of files to process. Ignores the file if it's invalid. Arguments: f : Filename of the input file. r : Filename of the corresponding temporary reference file relative to the temp directory. o : Filename of the corresponding output file relative to the optput directory.
Definition at line 117 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.init_dirs | ( | self | ) |
Initializes temp and output dirs and ends with error if not possible.
Definition at line 308 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.process_args | ( | self, | ||
argv | ||||
) |
Processes all command-line input. Input is validated in objects that are affected by it. i.e. , input that sets properties of ImageOptimizer is validated here, other input is passed to objects that use it and validated there. If an argument given to command line option is wrong, default value is usually used. If an unrecognizable option is given or an option that requires an argument is given without an argument, help is displayed and the program is aborted. Arguments: argv : List of command line options and their arguments.
Definition at line 347 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.process_file_list | ( | self, | ||
files, | ||||
fcounter, | ||||
procnum = 0 | ||||
) |
Processes given list of files. For each file in list, this generates temp files, compares them using tester and outputs the best file.
Definition at line 227 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.process_files | ( | self | ) |
Generates temp files, selects the best and cleans up. This is the main method of imgcrush: it handles generation of files based on input using file format modules, compares them using tester and outputs the best files. In the end it deletes the temp directory along with temporary files. If multiple processes are used, files are divided into groups, each processed by it's own process.
Definition at line 193 of file imageoptimizer.py.
def imgcrush.imageoptimizer.ImageOptimizer.try_tempdir | ( | self, | ||
temp | ||||
) |
Tries to create given temp directory. If temp dir already exists, it appends a number (0) to its name and tries to create that, if unsuccesful again, appends incremented number (1) and so on. If temp dir can't be created, it returns False, otherwise returns its path.
Definition at line 280 of file imageoptimizer.py.