def add_watermark(main_folder, image_file, path_watermark, all_size={'x':0,'x2':100,'y':0,'y2':100},opacity=0.5): if all_size['x']=="" or all_size['x2']=="" or all_size['y']=="" \ or all_size['y2']=="" or all_size['w_view']=="" or all_size['h_view']=="": return False path_to_folder = MEDIA_ROOT + main_folder result_file = WATERMARK_PREFIX + image_file path_watermark = MEDIA_ROOT + path_watermark if os.path.isfile(path_to_folder+image_file): shutil.copyfile(path_to_folder+image_file, path_to_folder+result_file) if os.path.isfile(path_to_folder+result_file): os.chmod(path_to_folder+result_file, 0755) result_file_path = path_to_folder+result_file # Открываем текущее изобразение изображение image = Image.open(result_file_path, 'r') w_orig = image.size[0] h_orig = image.size[1] w_koef = float(w_orig)/int(all_size['w_view']) h_koef = float(h_orig)/int(all_size['h_view']) x = int(int(all_size['x'])*w_koef) x2 = int(int(all_size['x2'])*w_koef) y = int(int(all_size['y'])*h_koef) y2 = int(int(all_size['y2'])*h_koef) w_watermark = x2 - x h_watermark = y2 - y if w_watermark!=0 and h_watermark!=0: watermark_size = str(w_watermark)+'x'+str(h_watermark) path_watermark = MEDIA_ROOT.replace('/media/','')+get_thumbnail(path_watermark, watermark_size, crop='center', quality=99).url # Открываем водяной знак if os.path.isfile(path_watermark): watermark = Image.open(path_watermark, 'r') assert opacity >= 0 and opacity <= 1 if opacity < 1: if watermark.mode != 'RGBA': watermark = watermark.convert('RGBA') else: watermark = watermark.copy() alpha = watermark.split()[3] alpha = ImageEnhance.Brightness(alpha).enhance(opacity) watermark.putalpha(alpha) layer = Image.new('RGBA', image.size, (0,0,0,0)) layer.paste(watermark, (x, y)) Image.composite(layer, image, layer).save(result_file_path) Image.composite(layer, image, layer).save(result_file_path) # Delete the Key Value Store reference but **not** the file. # Use this if you have changed the source delete(main_folder + result_file, delete_file=False) return result_file return False
def get_most_common(self): return WordCounter.listify(WordCounter.analyzeStems( MEDIA_ROOT.replace(MEDIA_URL, '') + self.raw_file.url))
import oembed oembed.autodiscover() from django.http import HttpResponseRedirect from settings import DEBUG, MEDIA_ROOT urlpatterns = patterns( "", (r"^lists/", include("lists.urls")), (r"^ajax_validate/", include("ajax_validate.urls")), (r"^rate/", include("djangoratings.urls")), (r"^admin/doc/", include("django.contrib.admindocs.urls")), (r"^admin/", include(admin.site.urls)), (r"^$", lambda request: HttpResponseRedirect("/lists/")), ) if DEBUG: urlpatterns += patterns( "", (r"^media/(?P<path>.*)$", "django.views.static.serve", {"document_root": MEDIA_ROOT, "show_indexes": True}), ( r"^versioned/(?P<path>.*)$", "django.views.static.serve", {"document_root": MEDIA_ROOT.child("versioned"), "show_indexes": True}, ), (r"^media/(?P<path>.*)$", "django.views.static.serve", {"document_root": MEDIA_ROOT}), (r"^versioned/(?P<path>.*)$", "django.views.static.serve", {"document_root": MEDIA_ROOT + "versioned/"}), )
def get_most_common(self): return WordCounter.listify( WordCounter.analyzeStems( MEDIA_ROOT.replace(MEDIA_URL, '') + self.raw_file.url))