How to convert photos from within Dolphin or Konqueror

 

Well, this is actually a spinoff-product from my effort to compensate a flaw of Digikam. But I think it might be useful for anyone and thus deserves an article of its own.

Imagine you have a folder with some pics in it – as they came off your chip or from the camera. You are in a hurry and, for example, need to send some files to someone else immediately. They don’t have to be perfect, should just be smaller. You could start your favourite image-editor, load the photo(s), crop them and  save them again. But this takes some time.

This is where my solution comes in handy.

You open Dolphin or Konqueror, mark the respective files with the mouse, right-click, choose Actions and start one of the actions you’ve prepared. This is done within seconds. Neato, right? 😉
This is how to do it.
The actions in Dolphin/Konqueror are controlled by files with the ending .desktop, which reside in ~/.kde4/share/kde/services. These are simple textfiles, which can be edited with your favourite editor – nano, tea, kwrite, kate, leafpad…

So we need to create some more of these files. You can simply copy/paste mine and change them according to your needs. I suggest you give them meaningful names. So an action that would resize a photo to 800px on the longest side, change the dpi/lpi to 72 and save the new file as jpg with 75% quality, should be named something like for example convert_800_72_jpg_75.desktop.

These are the templates.

Creates a jpg, 1000px wide, 72 dpi, 75%

[Desktop Entry]
MimeType=image/*
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
Actions=reSize_1000_72_75_jpg
[Desktop Action reSize_1000_72_75_jpg]
Name=Skalieren auf 1000px 72dpi 75% jpg
Icon=/usr/share/icons/default.kde4/32x32/actions/transform-scale.png
Exec=for i in %U; do convert $i -resize 1000x1000 -density 72 -quality 75 $(echo $i | cut -f1 -d".")_1000_72.jpg && kdialog --title "Resize" --passivepopup "$i wurde bearbeitet" 5; done
Terminal=false

Creates a jpg, 800px wide, 72 dpi, 75%

[Desktop Entry]
MimeType=image/*
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
Actions=reSize_800_72_jpg
[Desktop Action reSize_800_72_jpg]
Name=Skalieren auf 800px 72dpi 75% jpg
Icon=/usr/share/icons/default.kde4/32x32/actions/transform-scale.png
Exec=for i in %U; do convert $i -resize 800x800 -density 72 -quality 75 $(echo $i | cut -f1 -d".")_800_72.jpg && kdialog --title "Resize" --passivepopup "$i wurde bearbeitet" 5; done
Terminal=false

Creates a jpg, portrait, 600px high, 72 dpi, 75%, and strips off all exif-data

[Desktop Entry]
MimeType=image/*
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
Actions=reSize_600h_72_75_jpg
[Desktop Action reSize_600h_72_75_jpg]
Name=Skalieren Hochformat auf 600px 72dpi 75%
Icon=/usr/share/icons/default.kde4/32x32/actions/transform-scale.png
Exec=for i in %U; do convert $i -resize x600 -density 72 -quality 75 -strip $(echo $i | cut -f1 -d".")_600h_72.jpg && kdialog --title "Resize" --passivepopup "$i wurde bearbeitet" 5; done
Terminal=false

Name= is the name of the action, as you see it in the menu – here in german.
Exec= is the actual action. This is where you have to change values if you want to adopt the script.

Now let’s do something more complex…

Detail of an old cottage
Detail of an old cottage.

Creates a jpg, 800px wide, 72 dpi, 75% AND adds an even border of 22px in white AND adds my name to the lower right corner

[Desktop Entry]
MimeType=image/*
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
Actions=reSize_800_72_jpg_frame
[Desktop Action reSize_800_72_jpg_frame]
Name=Skalieren als jpg auf 800px 72dpi 75% mit Rahmen und Signatur
Icon=/usr/share/icons/default.kde4/32x32/actions/transform-scale.png
Exec=for i in %U; do convert $i -resize 800x800 -density 72 -quality 75 -gravity southeast -annotate 0 '© Michael Kaiser' -mattecolor "#ffffff" -frame 22 $(echo $i | cut -f1 -d".")_800_72.jpg && kdialog --title "Resize" --passivepopup "$i wurde bearbeitet" 5; done
Terminal=false

Notice that I used ‘convert’ and not ‘mogrify’ from the imagemagick-suite in all examples, as the former creates a new file, whereas the latter overwrites the original.
The command takes all formats as input that imagemagick knows about. The output is always .jpg – unless you change that.

The aspect ratio is not touched, no stretching or distorting whatsoever – unless you change that.

Of course you need to have imagemagick installed. ‘man convert’ and/or ‘man mogrify’ will show you what is possible. It is a lot, I assure you 😉

There is a plethora of possible applications. I have only begun to discover the possibilities myself. Here you’ll find an awesome guide with many examples.

Have fun! And if you have questions, I’ll try to help.

3 Kommentare

  • very good script but it doesnt accept filenames containing blanks. could you add this?

    • Certainly, but I did not try.

      And I am hesitant as well, because I’d always recommend not to use blanks in filenames, but, for example, underscores.
      This will in many other cases avoid problems too, for instance when it comes to FTPing and alike…

Schreibe einen Kommentar