jaspervdj / patat

Terminal-based presentations using Pandoc
GNU General Public License v2.0
2.42k stars 60 forks source link

Problem with image rendering using kitty #159

Open sebelk opened 9 months ago

sebelk commented 9 months ago

I have the following markdown:

---
patat:
  images:
    backend: auto
...

## test img inside kitty

![](/usr/share/icons/oxygen/256x256/places/start-here-kde-fedora.png)

I have the following error using kitty backend:

Failed to process : ImageMagick failed: Failed to identify image at path: /dev/shm/kitty-tty-graphics-protocol-3385452656 with error: Running the command: /usr/bin/magick identify -format {"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y","dispose":"%D","orientation":"%[EXIF:Orientation]"}, -- /dev/shm/kitty-tty-graphics-protocol-3385452656
Failed with error:
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.

If I run the kitty icat outside patat runs fine.

Versions: patat-0.9.2.0-1.fc39.x86_64 (OS: Fedora 39)

Please could you tell me if I'm missing something?

Thanks in advance

jaspervdj commented 9 months ago

Hi @sebelk! Thanks for creating this issue.

The markdown looks correct to me, so I wonder if it's something to do with the image, or some ImageMagick internals. If this were the case, it's weird that normal icat works fine though...

Could you try uploading the image here, as well as maybe trying a different image format?

jaspervdj commented 9 months ago

I see that patat is internally using kitty icat --transfer-mode=stream file.png. If you have time, could you try if using the transfer-mode argument is problematic outside of patat as well? That will narrow things down...

sebelk commented 9 months ago

@jaspervdj Thanks for your fast answer!

I've tested with at least 3 images that I attach below.

On all of those images kitty icat --transfer-mode=stream .... runs fine with no problems...

IANAP (I am not a programmer) :smiley: however I suspect that the issue is related to how 'patat' processes the output of the 'identify' command from ImageMagick.

Look at the complete error message:

Failed to process : ImageMagick failed: Failed to identify image at path: /dev/shm/kitty-tty-graphics-protocol-26013770 with error: Running the command: /usr/bin/magick identify -format {"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y","dispose":"%D","orientation":"%[EXIF:Orientation]"}, -- /dev/shm/kitty-tty-graphics-protocol-26013770
Failed with error:
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.

If you ran that command will fail, for example:

/usr/bin/magick identify -format {"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y","dispose":"%D","orientation":"%[EXIF:Orientation]"}, -- /usr/share/icons/oxygen/256x256/places/start-here-kde-fedora.png
identify: unrecognized color `%g,' @ warning/color.c/GetColorCompliance/1064.
identify: unable to open image 'transparency:%A,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
identify: unable to open image 'gap:%T,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: unable to open image 'gap:%T,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
identify: unable to open image 'index:%p,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: unable to open image 'index:%p,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
identify: unable to open image 'size:%wx%h,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: unable to open image 'size:%wx%h,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
identify: unable to open image 'dpi:%xx%y,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: unable to open image 'dpi:%xx%y,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
identify: unable to open image 'dispose:%D,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: unable to open image 'dispose:%D,': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
identify: unable to open image 'orientation:%[EXIF:Orientation],': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: unable to open image 'orientation:%[EXIF:Orientation],': No existe el fichero o el directorio @ error/blob.c/OpenBlob/3569.
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.
fmt:PNG,

Now let's quote commas:

/usr/bin/magick identify -format {"fmt":"%m"",""canvas":"%g"",""transparency":"%A"",""gap":"%T"",""index":"%p"",""size":"%wx%h"",""dpi":"%xx%y"",""dispose":"%D"",""orientation":"%[EXIF:Orientation]"}"," -- /usr/share/icons/oxygen/256x256/places/start-here-kde-fedora.png
identify: unknown image property "%[EXIF:Orientation]" @ warning/property.c/InterpretImageProperties/4213.
{fmt:PNG,canvas:256x256+0+0,transparency:Blend,gap:0,index:0,size:256x256,dpi:37.789999999999999147x37.789999999999999147,dispose:Undefined,orientation:},

And the ouput is much better :smiley:

And one more thing, if the path contains accents "n tilde" (~) it fails with a different error:

patat: readCreateProcess: kitty "+kitten" "icat" "--transfer-mode=stream" "--align=center" "~/Im\225genes/Wallpapers/43.jpg" (exit 1): failed

But with icat works fine:

kitty icat --transfer-mode=stream ~/Imágenes/Wallpapers/43.jpg > /dev/null

(No errors)

Could be an error in lib/Patat/Images/Kitty.hs ?

Thanks in advance!!

a)

start-here-kde-fedora

b)

screenshot

c)

43

jaspervdj commented 9 months ago

Yes, I think your intuition is right, and the issue with both the , and ~ may have something to do with these not being escaped correctly.

However, patat does not call ImageMagick at all -- kitty is calling ImageMagick internally instead. Maybe there is a way to avoid this issue, I'll try to reproduce it when I'm back from holidays.

krishjainx commented 6 months ago

@jaspervdj @sebelk , I've encountered an issue similar to what you have reported here. When trying to process images with ImageMagick, I receive the following error:

Failed to process : ImageMagick failed: Failed to identify image at path: /dev/shm/kitty-tty-graphics-protocol-1277450306 with error: Running the command: /usr/bin/magick identify -format {"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y","dispose":"%D","orientation":"%[EXIF:Orientation]"}, -- /dev/shm/kitty-tty-graphics-protocol-1277450306
Failed with error:
identify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746.

Interestingly, displaying images in Kitty using kitty icat --transfer-mode=stream image.jpg works fine. This issue arises when using the following markdown configuration in a .md file:

---
patat:
    images:
        backend:
            kitty
...

# A slide with only an image.

![](/home/krishjain/Downloads/image.jpg)

Thank you!