Jump to content

[linux] Converting jp2 files


zeppeliner

Recommended Posts

Posted

Script that converts jp2 files to png files, then deletes all jp2 files. It requires to work properly imagemagick package.

#!/bin/bash
    haveExtension () # this function returns the position of the first period it encounters (counting backwards), if it fails to find such a character, it prints -1
    {
        for (( i=$((${#1}-1)); i>-1; i--)) # od rozmiaru tekstu do -1 wykonuj
        do
            if [ "${1:$i:1}" = '.' ] # if a dot character is searched for at the given position, then
            then
                echo $i; # view its location
                return; # and the end of the function will be
            fi
        done
        echo -1; # and if not, return -1
    }

    getFileName () # this function returns the file name (without the extension)
    {
        filename=$(basename "$1"); 
        extPos=$(haveExtension "$filename"); 
        echo ${filename:0:$extPos}; 
    }

    

    for i in *.jp2; 
    do
        echo "Processing file: $i" 
        convert "$i" -quality 100 "$(getFileName "$i").png" 
    done

    for i in *.jp2; 
    do
        echo "Deleting file: $i" 
        rm -f "$i" 
    done

 

  • 1 month later...
Posted

KDE Dolphin service menu desktop file.

${HOME}/.local/share/kservices5/ServiceMenus/jp2png.desktop

 

[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=image/jp2;
Icon=autocorrection
X-KDE-Priority=TopLevel
X-KDE-StartupNotify=false
X-KDE-Submenu=Convert

Actions=Convert;

[Desktop Action Convert]
Name=Convert to PNG
Icon=image-png
Exec=filename=%f; ffmpeg -i "${filename}" "${filename%.*}.png"

 

It requires to work properly ffmpeg package.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...