I’m currently re-writing a good chunk of the weather script to take info from the BBC instead of Yahoo. So far, so good. It’s mostly working, has a lot more options for info and is broadly working, with the exception of a few tweaks.
My main problem is self inflicted but if I can solve it, should help others too.
That’s the weird thing, I’m doing exactly that. I have the chequered background. The resulting file looks right in Windows, Raspbian, Web browsers, etc. etc. Look closer at the white square on my cloud, you can see in the corners that some of it is becoming transparent. Also note that the square is black before I delete it and the cloud is white. Something is causing the black and white to invert. If I don’t use the alpha channel, the image is correct but without transparency. If use the alpha channel and I colour the cloud red in GIMP, it comes up coloured on the inky phat but with the background still white.
Behaviour and result is the same in GIMP 2.10 in Windows and GIMP 2.8 in Raspbian.
Re. export settings:
PNG obviously
Interlacing unticked
Save background colour ticked
save gamma unticked
save layer offset unticked
save resolution ticked
save creation time ticked
save comment greyed out
save colour values from transparent pixels tocked
compression level 9
One more thing, if I simply open and then export the stock cloud, it breaks also.
Notice the top left and bottom left pixels seem to be transparent…
Thank you Sven. I’m always open to new ideas and methods. I don’t think it’s that though. It’s something to do with how GIMP is encoding the alpha channel and PIL is processing it. I’m wondering if I’m somehow choosing some wrong settings when exporting it?
One thing I tried last night was to entirely remove the alpha channel. Same image, just no alpha channel. It displayed fine, correct colours but without any transparency of course.
I’ve concluded it’s something to do with GIMP and how it’s exporting the PNGs with alpha channels. I’ve instead created a modified inky pallette with a 4th colour (green). Areas to be transparent are coloured green. The image is then exported as is, without an alpha channel. I’ve then written a short python script which opens and resaves the image with the green denoted as transparency. This then works with the inky phat.
I will finish off the script later and post it here with instructions when it’s ready.
This will give a 4th colour of green. This won’t be used by the inky phat but should be used later to mark areas to be transparent.
Now go to the ‘Windows’ menu, ‘Dockable Dialogs’, then Palettes.
Right click on any palette on the right, then click 'Import Palette.
Select ‘Palette File’ then click the little folder icon and use the ‘Select Palette File’ dialogue to load your new palette file.
You should see white, black, red, green then all the rest white.
Click Import and the select your new palette on the right.
Now go to the ‘Image’ menu, then ‘Mode’, and select ‘Indexed’.
Select ‘Use custom palette’, then click the ‘Palette selection dialogue’ button just underneath (square button looks like a palette preview) and select your newly loaded inky-palette.gpl. It should still show the 4 colours above.
Untick ‘Remove unused and duplicate colors from colormap’
Click ‘Convert’
Ensure there’s no alpha channel by going to the ‘Layer’ menu, then ‘Transparency’, and selecting ‘Remove Alpha Channel’. This will be unavailable if no alpha channel is present.
Finally click ‘File’, ‘Export As…’ and save your png file. I suggest saving it in a new folder so you don’t accidentally process other images in the next step.
Create a new python script with the following code and save it in the same folder as your image(s)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PIL import Image
import glob
# Load our icon files and convert green to transparency
for icon in glob.glob("icon-*.png"):
im = Image.open(icon)
im.save(icon, transparency = 3, optimize = 1)
When you run this, it simply opens the image, then saves it with colour index 3 (green of 0,1,2,3) as transparency.
This then works with the Python Image Library where the GIMP transparency doesn’t.