26 Dec 2013, 12:25pm

leave a comment

  • Anzeige
  • Scale images for the web — quickly

    Start­ing Gimp just to scale down some pho­tos to send them by mail? Meh.
    How about mark them, right-click, “Send To” -> “Scale for web”?
    No prob­lemo:
    First, get a tool to scale images:

    sudo apt-get install imagemagick

    Now, cre­ate a script that takes a list of images as input, scales them down, and stores them with a pre­fixed file name. Go!

    pwd > ~/f0.txt
    echo "$@" > ~/f1.txt
    for file in $@
    	convert "$file" -quality 50 -resize 1024x768 "${file%/*}/web-${file##*/}"

    Make sure we chmod +x the script file we just cre­ated.
    Next, let’s inte­grate it into “Send To”. (This is an exam­ple for Thu­nar)
    Cre­ate a .desktop file in the sendto folder, e.g. /usr/share/Thunar/sendto/scale-for-web.desktop with fol­low­ing content:

    # Scale images for the web
    [Desktop Entry]
    Exec=scale-for-web %F
    Name=Scale for the web

    Replace both scale-for-web with the name you gave to your script file. Is the script’s folder in $PATH? No idea? Then just put the entire path+filename.
    Now, open Thu­nar, select some images (Jpeg or Png), right-click, “Send To” -> “Scale for the web”, wait a few sec­onds and you’ll see web-....jpg files appear­ing in the same folder. :)

    Ref­er­ences: how to scale images with imageMag­ick, extract path seg­ments, more details on string manipulation



    web site

    leave a comment