How to convert photos from within Dolphin or Konqueror

Well, this is actual­ly a spin­off-pro­duct from my effort to com­pen­sa­te a flaw of Digi­kam. But I think it might be use­ful for anyo­ne and thus deser­ves an arti­cle of its own.

Ima­gi­ne you have a fol­der with some pics in it – as they came off your chip or from the came­ra. You are in a hur­ry and, for examp­le, need to send some files to someo­ne else immedia­te­ly. They don’t have to be per­fect, should just be smal­ler. You could start your favou­rite image-edi­tor, load the photo(s), crop them and save them again. But this takes some time.

This is whe­re my solu­ti­on comes in handy.

You open Dol­phin or Kon­quer­or, mark the respec­ti­ve files with the mou­se, right-click, choo­se Actions and start one of the actions you’­ve pre­pa­red. This is done wit­hin seconds. Neato, right? 😉
This is how to do it.
The actions in Dolphin/Konqueror are con­trol­led by files with the ending .desk­top, which resi­de in ~/.kde4/share/kde/services. The­se are simp­le text­files, which can be edi­ted with your favou­rite edi­tor – nano, tea, kwri­te, kate, leafpad…

So we need to crea­te some more of the­se files. You can sim­ply copy/paste mine and chan­ge them accord­ing to your needs. I sug­gest you give them mea­ning­ful names. So an action that would resi­ze a pho­to to 800px on the lon­gest side, chan­ge the dpi/lpi to 72 and save the new file as jpg with 75% qua­li­ty, should be named some­thing like for examp­le convert_800_72_jpg_75.desktop.

The­se are the templates.

Crea­tes 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

Crea­tes 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

Crea­tes a jpg, por­trait, 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 actu­al action. This is whe­re you have to chan­ge values if you want to adopt the script.

Now let’s do some­thing more complex…

Detail of an old cottage
Detail of an old cottage.

Crea­tes a jpg, 800px wide, 72 dpi, 75% AND adds an even bor­der 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

Noti­ce that I used ›con­vert‹ and not ›mogri­fy‹ from the image­ma­gick-suite in all examp­les, as the for­mer crea­tes a new file, whe­re­as the lat­ter over­wri­tes the original.
The com­mand takes all for­mats as input that image­ma­gick knows about. The out­put is always .jpg – unless you chan­ge that.

The aspect ratio is not touched, no stret­ching or dis­tor­ting whatsoever – unless you chan­ge that.

Of cour­se you need to have image­ma­gick instal­led. ›man con­vert‹ and/or ›man mogri­fy‹ will show you what is pos­si­ble. It is a lot, I assu­re you 😉

The­re is a pletho­ra of pos­si­ble app­li­ca­ti­ons. I have only begun to dis­co­ver the pos­si­bi­li­ties mys­elf. Here you’ll find an awe­so­me gui­de with many examples.

Have fun! And if you have ques­ti­ons, I’ll try to help.

3 Kommentare

  • very good script but it doesnt accept file­na­mes con­tai­ning blanks. could you add this?

    • Cer­tain­ly, but I did not try.

      And I am hesi­tant as well, becau­se I’d always recom­mend not to use blanks in file­na­mes, but, for examp­le, underscores.
      This will in many other cases avoid pro­blems too, for instance when it comes to FTPing and alike…

Schreibe einen Kommentar