Xfce Forum

Sub domains
 

You are not logged in.

#1 2015-06-20 15:13:41

tryphon69
Member
Registered: 2015-06-20
Posts: 6

Nautilus-resize-image for Thunar

Hi,

Do you know a script who's doing like Nautilus-resize-image but for Thunar. I looked already on the web, but I didn't find anything who's running . Imagemagick and zenity are installed on my fedora.
For the scripts I try,I put them in a folder named script ( /home/script) and named them resize.sh. Then I create a custom action (in the "edit" menu of thunar). I enter /home/.../script/resize.sh f% as a command (actually, I dont know if %f is better than %F for that kind of script).

Can I modify the Nautilus-resize-image's script  to use it in Thunar? What changes must i do?

Offline

#2 2015-06-20 17:14:01

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,499

Re: Nautilus-resize-image for Thunar

tryphon69 wrote:

Can I modify the Nautilus-resize-image's script  to use it in Thunar? What changes must i do?

Perhaps you could post the Nautilus script for those who don't use Nautilus, if you'd like some input. Or, have a look at the resize images script and thunar action at this site - it also uses zenity and imagemagick.

EDIT: Okay, it's not a script but actually a nautilus extension: https://git.gnome.org/browse/nautilus-i … r/tree/src. This won't work in Thunar unless someone ports it over. If you're looking at just having a thunar custom action to resize images, have a look at the link I posted above.

Last edited by ToZ (2015-06-20 17:46:29)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2015-06-20 22:19:25

tryphon69
Member
Registered: 2015-06-20
Posts: 6

Re: Nautilus-resize-image for Thunar

Ok, here's the script :

#!/bin/bash

# paths, constants, etc.
PICPATH="$1"
TOTALPICS="$((($# - 1)))"
STEP="$(((100 / $TOTALPICS)))"
PROGR=0
MINSIZE=1
MAXSIZE=1000

# Check if ImageMagick commands are found
for command in convert identify
do
    if [ ! $(which $command) ]
    then
        zenity --error --text "Could not find \"$command\" application.\n
Make sure ImageMagick is installed and \"$command\" is executable."
        exit 1
    fi
done


# get the new size percentage, check it and set output directory path
SIZE=""
while [ -z "$SIZE" ] || [[ $SIZE -gt $MAXSIZE ]]; do
    SIZE="$(zenity --entry --title="Picture Resize" --text="Enter percentage...")"

    # exit if cancel pressed
    [[ $? != 0 ]] && exit 0

    # check range
    if [[ $SIZE -gt $MAXSIZE ]]; then
        zenity --error --text="$SIZE% is outside the accepted range: 1% - 1000%!"
    fi
done

# convert pics, show progress bar
while (( $# )); do
    convert "$PICPATH/$1" -resize "$SIZE%" -quality 95 -interlace line "$SIZE%-$1" 
    ((PROGR+=$STEP))
    echo $PROGR
    shift
done | zenity --progress --title="Picture Resize" --text="working..." --percentage=0 --auto-close

# check return value and print message depending on it
[[ $? == 0 ]] && zenity --info --title="Picture Resize" --text="All done!"|| zenity -
       -error --text="Canceled!" 

I try the script given on the website. It doesn't work for :
any value I give to percentage, I have an error message : "...% is outside the accepted range"
Do you know what's wrong on this script?

Last edited by tryphon69 (2015-06-23 11:53:38)

Offline

#4 2015-06-20 23:25:38

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,499

Re: Nautilus-resize-image for Thunar

tryphon69 wrote:

I try the script given on the website. It doesn't work for :
any value I give to percentage, I have an error message : "...% is outside the accepted range"
Do you know what's wrong on this script?

Yeah, just had a look. There is an error in the script. Try this version:

#!/bin/bash

# paths, constants, etc.
PICPATH="$1"
TOTALPICS="$((($# - 1)))"
STEP="$(((100 / $TOTALPICS)))"
PROGR=0
MINSIZE=1
MAXSIZE=1000

# get the new size percentage, check it and set output directory path
SIZE=""
while [ -z "$SIZE" ] || [[ $SIZE -gt $MAXSIZE ]]; do
    SIZE="$(zenity --entry --title="Picture Resize" --text="Enter percentage...")"

    # exit if cancel pressed
    [[ $? != 0 ]] && exit 0

    # check range
    if [[ $SIZE -gt $MAXSIZE ]]; then
        zenity --error --text="$SIZE% is outside the accepted range: 1% - 1000%!"
    fi
done

OUTPATH="resize_$SIZE%"

# check if output directory exists
[ -d "$PICPATH/$OUTPATH" ] || mkdir "$PICPATH/$OUTPATH"
shift

# convert pics, show progress bar
while (( $# )); do
    convert "$PICPATH/$1" -resize "$SIZE%" "$PICPATH/$OUTPATH/resized_$SIZE%-$1"
    ((PROGR+=$STEP))
    echo $PROGR
    shift
done | zenity --progress --title="Picture Resize" --text="working..." --percentage=0 -
                                 -auto-close

# check return value and print message depending on it
[[ $? == 0 ]] && zenity --info --title="Picture Resize" --text="All done!" || zenity -
       -error --text="Canceled!" 

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2015-06-21 18:47:46

tryphon69
Member
Registered: 2015-06-20
Posts: 6

Re: Nautilus-resize-image for Thunar

Thank you, works fine. I just change the script a little, to have the name like : x%-name and without a new folder

Offline

#6 2015-06-23 11:52:43

tryphon69
Member
Registered: 2015-06-20
Posts: 6

Re: Nautilus-resize-image for Thunar

I'm now looking to resize a picture with the size (not percentage). I try to modify the script above but I have troubles. Here's the script I try :

#!/bin/bash

# paths, constants, etc.
PICPATH="$1"
TOTALPICS="$((($# - 1)))"
STEP="$(((100 / $TOTALPICS)))"
PROGR=0
MINSIZE=12
MAXSIZE=2048

# Check if ImageMagick commands are found
for command in convert identify
do
    if [ ! $(which $command) ]
    then
        zenity --error --text "Could not find \"$command\" application.\n
Make sure ImageMagick is installed and \"$command\" is executable."
        exit 1
    fi
done


# get the new size, check it and set output directory path
SIZE=""
while [ -z "$SIZE" ] || [[ $SIZE -gt $MAXSIZE ]] || [[ $SIZE -gt $MINSIZE ]]; do
    SIZE="$(zenity --entry --title="Picture Resize" --text="Enter maximum size...")"

    # exit if cancel pressed
    [[ $? != 0 ]] && exit 0

    # check range max
    if [[ $SIZE -gt $MAXSIZE ]]; then
        zenity --error --text="$SIZE"px" is outside the accepted range: 12px - 2048px!"
    fi
done
	# check range min
    if [[ $SIZE -gt $MAXSIZE ]]; then
        zenity --error --text="$SIZE"px" is outside the accepted range: 12px - 2048px!"
    fi
done
# convert pics, show progress bar
while (( $# )); do
    convert "$PICPATH/$1" -resize "$SIZE" -quality 95 -interlace line "$SIZE"px"-$1"
    ((PROGR+=$STEP))
    echo $PROGR
    shift
done | zenity --progress --title="Picture Resize" --text="working..." --percentage=0 --auto-close

# check return value and print message depending on it
[[ $? == 0 ]] && zenity --info --title="Picture Resize" --text="All done!" || zenity -
       -error --text="Canceled!" 

My problems :
- the script doesn't work (when I enter a value, ce script asks me again to enter a value)
- When I enter a size smaller than 12px, the script halts (I have the error message for a bigger size, these part work)
-If I select more than one picture, I don't have these custom action, even if it works with the script above.

Offline

#7 2015-06-23 14:05:04

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,499

Re: Nautilus-resize-image for Thunar

You have a few problems with that script:

1. The first while script has 2 done statements.
2. If the size isn't fitting within the parameters, you're not resetting the SIZE string
3. You should move the gt/lt size checks later and reset size if its not in the range.

Try this version:

#!/bin/bash

# paths, constants, etc.
PICPATH="$1"
TOTALPICS="$((($# - 1)))"
STEP="$(((100 / $TOTALPICS)))"
PROGR=0
MINSIZE=12
MAXSIZE=2048

# Check if ImageMagick commands are found
for command in convert identify
do
    if [ ! $(which $command) ]
    then
        zenity --error --text "Could not find \"$command\" application.\n
Make sure ImageMagick is installed and \"$command\" is executable."
        exit 1
    fi
done


# get the new size and check it
SIZE=""
while [ -z "$SIZE" ]; do
    SIZE="$(zenity --entry --title="Picture Resize" --text="Enter maximum size...")"

    # exit if cancel pressed
    [[ $? != 0 ]] && exit 0

    # check range
    if [[ $SIZE -lt $MINSIZE ]] || [[ $SIZE -gt $MAXSIZE ]]; then
        zenity --error --text="$SIZE"px" is outside the accepted range: 12px - 2048px!"
        SIZE=""
    fi
done

# convert pics, show progress bar
while (( $# )); do
    convert "$PICPATH/$1" -resize "$SIZE" -quality 95 -interlace line "$SIZE"px"-$1"
    ((PROGR+=$STEP))
    echo $PROGR
    shift
done | zenity --progress --title="Picture Resize" --text="working..." --percentage=0 --auto-close

# check return value and print message depending on it
[[ $? == 0 ]] && zenity --info --title="Picture Resize" --text="All done!" || zenity -
       -error --text="Canceled!" 

Also, if your entered size value is the width of the new image, you should probably change the phrasing of the first dialog from "Enter maximum size..." to something more descriptive of what you're doing, like: "Enter new width (12-2048px) - aspect ratio will be maintained..."

Last edited by ToZ (2015-06-23 14:08:51)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#8 2015-06-23 20:53:22

tryphon69
Member
Registered: 2015-06-20
Posts: 6

Re: Nautilus-resize-image for Thunar

The second part of the script (checking the width range) is ok, it works well. I change the description of this part :
# Enter new width (12px-2048px) and check it - aspect ratio will be maintained...

The third part (converting picts), still not working :
- The script is running (I have the "All done text" with zenity), but the new picture is not created.

And I still have this problem : when I select more than one picture, the custom action does not appear on the right-click menu.

Offline

#9 2015-06-24 01:38:39

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,499

Re: Nautilus-resize-image for Thunar

In the custom action, make sure the command is set to:

/path/to/script %d %N

...where "/path/to/script" is the path and name of the script you created.
- %d = passes the directory name
- %N = passes the file names


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#10 2015-06-24 06:16:56

tryphon69
Member
Registered: 2015-06-20
Posts: 6

Re: Nautilus-resize-image for Thunar

Ok, it's working well. I had to log out once and then it work.

Here's the final script :

#!/bin/bash

# paths, constants, etc.
PICPATH="$1"
TOTALPICS="$((($# - 1)))"
STEP="$(((100 / $TOTALPICS)))"
PROGR=0
MINSIZE=12
MAXSIZE=2048

# Check if ImageMagick commands are found
for command in convert identify
do
    if [ ! $(which $command) ]
    then
        zenity --error --text "Could not find \"$command\" application.\n
Make sure ImageMagick is installed and \"$command\" is executable."
        exit 1
    fi
done


# Enter new width (12px-2048px) and check it - aspect ratio will be maintained...
SIZE=""
while [ -z "$SIZE" ]; do
    SIZE="$(zenity --entry --title="Picture Resize" --text="Enter maximum width...")"

    # exit if cancel pressed
    [[ $? != 0 ]] && exit 0

    # check range
    if [[ $SIZE -lt $MINSIZE ]] || [[ $SIZE -gt $MAXSIZE ]]; then
        zenity --error --text="$SIZE"px" is outside the accepted range: 12px - 2048px!"
        SIZE=""
    fi
done

# convert pics
while (( $# )); do
    convert "$PICPATH/$1" -resize "$SIZE" -quality 95 -interlace line "$SIZE"px"-$1"
    ((PROGR+=$STEP))
    echo $PROGR
    shift
   
#show progress bar
done | zenity --progress --title="Picture Resize" --text="working..." --percentage=0 --auto-close

# check return value and print message depending on it
[[ $? == 0 ]] && zenity --info --title="Picture Resize" --text="All done!" || zenity -
       -error --text="Canceled!" 

Thank you very much!

Offline

Registered users online in this topic: 0, guests: 1
[Bot] CCBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.010 seconds, 7 queries executed - Memory usage: 598.19 KiB (Peak: 615.03 KiB) ]