mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-25 16:20:33 +03:00
Set options from environment variables
This commit is contained in:
parent
3bfdfcd48a
commit
67e1e03c79
37
PIL/Image.py
37
PIL/Image.py
|
@ -2824,3 +2824,40 @@ def radial_gradient(mode):
|
|||
:param mode: Input mode.
|
||||
"""
|
||||
return Image()._new(core.radial_gradient(mode))
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Resources
|
||||
|
||||
def _apply_env_variables(env=None):
|
||||
if env is None:
|
||||
env = os.environ
|
||||
|
||||
for var_name, setter in [
|
||||
('PILLOW_ALIGNMENT', core.set_alignment),
|
||||
('PILLOW_BLOCK_SIZE', core.set_block_size),
|
||||
('PILLOW_BLOCKS_MAX', core.set_blocks_max),
|
||||
]:
|
||||
if var_name not in env:
|
||||
continue
|
||||
|
||||
var = env[var_name].lower()
|
||||
|
||||
units = 1
|
||||
for postfix, mul in [('k', 1024), ('m', 1024*1024)]:
|
||||
if var.endswith(postfix):
|
||||
units = mul
|
||||
var = var[:-len(postfix)]
|
||||
|
||||
try:
|
||||
var = int(var) * units
|
||||
except ValueError:
|
||||
warnings.warn("{0} is not int".format(var_name))
|
||||
continue
|
||||
|
||||
try:
|
||||
setter(var)
|
||||
except ValueError as e:
|
||||
warnings.warn("{0}: {1}".format(var_name, e))
|
||||
|
||||
_apply_env_variables()
|
||||
|
|
|
@ -373,7 +373,7 @@ ImagingAllocateArray(Imaging im, int dirty)
|
|||
{
|
||||
int y, line_in_block, current_block;
|
||||
ImagingMemoryArena arena = &ImagingDefaultArena;
|
||||
char* p;
|
||||
char* p = NULL;
|
||||
int linesize, lines_per_block, blocks_count;
|
||||
|
||||
/* 0-width or 0-height image. No need to do anything */
|
||||
|
|
Loading…
Reference in New Issue
Block a user