Hi again,

here's another little (haha, took hours) thing: I created an
openraster-thumbnailer based on cover-thubmnailer (well, I stripped out
a lot of things), that means, gnome/nautilus people will be able to see
.ora previews on their desktop / in their browser windows. I attached
the files needed for this (openraster-thumbnailer and
openraster-thumbnailer.schemas), but I haven't created an installation
script, yet.
However, here are the instructions:
 sudo cp openraster-thumbnailer /usr/bin/
 sudo chmod +x /usr/bin/openraster-thumbnailer
 sudo cp openraster-thumbnailer.schemas /usr/share/gconf/schemas/
 gconftool-2 --install-schema-file
/usr/share/gconf/schemas/openraster-thumbnailer.schemas
 gconf-schemas --register
/usr/share/gconf/schemas/openraster-thumbnailer.schemas

(but I'm unsure if that last step is needed)
Then simply restart nautilus (e.g. "killall -9 nautilus") and it should
create thumbnails for .ora files. If it doesn't, you might need to append
 image/openraster                                ora
to /etc/mime.types

If anyone's good at packaging or writing install-scripts, please let me
know. I'd be glad to be able to upload .deb files to my launchpad PPA so
that at least ubuntu users can easily install this script.
If there are archlinux users out there, I think it won't be too hard to
upload it to AUR or so.

Thanks

Till

P.S.: It still needs proper testing, though ;)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import Image, urllib, os.path, sys, re, zipfile, gtk

class Thumb(object):
    '''
    Create thumnails
    @img_path : The path of the picture to thumnail
    '''
    def __init__(self, img_path):
        ora = zipfile.ZipFile(file(img_path))
        data = ora.read("Thumbnails/thumbnail.png")
        loader = gtk.gdk.PixbufLoader("png")
        loader.write(data)
        loader.close()
        self.pixbuf = loader.get_pixbuf()
        self.thumb = None

    def create_thumb(self, size=96):
        '''
        create a square thumbnail
        @size : the size of the thumbnail (in pixels). NOTE: Shouldn't be
                greater than 128 px for a standard freedesktop thumbnail.
        '''
        ratio = float(self.pixbuf.get_height()) / self.pixbuf.get_width()
        self.pixbuf = self.pixbuf.scale_simple(size, int(size*ratio), 
gtk.gdk.INTERP_BILINEAR)

    def save_thumb(self, output, format='png'):
        '''
        Save the thumbnail in a file
        @output : the output path for the thumbnail
        @format : the format of the picture (Must be a PNG for a standard
                  freedesktop thumbnail !)
        '''
        self.pixbuf.save(output, format)

if __name__ == "__main__":
    #If we have 2 args
    if len(sys.argv) == 3:
        input = urllib.url2pathname(sys.argv[1]).replace('file://', '')
        output = urllib.url2pathname(sys.argv[2]).replace('file://', '')
        pic = Thumb(input)
        pic.create_thumb()
        pic.save_thumb(output, 'png')
    elif len(sys.argv) == 4:
        input = urllib.url2pathname(sys.argv[1]).replace('file://', '')
        output = urllib.url2pathname(sys.argv[2]).replace('file://', '')
        size = int(sys.argv[3])
        pic = Thumb(input)
        pic.create_thumb(size)
        pic.save_thumb(output, 'png')
    else:
        print "E: ["+__file__+":main] Need two(three) args : the input 
directory and the output image file (and the image size)."
        sys.exit(1)


<gconfschemafile>
<schemalist>
 <schema>
  <key>/schemas/desktop/gnome/thumbnailers/im...@openraster/enable</key>
  <applyto>/desktop/gnome/thumbnailers/im...@openraster/enable</applyto>
  <owner>openraster-thumbnailer</owner>
  <type>bool</type>
  <default>true</default>
  <locale name="C">
   <short/>
   <long/>
  </locale>
 </schema>
 <schema>
  <key>/schemas/desktop/gnome/thumbnailers/im...@openraster/command</key>
   <applyto>/desktop/gnome/thumbnailers/im...@openraster/command</applyto>
   <owner>openraster-thumbnailer</owner>
   <type>string</type>
   <default>/usr/bin/openraster-thumbnailer %s %u %o</default>
   <locale name="C">
    <short/>
    <long/>
   </locale>
 </schema>
</schemalist>
</gconfschemafile>
_______________________________________________
Mypaint-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/mypaint-discuss

Reply via email to