]> git.tokkee.org Git - inkscape.git/commitdiff

Code

automatic file extension
authoramphi <amphi@users.sourceforge.net>
Mon, 8 Jan 2007 05:29:09 +0000 (05:29 +0000)
committeramphi <amphi@users.sourceforge.net>
Mon, 8 Jan 2007 05:29:09 +0000 (05:29 +0000)
share/extensions/extractimage.inx
share/extensions/extractimage.py

index 1c80ccaae3dd52bf672a85b25db7f61840bf8c72..4036c05dbf6d1ec0a81f5209d6bea2e961559b2e 100644 (file)
@@ -4,6 +4,7 @@
        <dependency type="executable" location="extensions">extractimage.py</dependency>
        <dependency type="executable" location="extensions">inkex.py</dependency>
        <param name="filepath" type="string" _gui-text="Path to save image">none</param>
+       <param name="desc" type="description">Note: The file extension is appended automatically.</param>
     <effect>
                <object-type>all</object-type>
                 <effects-menu>
index f1b0f6f7a246f2b1e8a29d1ff468690aa7c92bff..5807c9e5b56a0f7947aebda3d824da9345d342fe 100644 (file)
@@ -22,11 +22,20 @@ import inkex, base64
 class MyEffect(inkex.Effect):
     def __init__(self):
         inkex.Effect.__init__(self)
+        self.OptionParser.add_option("--desc")
         self.OptionParser.add_option("--filepath",
                         action="store", type="string", 
                         dest="filepath", default=None,
                         help="")
     def effect(self):
+        mimesubext={
+            'png' :'.png',
+            'bmp' :'.bmp',
+            'jpeg':'.jpg',
+            'jpg' :'.jpg', #bogus mime
+            'icon':'.ico',
+            'gif' :'.gif'
+        }
         ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
         
         # exbed the first embedded image
@@ -39,6 +48,16 @@ class MyEffect(inkex.Effect):
                         if (xlink.value[:4]=='data'):
                             comma = xlink.value.find(',')
                             if comma>0:
+                                #get extension
+                                fileext=''
+                                semicolon = xlink.value.find(';')
+                                if semicolon>0:
+                                    for sub in mimesubext.keys():
+                                        if sub in xlink.value[5:semicolon]:
+                                            fileext=mimesubext[sub]
+                                            path=path+fileext;
+                                            break
+                                #save
                                 data = base64.decodestring(xlink.value[comma:])
                                 open(path,'wb').write(data)
                                 xlink.value = path