NikitaIvanovV / ctpv

Image previews for lf file manager
https://www.nikitaivanov.com/man1/ctpv
MIT License
264 stars 23 forks source link

Books in djvu format creates high use of system resources #54

Open poeplva opened 1 year ago

poeplva commented 1 year ago

I have a book in djvu format, when I come over it in lf the memory and CPU utilizations gets very high. Checking top while doing this shows that the program that causes this is magick. So what happens is, ctpv thinks djvu files are image files (which is correct and what file --mime-type says) and tries to process them for a preview with ImageMagick. But since the file is 945 pages, it is of course a huge amount of work for ImageMagick. So I think we should find another method to produce previews for djvu files as they are a common format for (especially old) books.

poeplva commented 1 year ago
preview dejavu image/vnd.djvu {{
    tmpfilejpeg="/tmp/ctpv-$RANDOM.jpeg"
    trap "rm -f $tmpfilejpeg" 0 2 3 15
    djvused "$f" -e 'select 1; save-page /dev/stdout' | convert -density 300 - "$tmpfilejpeg" > /dev/null 2>&1
    ctpv "$tmpfilejpeg" $w $h $x $y $id
    exit 1
}}

Here is a way to do this via changing the config, but it seems to be a little bit slower than previews for pdfs. Yet, I still think this should be the default way in the program.

siyia2 commented 4 months ago

thx! i added this:

preview dejavu image/vnd.djvu {{
    tmpfilejpeg="/tmp/ctpv-$RANDOM.jpeg"
    trap "rm -f $tmpfilejpeg" 0 2 3 15
    djvused "$f" -e 'select 1; save-page /dev/stdout' | convert -density 300 - "$tmpfilejpeg" > /dev/null 2>&1
    ctpv "$tmpfilejpeg" $w $h $x $y $id
    exit 1
}}

to ~/.config/ctpv/config and .djvu previews work now!