Results 1 to 5 of 5

Thread: Nautilus script to convert image types (and convert question)?

  1. #1
    Join Date
    Mar 2007
    Location
    $HOME (Washington State)
    Beans
    4,590

    Nautilus script to convert image types (and convert question)?

    I was wondering if there was a nautilus script for converting image types. This would be a great help for me. Also, if not, is there a way to use the convert tool on imagemagick to convert several images to PNG while keeping their origional filename (the part be for the .* part). Thanks for the help!
    See my themes here! | Dont preach Linux, mention it | Make GNOME Themes
    I'm no longer on here. If you want to talk to me, go to noost.org.
    My DeviantArt | Linux user #461096 | Ubuntu user #15753

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Nautilus script to convert image types (and convert question)?

    It's not too hard to make such a script. Here's an example script
    Code:
    #!/bin/bash
    
    scriptname=`basename $0`
    # Determine image type to convert to based on the name of the script
    newext=`echo $scriptname | sed 's/convert.to.\(.\+\)/.\1/'`
    logfile=`mktemp -t $script_name.XXXXXX`
    
    tail -f $logfile | zenity --text-info --title="Converting images to $newext" &
    for image in "$@"; do
        # Determine target image name
        target=$(echo $image|sed 's/\(.*\)\..\+/\1/')$newext
        echo "$image -> $target" >> $logfile
        convert "$image" "$target"
    done
    
    echo done >> $logfile
    rm -f $logfile
    If you save this script as ~/.gnome2/nautilus-scripts/convert_to_png you will be able to select several images in nautilus, and convert them to png. foo.jpg will be converted to foo.png (was this what you meant by keeping the original filename?)

    The script decides what filetype to convert to based on the script's name, so making symlinks for other image types will let you use the same script. i.e.
    Code:
    cd ~/.gnome2/nautilus-scripts/
    ln -s convert_to_png convert_to_jpg
    ln -s convert_to_png convert_to_gif
    With the above symlinks, you can convert to jpg and gif as well.

  3. #3
    Join Date
    Mar 2007
    Location
    $HOME (Washington State)
    Beans
    4,590

    Re: Nautilus script to convert image types (and convert question)?

    Quote Originally Posted by geirha View Post
    It's not too hard to make such a script. Here's an example script
    Code:
    #!/bin/bash
    
    scriptname=`basename $0`
    # Determine image type to convert to based on the name of the script
    newext=`echo $scriptname | sed 's/convert.to.\(.\+\)/.\1/'`
    logfile=`mktemp -t $script_name.XXXXXX`
    
    tail -f $logfile | zenity --text-info --title="Converting images to $newext" &
    for image in "$@"; do
        # Determine target image name
        target=$(echo $image|sed 's/\(.*\)\..\+/\1/')$newext
        echo "$image -> $target" >> $logfile
        convert "$image" "$target"
    done
    
    echo done >> $logfile
    rm -f $logfile
    If you save this script as ~/.gnome2/nautilus-scripts/convert_to_png you will be able to select several images in nautilus, and convert them to png. foo.jpg will be converted to foo.png (was this what you meant by keeping the original filename?)

    The script decides what filetype to convert to based on the script's name, so making symlinks for other image types will let you use the same script. i.e.
    Code:
    cd ~/.gnome2/nautilus-scripts/
    ln -s convert_to_png convert_to_jpg
    ln -s convert_to_png convert_to_gif
    With the above symlinks, you can convert to jpg and gif as well.
    That is what I meant by keeping the origional filename, and thanks for the script, I will try it out!
    See my themes here! | Dont preach Linux, mention it | Make GNOME Themes
    I'm no longer on here. If you want to talk to me, go to noost.org.
    My DeviantArt | Linux user #461096 | Ubuntu user #15753

  4. #4
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Nautilus script to convert image types (and convert question)?

    Note that it if you convert foo.jpg to foo.png, and foo.png allready exist, it will overwrite it without asking. If you know a little bash scripting, it's easy to add a little check for that though.

  5. #5
    Join Date
    Mar 2007
    Location
    $HOME (Washington State)
    Beans
    4,590

    Re: Nautilus script to convert image types (and convert question)?

    Unfortunately, I know very little bash scripting, but this script works great! I just converted a whole bunch of windows icons to png.
    See my themes here! | Dont preach Linux, mention it | Make GNOME Themes
    I'm no longer on here. If you want to talk to me, go to noost.org.
    My DeviantArt | Linux user #461096 | Ubuntu user #15753

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •