From 738a307f3b24ee9b2de16e7e56d495a14709eef8 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 06 Feb 2011 21:31:03 +0000 Subject: image_to_base64 accepts pathname --- diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index f600228..8f12f61 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -28,7 +28,7 @@ import base64 from sprites import Sprite from tasprite_factory import SVG -from tautils import image_to_base64, data_to_string, round_int +from tautils import image_to_base64, get_path, data_to_string, round_int from taconstants import CANVAS_LAYER, BLACK, WHITE import logging @@ -498,7 +498,8 @@ class TurtleGraphics: if self.tw.running_sugar: # In Sugar, we need to embed the images inside the SVG self.tw.svg_string += self.svg.image(x - self.width / 2, - y, w, h, path, image_to_base64(pixbuf, self.tw.activity)) + y, w, h, path, image_to_base64(pixbuf, + get_path(self.tw.activity, 'instance'))) else: self.tw.svg_string += self.svg.image(x - self.width / 2, y, w, h, path) diff --git a/TurtleArt/taexporthtml.py b/TurtleArt/taexporthtml.py index 09042f8..2dac7e6 100644 --- a/TurtleArt/taexporthtml.py +++ b/TurtleArt/taexporthtml.py @@ -22,7 +22,7 @@ import pygtk pygtk.require('2.0') import gtk import os.path -from tautils import data_to_string, save_picture, image_to_base64 +from tautils import data_to_string, save_picture, image_to_base64, get_path from gettext import gettext as _ from cgi import escape @@ -90,7 +90,8 @@ def save_html(self, tw, embed_flag=True): tmp = imgdata else: pixbuf = gtk.gdk.pixbuf_new_from_file(p) - imgdata = image_to_base64(pixbuf, tw.activity) + imgdata = image_to_base64(pixbuf, + get_path(tw.activity, 'instance')) tmp = self.html_glue['img2'][0] tmp += imgdata tmp += self.html_glue['img2'][1] @@ -110,7 +111,7 @@ def save_html(self, tw, embed_flag=True): else: if self.embed_images == True: imgdata = image_to_base64(save_picture(self.tw.canvas), - tw.activity) + get_path(tw.activity, 'instance')) else: imgdata = os.path.join(self.tw.load_save_folder, 'image') self.tw.save_as_image(imgdata) diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index c66b322..414935a 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -285,12 +285,12 @@ def get_path(activity, subpath): "org.laptop.TurtleArtActivity", subpath)) -def image_to_base64(pixbuf, activity): +def image_to_base64(pixbuf, pathname): """ Convert an image to base64 """ - _file_name = os.path.join(get_path(activity, 'instance'), 'imagetmp.png') + _file_name = os.path.join(pathname, 'imagetmp.png') if pixbuf != None: pixbuf.save(_file_name, "png") - _base64 = os.path.join(get_path(activity, 'instance'), 'base64tmp') + _base64 = os.path.join(pathname, 'base64tmp') _cmd = "base64 <" + _file_name + " >" + _base64 subprocess.check_call(_cmd, shell=True) _file_handle = open(_base64, 'r') -- cgit v0.9.1