Example #1
0
def scale(img, size, path, quality):
    """按指定尺寸缩放图片,生成新图并保存. 缩放成功,返回新生成文件名,否则返回None
    call thumb()
    
    params:
        img: PIL Image object
        size: 文件缩放高宽值,tuple type
        path: 存储图片文件的目录(不包括最终文件名),绝对路径
        quality: 缩放后生成图片的分辨率, 将决定图片的存储容量, 100同原图容量, -->0依次减小 
    """
    
    filename = utils.genUuid()
    if _thumb(img, size) and _save(img, path, filename, _quality=quality):
        return filename

    return None
Example #2
0
     XY = (
         int(request.REQUEST.get("x1", '0')), 
         int(request.REQUEST.get("y1", '0')), 
         int(request.REQUEST.get("x2", '50')),
         int(request.REQUEST.get("y2", '50'))
     )
     if XY[0] == XY[2] and XY[1] == XY[3]:
         raise Exception
     img = img.crop(XY)
 except:
     utils.addMsg(request, messages.WARNING, u"""还没有对头像进行剪切。剪切请在
         大头像上按住、并拖动鼠标。若不需要剪切,可点击'撤销'""")
     return HttpResponseRedirect(reverse("profiles_setpic")) 
 
 
 big_pic = img_utils.scalePic(img, PIC_ROOT, "profile", utils.genUuid()+'_b', settings.PIC_SIZE_BIG, 100)
 normal_pic = img_utils.scalePic(img, PIC_ROOT, "profile", utils.genUuid()+'_n', settings.PIC_SIZE_NORMAL, 80)
 small_pic = img_utils.scalePic(img, PIC_ROOT, "profile", utils.genUuid()+'_s', settings.PIC_SIZE_SMALL, 50)
 
 if big_pic and normal_pic and small_pic:
     
     ## 删除临时图片及设置之前的图片
     if profile.tmp_pic != settings.DEFAULT_PIC:
         file_utils.remove(PIC_ROOT, profile.tmp_pic)
     
     if profile.big_pic != settings.DEFAULT_PIC:
         file_utils.remove(PIC_ROOT, profile.big_pic)
     if profile.normal_pic != settings.DEFAULT_PIC_NORMAL:
         file_utils.remove(PIC_ROOT, profile.normal_pic)
     if profile.small_pic != settings.DEFAULT_PIC_SMALL:
         file_utils.remove(PIC_ROOT, profile.small_pic)