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­k­am. But I think it might be useful for anyo­ne and thus deser­ves an artic­le 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 exam­p­le, need to send some files to someone else imme­dia­te­ly. They don’t have to be per­fect, should just be smal­ler. You could start your favou­ri­te 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­que­r­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­pared. This is done within seconds. Nea­to, 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­ri­te 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 accor­ding to your needs. I sug­gest you give them meaningful 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 exam­p­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 touch­ed, no stret­ching or dis­tort­ing whatsoe­ver – 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 ple­tho­ra of pos­si­ble appli­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 filena­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 filena­mes, but, for exam­p­le, underscores.
      This will in many other cases avo­id pro­blems too, for ins­tance when it comes to FTPing and alike…

Schreibe einen Kommentar