custom thumbnailer not working



Hi,
  I've been trying to write a custom thumbnailer for nautilus and I
can't understand why it is not working.  I am wondering if there is a
bug preventing it from working, can any body help me please :)

I added:
[Thumbnailer Entry]
TryExec=/full/path/to/my/script.py
Exec=/full/path/to/my/script.py %s %u %o
MimeType=application/gpvdm;

to the file:
/usr/share/thumbnailers/gpvdm.thumbnailer

/full/path/to/my/script.py  looks like this, which generates a
rectangle full of random colors:

#!/usr/bin/env python3
import os
import sys
import math
import cairo
import shutil
from PIL import Image
from io import BytesIO
from PIL import ImageDraw
import random

def gen_icon(path,icon_size):
    image = Image.new('RGBA',(icon_size,icon_size))
    draw = ImageDraw.Draw(image)

    for x in range(0,64):
        for y in range(0,64):

            r = random.randrange(255)
            g = random.randrange(255)
            b = random.randrange(255)
            a = random.randrange(255)

            draw.rectangle((x,y,x+1,y+1),fill=(r,g,b,a))

    image.save(path, "PNG")

if __name__ == '__main__':

    if len(sys.argv)>1:
        image_size=sys.argv[1]
        input_file=sys.argv[2]
        output_file=sys.argv[3]

        gen_icon(output_file,int(image_size))

    sys.exit(0)

When I refresh nutilus, the script spits out a correct looking thumbnail into:
/home/rod/.cache/thumbnails/large
I get no /home/rod/.cache/thumbnails/fail directory... so far so good.

BUT the thumbnail does not show in nautilus, no matter how many times
I refresh the window or close it/kill nautilus ect....  However when I
open up the thumbnail in gimp and click export to over write the
thumbnail, then refresh nautilus, the thumbnail suddenly appears in
nautilus. I've used 'identify -verbose' to examine a working png
thumbnail generated by a non custom thumbnailer and one generated from
my program and the output looks identical namely:
 Properties:
    date:create: 2018-10-30T21:22:53+00:00
    date:modify: 2018-10-30T21:22:53+00:00
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 6
    png:IHDR.color_type: 6 (RGBA)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 256, 256
    png:sRGB: intent=0 (Perceptual Intent)
    png:text: 3 tEXt/zTXt/iTXt chunks were found
    signature: 5adf30d72e1ba683c7c21c25fb44926d73f23fc4e18b719db5187ac4c362b265
    Software: GNOME::ThumbnailFactory
    Thumb::MTime: 1534174655

So, my question is, what is the difference between the png image I am
generating (which does not work) and the png images generated by the
internal thumbnailers which do work.  is this a bug or have I missed
something.

Thanks !
Rod


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]