@task
@use_master
@set_modified_on
def resize_preview(src, pk, **kw):
 instance = Preview.objects.get(pk=pk)
 (thumb_dst, full_dst) = (instance.thumbnail_path, instance.image_path)
 sizes = (instance.sizes or {})
 log.info(('[1@None] Resizing preview and storing size: %s' % thumb_dst))
 try:
  thumbnail_size = APP_PREVIEW_SIZES[0][:2]
  image_size = APP_PREVIEW_SIZES[1][:2]
  with private_storage.open(src, 'rb') as fp:
   size = Image.open(fp).size
  if (size[0] > size[1]):
   thumbnail_size = thumbnail_size[::(-1)]
   image_size = image_size[::(-1)]
  if kw.get('generate_thumbnail', True):
   sizes['thumbnail'] = resize_image(src, thumb_dst, thumbnail_size, remove_src=False)
  if kw.get('generate_image', True):
   sizes['image'] = resize_image(src, full_dst, image_size, remove_src=False)
  instance.sizes = sizes
  instance.save()
  log.info(('Preview resized to: %s' % thumb_dst))
  private_storage.delete(src)
  return True
 except Exception as e:
  log.error(('Error saving preview: %s; %s' % (e, thumb_dst)))

@ task @ use_master @ set_modified_on def resize_preview ( src , pk , ** kw ) : instance = Preview . objects . get ( pk = pk ) ( thumb_dst , full_dst ) = ( instance . thumbnail_path , instance . image_path ) sizes = ( instance . sizes or { } ) log . info ( ( '[1@None] Resizing preview and storing size: %s' % thumb_dst ) ) try : thumbnail_size = APP_PREVIEW_SIZES [ 0 ] [ : 2 ] image_size = APP_PREVIEW_SIZES [ 1 ] [ : 2 ] with private_storage . open ( src , 'rb' ) as fp : size = Image . open ( fp ) . size if ( size [ 0 ] > size [ 1 ] ) : thumbnail_size = thumbnail_size [ : : ( - 1 ) ] image_size = image_size [ : : ( - 1 ) ] if kw . get ( 'generate_thumbnail' , True ) : sizes [ 'thumbnail' ] = resize_image ( src , thumb_dst , thumbnail_size , remove_src = False ) if kw . get ( 'generate_image' , True ) : sizes [ 'image' ] = resize_image ( src , full_dst , image_size , remove_src = False ) instance . sizes = sizes instance . save ( ) log . info ( ( 'Preview resized to: %s' % thumb_dst ) ) private_storage . delete ( src ) return True except Exception as e : log . error ( ( 'Error saving preview: %s; %s' % ( e , thumb_dst ) ) )
resizes preview images and stores the sizes on the preview .