Skip to content

Commit

Permalink
Make sure directories are created if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
efloehr committed Feb 4, 2015
1 parent 696c462 commit 05a51c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
27 changes: 16 additions & 11 deletions image/management/commands/generate_daymaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,23 @@ def handle(self, *args, **options):
im_max.putpixel(pos, color_max)

# All done, save
dirpath = os.path.join(TIMELAPSE_DIR, APP_DIR, 'daymaps')
im_center.save(os.path.join(dirpath, 'center_raw.png'))
im_mean.save(os.path.join(dirpath, 'mean_raw.png'))
im_median.save(os.path.join(dirpath, 'median_raw.png'))
im_min.save(os.path.join(dirpath, 'min_raw.png'))
im_max.save(os.path.join(dirpath, 'max_raw.png'))
imagepath = os.path.join(TIMELAPSE_DIR, APP_DIR, 'daymaps')

# Make directory if it doesn't exist
if not os.path.exists(imagepath):
os.makedirs(imagepath)

im_center.save(os.path.join(imagepath, 'center_raw.png'))
im_mean.save(os.path.join(imagepath, 'mean_raw.png'))
im_median.save(os.path.join(imagepath, 'median_raw.png'))
im_min.save(os.path.join(imagepath, 'min_raw.png'))
im_max.save(os.path.join(imagepath, 'max_raw.png'))

# Scale
im_center.resize((1920,1080), Image.BICUBIC).save(os.path.join(dirpath, 'center_hd.png'))
im_mean.resize((1920,1080), Image.BICUBIC).save(os.path.join(dirpath, 'mean_hd.png'))
im_median.resize((1920,1080), Image.BICUBIC).save(os.path.join(dirpath, 'median_hd.png'))
im_min.resize((1920,1080), Image.BICUBIC).save(os.path.join(dirpath, 'min_hd.png'))
im_max.resize((1920,1080), Image.BICUBIC).save(os.path.join(dirpath, 'max_hd.png'))
im_center.resize((1920,1080), Image.BICUBIC).save(os.path.join(imagepath, 'center_hd.png'))
im_mean.resize((1920,1080), Image.BICUBIC).save(os.path.join(imagepath, 'mean_hd.png'))
im_median.resize((1920,1080), Image.BICUBIC).save(os.path.join(imagepath, 'median_hd.png'))
im_min.resize((1920,1080), Image.BICUBIC).save(os.path.join(imagepath, 'min_hd.png'))
im_max.resize((1920,1080), Image.BICUBIC).save(os.path.join(imagepath, 'max_hd.png'))


10 changes: 10 additions & 0 deletions image/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def make_daystrip(day):
img.paste(picture.crop((0,400,2048,401)),(0,row))

imagepath = os.path.join(TIMELAPSE_DIR, APP_DIR, 'daystrip')

# Make directory if it doesn't exist
if not os.path.exists(imagepath):
os.makedirs(imagepath)

filename = '{0}.png'.format(dayname)
img_filepath = os.path.join(imagepath, filename)
img.save(img_filepath)
Expand Down Expand Up @@ -146,6 +151,11 @@ def make_daystrip_picture(day):
img.paste(picture.crop((column,0,column+1,1536)),(column,0))

imagepath = os.path.join(TIMELAPSE_DIR, APP_DIR, 'daypic')

# Make directory if it doesn't exist
if not os.path.exists(imagepath):
os.makedirs(imagepath)

filename = '{0}.png'.format(dayname)
img_filepath = os.path.join(imagepath, filename)
img.save(img_filepath)
Expand Down

0 comments on commit 05a51c7

Please sign in to comment.