--- a/src/egonomy/config.py.tmpl Tue Mar 05 10:30:02 2013 +0100
+++ b/src/egonomy/config.py.tmpl Tue Mar 12 13:13:29 2013 +0100
@@ -136,3 +136,6 @@
}
IMAGES_PER_PAGE = 32
+
+BATIK_RASTERIZER_PATH = "path/to/batik-rasterizer.jar"
+BATIK_RASTERIZER_TEMP_FOLDER = "path/to/tmp_folder"
--- a/src/egonomy/views.py Tue Mar 05 10:30:02 2013 +0100
+++ b/src/egonomy/views.py Tue Mar 12 13:13:29 2013 +0100
@@ -14,6 +14,9 @@
from egonomy.search_indexes.query import ModelRelatedSearchQuerySet
from haystack.query import RelatedSearchQuerySet
import json
+import os
+import uuid
+import subprocess
import logging
logger = logging.getLogger(__name__)
@@ -221,8 +224,39 @@
frg_path = request.GET.get("path") or "MZ"
if not image_id or frg_path=="MZ":
return HttpResponseForbidden("The request needs an image and a not null path parameters.")
- # This is a TEMPORARY algorithm. In the future, this function build a picture from the fragment and will request the senseetive api
- img = get_object_or_404(Image, id=image_id)
+
+ img = get_object_or_404(Image.objects.select_related('info', 'metadata'), id=image_id)
+ frg = Fragment()
+ frg.image = img
+ frg.coordinates = frg_path
+ # We build the svg xml
+ file = os.path.join(settings.MEDIA_ROOT, str(img.info.image_file))
+ logger.debug(file)
+ svg = '<svg preserveAspectRatio="none" width="476px" height="476px" viewBox="' + frg.viewbox_square +'" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n\
+ <defs>\n\
+ <clipPath id="fragment-clip">\n\
+ <path d="' + frg_path + '" />\n\
+ </clipPath>\n\
+ </defs>\n\
+ <image xlink:href="' + file + '" x="0" y="0" preserveAspectRatio="none" width="1" height="1" opacity=".3"/>\n\
+ <image xlink:href="' + file + '" x="0" y="0" preserveAspectRatio="none" width="1" height="1" clip-path="url(#fragment-clip)"/>\n\
+</svg>'
+ # We save the svg file
+ uid = str(uuid.uuid1())
+ svg_file = open(os.path.join(settings.BATIK_RASTERIZER_TEMP_FOLDER, uid + '.svg'),'w')
+ svg_file.write(svg)
+ svg_file.close()
+ # We execute the batik command
+ args = ["java", "-jar", settings.BATIK_RASTERIZER_PATH, svg_file.name]
+ p = subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ if p.returncode!=0:
+ HttpResponse("Batik error : " + str(err))
+ # The picture png is now created
+
+
+
+ # This is a TEMPORARY algorithm. In the future, this function build a picture from the fragment and will request the senseetive api
frg_list = Fragment.objects.filter(image=img)
tag_list = []
for frg in frg_list:
@@ -230,7 +264,7 @@
for t in tags:
t = t.strip()
if t != "":
- logger.debug(t)
+ #logger.debug(t)
tag_list.append(t)
from time import sleep
sleep(2)