4

problem
I am able to load pictures with the Image() module in kivy. But for some reason, I can't load .tif files into kivy. When the image source is '..\pics\lugia.png', the image loads perfectly fine. But if the source is '..\pics\snorlax.tif', I just get that white box and the error:

[WARNING] [Image       ] Unable to load image <C:\Users\path\pics\snorlax.tif>
[ERROR  ] [Image       ] Error loading texture ..\pics\snorlax.tif

code

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.image import Image

class ContainerBox(BoxLayout):
    def __init__(self, **kwargs):
        super(ContainerBox, self).__init__(**kwargs)
        self.orientation = 'vertical'
        #self.picture = Image(allow_stretch=True, source='..\pics\lugia.png')
        self.picture = Image(allow_stretch=True, source='..\pics\snorlax.tif')
        Clock.schedule_once(lambda dt: self.add_widget(self.picture), timeout=0.1)


class SimpleImage(App):
    def build(self):
        return ContainerBox()

if __name__ == '__main__':
    SimpleImage().run()

technical details

  • The images are from veekun.com (property of nintendo etc).
  • All the images are 64 x 64. I just exported some of them into TIFF format. So image size shouldn't be the problem.
  • I am using Kivy version 1.11.0rc1
  • According to Anaconda, the virtual environment is running Python 3.5.6
  • I am running this via PyCharm on Windows 7
  • I have sdl2_image version 2.0.2 build 0. According to the sdl2_image page, sdl2_image has supported tiff since version 1.2.5.
  • I have libtiff version 4.0.9
  • changing the file extension from '.tif' to '.tiff'

my question to you
Am I doing something wrong, or does Kivy just not support TIFF format?

SuperKogito
  • 2,998
  • 3
  • 16
  • 37
wimworks
  • 283
  • 3
  • 15
  • Probably whatever image loader you're using doesn't support tiff, or at least doesn't have tiff support enabled. – inclement Sep 21 '19 at 21:57
  • It looks like the sdl2_image image provider can support tiff, so probably either you are not using that or (as above) it doesn't have that support enabled. – inclement Sep 21 '19 at 22:24
  • How do I even find out what image loader I'm using? – wimworks Sep 22 '19 at 06:03
  • It should be printed in the log. – inclement Sep 22 '19 at 10:33
  • The log shows `[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)`. I assume those are my image providers. How do I add one that supports tiff? – wimworks Sep 22 '19 at 16:41
  • I have sdl2_image version 2.0.2 build 0. According to [the sdl2_image page](https://www.libsdl.org/projects/SDL_image/), sdl2_image has supported tiff since version 1.2.5. – wimworks Sep 24 '19 at 00:55
  • @FergusWyrm share the tiff – eyllanesc Sep 24 '19 at 03:09
  • @eyllanesc here's [snorlax.tif](https://drive.google.com/file/d/14wkJzDo3HpSB2Dyx2JzNmbGjY0vcwq57/view) and [salamence.tiff](https://drive.google.com/file/d/1NwpeXF3SIILNbAHy6VNIyhfXXHJm5HWU/view). Both pictures result in the same error. CCITT_1.TIF from [this site](https://www.fileformat.info/format/tiff/sample/index.htm) doesn't work either. – wimworks Sep 25 '19 at 20:12
  • 1
    I am able to load both (*tif(f)*) files using your code (after a few warning message boxes pop up), while *CCITT\_1* works fine. *Python 3.7.3* and *Kivy 1.10.1* (*sdl* (*kivy.deps.sdl2 0.1.18*) and all dependencies installed by *pip*, as instructed in the *Kivy* web page) on *Win*. I noticed you're using a *rc\** version. You should upgrade to an official released one. Also, double the *bkslash*es in paths (`source='..\\pics\\snorlax.tif'`), or use *raw* strings (not the root cause here, but it might generate problems). – CristiFati Sep 26 '19 at 21:33
  • This works for me also on Mac, Providers: img_tex, img_imageio, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored) and sdl2 was used. – Hezi Shahmoon Sep 27 '19 at 15:56
  • @CristiFati It sounds like my wonky installation is to blame for this. I've been trying to use anaconda to keep all installations in virtual environments. – wimworks Sep 27 '19 at 21:41
  • Can't reproduce your bug. Using: Python 3.5.1 on OSX, Kivy 1.11.1. Providers: img_tex, img_imageio, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored). Using *pip* on a virtualenv. The window shows snorlax correctly. – Laurent LAPORTE Sep 28 '19 at 18:25
  • I made a new python virtual environment with venv, installed kivy following the official guide, and got it running. It can view tiff files now (although I'm getting `TIFFReadDirectory` Warnings, but that's a separate issue). – wimworks Sep 29 '19 at 00:47

1 Answers1

2

You need to create a proper installation
I used anaconda to install kivy and I wasn't very thorough with installing the dependencies properly. So I had to create a fresh virtual python installation.

Note: This is for python version 3.5 or higher. Also I am going to have you explicitly state what python installation is going to be creating this environment. To my knowledge, there's no good reason to do this.

Windows

  1. (optional) find where python is installed for you.
    Start windows command prompt.
    C:\Users\H>python
    import sys, os
    os.path.dirname(sys.executable)
    C:\Users\H\AppData\Local\Programs\Python\Python36
    therefore, my python installation is at C:\Users\H\AppData\Local\Programs\Python\Python36\python
  2. Prepare a place for your new virtual environment.
    I created a folder called "venvs" in my home directory.
    C:\Users\H\venvs
  3. Create new virtual environment. I'll name mine "env1".
    Start windows command prompt.
    if you did step 1
    C:\Users\H>C:\Users\H\AppData\Local\Programs\Python\Python36\python -m venv C:\Users\H\venvs\env1
    if you did not do step 1
    C:\Users\H>python -m venv C:\Users\H\venvs\env1
  4. Activate the new virtual environment
    C:\Users\H>C:\Users\H\venvs\env1\Scripts\activate
  5. Install dependencies
    (env1) C:\Users\H>python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.22 kivy_deps.glew==0.1.12
  6. Install kivy
    (env1) C:\Users\H>python -m pip install kivy==1.11.1
  7. PyCharm
    If you're using PyCharm, go to File>Settings
    From the settings menu Project>Project Interpreter
    Click the gear>Add
    In the Add Python Interpreter menu select 'Existing environment', then set the interpreter to the location of your new virtual environment.
    Mine was C:\Users\H\venvs\env1\Scripts\python.exe.
    Click Okay. Hit Apply in the settings menu. Once you hit okay, your script should be able to view TIFF files.
wimworks
  • 283
  • 3
  • 15