Module calmagick
[hide private]
[frames] | no frames]

Module calmagick

source code

high quality photo calendar composition using ImageMagick

Classes [hide private]
  PNMImage
class to represent an PNM grayscale image given in P2 format
Functions [hide private]
subprocess.Popen
run_callirhoe(style, size, args, outfile)
launch callirhoe to generate a calendar
source code
type(x)
_bound(x, lower, upper)
return the closest number to x that lies in [lower,upper]
source code
optparse.OptionParser
get_parser()
get the argument parser object
source code
 
check_parsed_options(options)
set (remaining) default values and check validity of various option combinations
source code
[[str,...],[str,...],[str,...]]
parse_magick_args()
extract arguments from command-line that will be passed to ImageMagick
source code
str
mktemp(ext='')
get temporary file name with optional extension
source code
str
get_outfile(infile, outdir, base_prefix, format, hint=None)
get output file name taking into account output directory, format and prefix, avoiding overwriting the input file
source code
(int,int)
_IM_get_image_size(img, args)
extract tuple(width,height) from image file using ImageMagick
source code
float
_IM_get_image_luminance(img, args, geometry=None)
get average image luminance as a float in [0,255], using ImageMagick
source code
[str,...]
_IM_entropy_args(alt=False)
IM entropy computation arguments, depending on default or alternate algorithm
source code
(int,int,int,int)
_entropy_placement(img, size, args, options, r)
get rectangle of minimal/maximal entropy
source code
(int,int,int,int)
_manual_placement(size, options, r)
get rectangle of ratio r with user-defined placement (N,S,W,E,NW,NE,SW,SE,center,random)
source code
dict
get_cache(num_photos, num_months)
returns a reference to the cache object, or None if caching is disabled
source code
 
compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=None, cache=None)
performs calendar composition on a photo image
source code
[(int,int),...]
parse_range(s, hint=None)
returns list of (Month,Year) tuples for a given range
source code
 
range_worker(q, ev, i)
worker thread for a (Month,Year) tuple
source code
 
main_program()
this is the main program routine
source code
Variables [hide private]
  _prog_im = 'convert'
ImageMagick binary, either 'convert' or env var CALLIRHOE_IM
  _IM_lum_args = ['-colorspace', 'Lab', '-channel', 'R', '-separ...
IM colorspace conversion arguments to extract image luminance
  _IM_entropy_head = ['-scale', '262144@>']
IM args for entropy computation: pre-scaling
  _IM_entropy_alg = [['-define', 'convolve:scale=!', '-define', ...
IM main/alternate entropy computation operator
  _IM_entropy_tail = ['-colorspace', 'Lab', '-channel', 'R', '-s...
IM entropy computation final colorspace
  _cache = {}
cache input photo computed rectangle and luminance, key=filename, value=(geometry,is_dark)
  _mutex = threading.Lock()
mutex for cache access
  __package__ = None
Function Details [hide private]

run_callirhoe(style, size, args, outfile)

source code 

launch callirhoe to generate a calendar

Parameters:
  • style - calendar style to use (passes -s option to callirhoe)
  • size - tuple (width,height) for output calendar size (in pixels)
  • args - (extra) argument list to pass to callirhoe
  • outfile - output calendar file
Returns: subprocess.Popen
Popen object

parse_magick_args()

source code 

extract arguments from command-line that will be passed to ImageMagick

ImageMagick-specific arguments should be defined between arguments --pre-magick, --in-magick, --post-magick is this order

Returns: [[str,...],[str,...],[str,...]]
3-element list of lists containing the [pre,in,post]-options

_entropy_placement(img, size, args, options, r)

source code 

get rectangle of minimal/maximal entropy

Parameters:
  • img - image file
  • size - image size tuple(width,height)
  • args - ImageMagick pre-processing argument list (see --pre-magick)
  • options - (command-line) options object
  • r - rectangle ratio, 0=match input ratio
Returns: (int,int,int,int)
IM geometry tuple(width,height,x,y)

_manual_placement(size, options, r)

source code 

get rectangle of ratio r with user-defined placement (N,S,W,E,NW,NE,SW,SE,center,random)

Parameters:
  • size - image size tuple(width,height)
  • options - (command-line) options object
  • r - rectangle ratio, 0=match input ratio
Returns: (int,int,int,int)
IM geometry tuple(width,height,x,y)

get_cache(num_photos, num_months)

source code 

returns a reference to the cache object, or None if caching is disabled

Returns: dict

Note: caching is enabled only when more than 1/6 of photos is going to be re-used

compose_calendar(img, outimg, options, callirhoe_args, magick_args, stats=None, cache=None)

source code 

performs calendar composition on a photo image

Parameters:
  • img - photo file
  • outimg - output file
  • options - (command-line) options object
  • callirhoe_args - extra argument list to pass to callirhoe
  • magick_args - [pre,in,post]-magick argument list
  • stats - if not None: tuple(current,total) counting input photos
  • cache - if cache enabled, points to the cache dictionary

parse_range(s, hint=None)

source code 

returns list of (Month,Year) tuples for a given range

Parameters:
  • s - range string in format Month1-Month2/Year or Month:Span/Year
  • hint - span value to be used, when Span=0
Returns: [(int,int),...]
list of (Month,Year) tuples for every month specified

range_worker(q, ev, i)

source code 

worker thread for a (Month,Year) tuple

Parameters:
  • ev - Event used to consume remaining items in case of error
  • q - Queue object to consume items from
  • i - Thread number

main_program()

source code 

this is the main program routine

Parses options, and calls compose_calendar() the appropriate number of times, possibly by multiple threads (if requested by user)


Variables Details [hide private]

_IM_lum_args

IM colorspace conversion arguments to extract image luminance

Value:
['-colorspace',
 'Lab',
 '-channel',
 'R',
 '-separate',
 '+channel',
 '-set',
 'colorspace',
...

_IM_entropy_alg

IM main/alternate entropy computation operator

Value:
[['-define',
  'convolve:scale=!',
  '-define',
  'morphology:compose=Lighten',
  '-morphology',
  'Convolve',
  'Sobel:>'],
 ['(', '+clone', '-blur', '0x2', ')', '+swap', '-compose', 'minus', '-\
...

_IM_entropy_tail

IM entropy computation final colorspace

Value:
['-colorspace',
 'Lab',
 '-channel',
 'R',
 '-separate',
 '+channel',
 '-set',
 'colorspace',
...