Page 3 of 11 FirstFirst 12345 ... LastLast
Results 21 to 30 of 106

Thread: HOWTO: Thumbnails for OpenOffice.org 2 files

  1. #21
    Join Date
    Apr 2005
    Location
    Sintra, Portugal
    Beans
    835

    Talking Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    Worked great!

    Thanks!

  2. #22

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    Nice one minio

    Heres another one, grabs the icon from the current gnome theme instead...
    Not really sure what the deal is with the mime types I've got
    • gnome-mime-application-vnd.oasis.opendocument.text
    • ooo-writer
    • gnome-mime-application-vnd.stardivision.writer
    • openofficeorg-20-writer
    • gnome-mime-application-vnd.sun.xml.writer
    • ximian-openoffice-writer
    • ooo_writer

    Any idea which one is the 'correct' one? My monies on the oasis one.


    Code:
    #!/usr/bin/env python
    
    import gnomevfs
    import gtk
    import os
    import sys
    import zipfile
    from PIL import Image, ImageEnhance
    
    # Alter these varibles to change thumbnail look
    ICON_USE_CURRENT_THEME = True
    # If not using current theme then use this path
    ICON_PATH_BASE = "/usr/share/icons/hicolor/48x48/apps/" # Change this path to alter icons
    ICON_PREFIX = "ooo-" #Ubuntu icons
    #ICON_PREFIX="openofficeorg-20-" #OOo2 stock icons
    
    ICON_OPACITY = 0.6 #Opacity of the icon (between 0.0 and 1.0)
    THUMBNAIL_BACKGROUND_COLOR = "white" # Color of the background
    # Prefix for using mime types
    ICON_MIME_PREFIX = "gnome-mime-application-"
    
    in_file_path = gnomevfs.get_local_path_from_uri(sys.argv[1])
    out_file_path = sys.argv[2]
    path_without_thumbs = os.getenv("HOME")+"/Templates" 
    	
    def get_icon(thumbnail_size):
    	icon_names={"formula":"math","graphics":"draw","presentation":"impress","spreadsheet":"calc","text":"writer"}
    	#Get file mimetype
    	file_mime_type=gnomevfs.get_mime_type(in_file_path)
    	#print file_mime_type
    	#Get last part of mimetype name.
    	application_name=file_mime_type.split(".")[-1]	
    	try:
    		#For OOo2 files we have to find icon name in icon_names
    		icon_name=icon_names[application_name]
    	except:
    		#But for OOo1 files it is equal to icon name (without prefix).
    		icon_name=application_name
    	#Load icon
    	if ICON_USE_CURRENT_THEME:
    		icon_name = ICON_MIME_PREFIX+ file_mime_type.split("/")[1]
    		icon = get_current_theme_icon( icon_name )
    	else:
    		icon = Image.open(ICON_PATH_BASE+ICON_PREFIX+icon_name +".png").convert("RGBA")
    	#Set it's opacity
    	icon = set_icon_opacity(icon,ICON_OPACITY)
    	#And set it's position in thumbnail
    	icon_posx=thumbnail_size[0]-icon.size[0]
    	icon_posy=thumbnail_size[1]-icon.size[1]
    	icon_width=thumbnail_size[0]
    	icon_height=thumbnail_size[1]
    	return {"image":icon,"position":(icon_posx,icon_posy,icon_width,icon_height)}	
    
    def get_basic_thumbnail():
    	#Find out if the file is not in Templates directory
    	if in_file_path.find(path_without_thumbs)!=0:
    		try:
    			#Extract thumbnail from OOo file and save it
    			zip=zipfile.ZipFile(in_file_path,mode="r")
    			picture=zip.read("Thumbnails/thumbnail.png")
    			zip.close()
    			thumbnail=open(out_file_path,"w")
    			thumbnail.write(picture)
    			thumbnail.write("/n")
    			thumbnail.close()
    			#Open saved thumbnail
    			image=Image.open(out_file_path).convert("RGBA")
    			return {"suceeded":True,"image":image,"size":(image.size[0],image.size[1])}
    		
    		except:
    			return {"suceeded":False}
    	else:
    		return {"suceeded":False}
    
    # Nicked from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879
    def set_icon_opacity(icon,opacity):
    	#Returns an image with reduced opacity.
    	assert opacity >= 0 and opacity <= 1
    	if icon.mode != 'RGBA':
    		icon = icon.convert('RGBA')
    	else:
    		icon = icon.copy()
    	alpha = icon.split()[3]
    	alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    	icon.putalpha(alpha)
    	return icon
    
    # Convert GTK pixbuf to PIL Image
    def convert_pixbuf_to_image(pb):
    	assert(pb.get_colorspace() == gtk.gdk.COLORSPACE_RGB)
    	dimensions = pb.get_width(), pb.get_height()
    	stride = pb.get_rowstride()
    	pixels = pb.get_pixels()
    	mode = pb.get_has_alpha() and "RGBA" or "RGB"
    	return Image.frombuffer(mode, dimensions, pixels,"raw", mode, stride, 1)
    
    # Get the icon from the current GTK theme
    def get_current_theme_icon( icon ):
    	theme = gtk.icon_theme_get_default()
    	#print theme.list_icons()
    	pixbuf_icon = theme.load_icon(icon, 46, 0)
    	return convert_pixbuf_to_image(pixbuf_icon)
    
    thumbnail=get_basic_thumbnail()
    if thumbnail["suceeded"]:
    	background=Image.new("RGB", thumbnail["size"], THUMBNAIL_BACKGROUND_COLOR)
    	icon=get_icon(thumbnail["size"])
    	thumbnail=thumbnail["image"]
    	# Add thumbnail
    	background.paste(thumbnail, None, thumbnail)
    	# Add icon
    	background.paste(icon["image"],icon["position"],icon["image"])
    	# Save thumbnail
    	background.save(out_file_path,"PNG")
    Last edited by KillerKiwi; November 7th, 2005 at 09:34 AM.

  3. #23
    Join Date
    Oct 2005
    Location
    Rome, Ga
    Beans
    2,339
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    I don't get it. I already see thumbnails.

  4. #24
    Join Date
    Nov 2004
    Location
    Prague, Czech Republic
    Beans
    68

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    KillerKiwi:I have no idea either. I would say oasis and stardivision.writer but it is a blind shot. I have one more idea how to change the code so I'll try to do it till end of week.


    BLTicklemonster: Huh? Do you have clean breezy install or do you have custom OOo2?

  5. #25
    Join Date
    Mar 2005
    Beans
    147

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    Is there a way to get thumbnails to show up for documents saved in openoffice with excel or word extensions?

  6. #26

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    The all knowing wiki knows

    http://en.wikipedia.org/wiki/OpenDocument#File_types

    application/vnd.oasis.opendocument.text
    which Im pretty sure maps to the icon
    gnome-mime-application-vnd.oasis.opendocument.text

    Which is what the code I posted is using, much 'better' as opendocument is not just openoffice.

    Is there a way to get thumbnails to show up for documents saved in openoffice with excel or word extensions?
    Not using this method, as far as i know ms formats do not include a thumbnail. You could create one on the fly some how but that would be very slow

    Kiwi
    Last edited by KillerKiwi; November 8th, 2005 at 05:56 AM.

  7. #27
    Join Date
    Jun 2005
    Location
    Canada
    Beans
    79
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Exclamation Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    Quote Originally Posted by minio
    Ok i rewrote the code once again. It should work (at least it seems to work for me...)
    I found that this code doesn't work in Breezy, but the previous code (post 12) did.

  8. #28
    Join Date
    Nov 2004
    Location
    Prague, Czech Republic
    Beans
    68

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    Quote Originally Posted by Zxaos
    I found that this code doesn't work in Breezy, but the previous code (post 12) did.
    So this is strange, because I have breezy and it works for me. What do you get if you try run it from terminal? To run it from terminal put there something like this:
    Code:
    ooo2-thumbnailer file:///home/yourhome/path_to_some_OOo2_file /home/yourhome/Desktop/img.png

  9. #29
    Join Date
    Aug 2005
    Location
    Oslo, Norway
    Beans
    225

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    When I run this command on my up-to-date Breezy system, using your code from post #12, I get the following output:

    File "/usr/bin/ooo2-thumbnailer", line 21
    icon_names={"formula":"math","graphics":"draw","pr esentation":"impress","spreadsheet":"calc","text": "writer"}
    ^
    IndentationError: expected an indented block

  10. #30
    Join Date
    Nov 2004
    Location
    Prague, Czech Republic
    Beans
    68

    Re: HOWTO: Thumbnails for OpenOffice.org 2 files

    Corrected. There should be a tab at the start of line 21. I wonder where I lost it. Thanks magnusbb for noticing.

Page 3 of 11 FirstFirst 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •