SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-11-10 16:47:13

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

[ Tip ] Quick resizing of images in Thunar

The topic came up quite by accident in Ubuntu vs Crunchbang. Anonymous provided the link.

    http://customisinglife.wordpress.com/20 … -pictures/

I am a photographer that was in need of a quick way to resize images for uploading proofs to my server.
Nautilus had this sort of thing. However I don't like Nautilus and wanted a way to do this in Thunar.
   
This is what I came up with using the model from the link above.
Three scripts that will size to 640, 800, 1024 and place them nice and neat in cwd.
This will work with multiple images.
So no need for Nautilus anymore as that was the only thing I used it for. smile

Perhaps these scripts will be useful to someone here. Modify to taste.

1.
#!/bin/sh
# Name rez640

mkdir -p ./Resized/640
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry 640×640 -quality 100 $file ./Resized/640/${name}_640.jpg
done

2.
#!/bin/sh
# Name rez800

mkdir -p ./Resized/800
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry 800×800 -quality 100 $file ./Resized/800/${name}_800.jpg
done

3.
#!/bin/sh
# Name rez1024

mkdir -p ./Resized/1024
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry 1024×1024 -quality 100 $file ./Resized/1024/${name}_1024.jpg
done

Last edited by aicardi (2009-11-10 18:07:20)


--
aicardi

Offline

Be excellent to each other!

#2 2009-11-10 17:03:59

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

why not something like

#!/bin/sh

mkdir -p ./Resized/$1
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg
done

wouldn't it be more flexible?


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#3 2009-11-10 17:08:48

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:

why not something like

#!/bin/sh

mkdir -p ./Resized/$1
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg
done

wouldn't it be more flexible?

Will this create respective folders with respective sizes? I use three sizes.
I will certainly test it now.


--
aicardi

Offline

#4 2009-11-10 17:14:22

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

it needs modifying a bit

'for file' will loop through the size argument aswell at the mo.


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#5 2009-11-10 17:17:47

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

aicardi wrote:
benj1 wrote:

why not something like

#!/bin/sh

mkdir -p ./Resized/$1
for file
do
name=`echo $file | cut -f1 -d.`
convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg
done

wouldn't it be more flexible?

Will this create respective folders with respective sizes? I use three sizes.
I will certainly test it now.

This did not work.
What I needed was an action that resizes to specific sizes. I use 3 sizes. 640, 800, 1024
I have an action for each.
When I select say 640 it creates the Resized folder in cwd (unless it is already there) as well as the 640 folder (unless it is already there)
and puts the resized image in the folder.
Same thing with each size.
So I end up with ./Resized/ 640 800 and 1024

Last edited by aicardi (2009-11-10 18:58:56)


--
aicardi

Offline

#6 2009-11-10 17:28:00

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:

it needs modifying a bit

'for file' will loop through the size argument aswell at the mo.

Yes. But the way it is now when I highlight an image or many images in Thunar and right click all I have to do is select the size I want and its done. I have three actions.
1 640
2 800
3 1024

Each end up in the respective folder in Resized with the respective *_640.jpg, *_800.jpg, *_1024.jpg
Makes it easy for me to know what size an image is by the filename.


--
aicardi

Offline

#7 2009-11-10 19:02:28

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 12,486

Re: [ Tip ] Quick resizing of images in Thunar

Does resize retain the images' original aspect ratios, or are you importing square images?


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#8 2009-11-10 19:05:32

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

pvsage wrote:

Does resize retain the images' original aspect ratios, or are you importing square images?

I am importing both. The reason for 640x640 instead of 640x480 for example is that it keeps the "long" side of the image at 640 be it landscape or portrait.

So the answer is yes to both.

Last edited by aicardi (2009-11-10 19:06:29)


--
aicardi

Offline

#9 2009-11-10 19:17:43

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 12,486

Re: [ Tip ] Quick resizing of images in Thunar

Well, then this will come in handy; I'm trying to come up with a bash script that handles LastFM artist images a bit more elegantly than Python's resize command.


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#10 2009-11-10 19:21:01

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

pvsage wrote:

Well, then this will come in handy; I'm trying to come up with a bash script that handles LastFM artist images a bit more elegantly than Python's resize command.

I hope it helps. It works very effectively for my needs. Try one and see. Let me know the outcome please.


--
aicardi

Offline

#11 2009-11-10 21:02:26

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

@ aikardi

its up to you, it depends what you want it for for, i would personally have the one script and just call it with different arguments then have three different scripts then in the custom actions, it isn't any harder to setup
eg
resize-640 command would be 'resize 640 %F'
instead of
resize-640 being 'resize_640 %F'

Last edited by benj1 (2009-11-10 21:02:56)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#12 2009-11-10 21:10:56

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:

@ aikardi

its up to you, it depends what you want it for for, i would personally have the one script and just call it with different arguments then have three different scripts then in the custom actions, it isn't any harder to setup
eg
resize-640 command would be 'resize 640 %F'
instead of
resize-640 being 'resize_640 %F'

I'm not sure exactly how I would call the different args if it is a action in Thunar. I can see that if I were running it from command line.
Right now what I have when I right click a jpg in Thunar is a choice of three  640 which calls that script, 800 which calls that script.
I don't always do all three and I do want a new folder in cwd with the respective folders of each size.

In short- I just don't know how to write the single script to be used as a Thunar action that will know which I want.

Hey- I'm just happy as a clown that I got something to do what I want and need. May not be the most elegant way but it does work well.

Last edited by aicardi (2009-11-10 21:14:18)


--
aicardi

Offline

#13 2009-11-10 21:37:14

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 12,486

Re: [ Tip ] Quick resizing of images in Thunar

@aicardi - once I figure out how to pass info to and from the LastFM API within a bash script I'll take a crack at it.  I think it boils down to translating the lastfm part of iggykoopa's conkymusic.py script to bash.


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#14 2009-11-10 21:37:47

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

#!/bin/sh                                                                                                   

mkdir -p ./Resized/$1             
for file
    do
    if [ ! -e "$file" ]
        then
        continue
    fi
    name=$( echo $file | cut -f1 -d.)
    convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg
done

should work, (i get errors with the geometry option, but i get that with yours aswell)
'if' tests if the file exists ie if its our size option, and starts loop on next arg (the file) if it is.
$1 is the size so it makes the correct directory (on line 3) and inserts it everywhere else.

then commands for the custom actions would be 'resize 640 %F' for size 640x640 etc etc, assuming you call the script 'resize'

Last edited by benj1 (2009-11-10 21:38:10)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#15 2009-11-10 21:39:30

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

pvsage wrote:

@aicardi - once I figure out how to pass info to and from the LastFM API within a bash script I'll take a crack at it.  I think it boils down to translating the lastfm part of iggykoopa's conkymusic.py script to bash.

I know nothing about that. smile


--
aicardi

Offline

#16 2009-11-10 21:51:01

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:
#!/bin/sh                                                                                                   

mkdir -p ./Resized/$1             
for file
    do
    if [ ! -e "$file" ]
        then
        continue
    fi
    name=$( echo $file | cut -f1 -d.)
    convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg
done

should work, (i get errors with the geometry option, but i get that with yours aswell)
'if' tests if the file exists ie if its our size option, and starts loop on next arg (the file) if it is.
$1 is the size so it makes the correct directory (on line 3) and inserts it everywhere else.

then commands for the custom actions would be 'resize 640 %F' for size 640x640 etc etc, assuming you call the script 'resize'

I dont get the errors. The 640x640 for example simply makes the long side of the image 640 be it landscape or portrait. Or square.

I do have only the three scripts. I created three actions in Thunar. One named 640. This action calls on the rez640 script (that is what I named it).
The end of the script "_640" simply tacs on the _640 to the filename.  eg image.jpg to image_640.jpg The image ends up in a folder named 640 within the Resized dir.
The other action calls on the rez800 script which does the same thing. Creates a folder within Resized and places the newly resized image in a folder named 800.
The file has _800 appended to it. eg image.jpg to image_800.jpg.

This way I don't need the extra script to call on anything. The action calls on the script I want.
Does this babble make sense? smile

This is what I have in the command for the Thunar action to resize to 640.
/home/anthony/.config/Thunar/scripts/rsz640 %N
This is what I have as the file pattern in the Thunar actions Appearance Conditions
*.jpg;*.JPG;*.jpeg;*JPEG
I have Image files ticked in Appears if selection contains.

Last edited by aicardi (2009-11-10 22:20:08)


--
aicardi

Offline

#17 2009-11-10 22:29:44

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

(well if it works for you thats great, different versions maybe?)

anyway you dont need an extra script, you needs 2 less.

at the moment you have 3 scripts.
rez640,rez800,rez1024

so presumably your command in the context menu in thunar 'edit-->configure custom actions-->edit currently selected action (button on right)'will be

'rez640 %F' etc etc.

instead of that just use

'rez 640 %F' (notice the space, you are handing it an argument of 640) etc etc.
EDIT: in your case it would be '/home/anthony/.config/Thunar/scripts/rsz 640 %N'
now you just have 1 script, if you want you could add a command

'rez 10000000000000000000 %F'
or call it from the command line, using whatever argument you wanted.

convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg

$1 is replaced by the first argument 640,800,1024.........
for 'rez 640 %F' it would be equivalent to

convert -geometry 640×640 -quality 100 $file ./Resized/640/${name}_640.jpg

so it would rename it with the _640.jpg suffix aswell.

Last edited by benj1 (2009-11-10 22:32:02)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#18 2009-11-10 22:45:11

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:

(well if it works for you thats great, different versions maybe?)

anyway you dont need an extra script, you needs 2 less.

at the moment you have 3 scripts.
rez640,rez800,rez1024

so presumably your command in the context menu in thunar 'edit-->configure custom actions-->edit currently selected action (button on right)'will be

'rez640 %F' etc etc.

instead of that just use

'rez 640 %F' (notice the space, you are handing it an argument of 640) etc etc.
EDIT: in your case it would be '/home/anthony/.config/Thunar/scripts/rsz 640 %N'
now you just have 1 script, if you want you could add a command

'rez 10000000000000000000 %F'
or call it from the command line, using whatever argument you wanted.

convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg

$1 is replaced by the first argument 640,800,1024.........
for 'rez 640 %F' it would be equivalent to

convert -geometry 640×640 -quality 100 $file ./Resized/640/${name}_640.jpg

so it would rename it with the _640.jpg suffix aswell.

This is what I have in the command in actions
rsz640 %N  (That's it. No etc... etc)

So what you are saying is I can have one script that will do all three depending on which I choose?
If I want 640 it will resize the image or all images selected in Thunar. Create the folder Resized. Create the folder 640 within Resized and place those resized images in that folder.
If I want 800 it can resize to 800. Create 800 folder in Resized folder and place those 800 images in it.

I am following you a bit.
One script that will do all three by throwing it a different arg. Am I following correctly?


--
aicardi

Offline

#19 2009-11-10 22:53:14

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

aicardi wrote:

One script that will do all three by throwing it a different arg. Am I following correctly?

yes.

the easy way to test it is just to save it as
'rsz' (or rez, whichever)

then the thunar commands change to this
'/home/anthony/.config/Thunar/scripts/rsz 640 %N'
'/home/anthony/.config/Thunar/scripts/rsz 800 %N'
'/home/anthony/.config/Thunar/scripts/rsz 1024 %N'

it will work exactly the same as your original 3 scripts.


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#20 2009-11-10 23:09:04

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:
aicardi wrote:

One script that will do all three by throwing it a different arg. Am I following correctly?

yes.

the easy way to test it is just to save it as
'rsz' (or rez, whichever)

then the thunar commands change to this
'/home/anthony/.config/Thunar/scripts/rsz 640 %N'
'/home/anthony/.config/Thunar/scripts/rsz 800 %N'
'/home/anthony/.config/Thunar/scripts/rsz 1024 %N'

it will work exactly the same as your original 3 scripts.

Okay I'm going to mess with this. I can obviously leave what I have setup until I get it.
I am sure I will have some questions. So don't go far. tongue


--
aicardi

Offline

#21 2009-11-10 23:45:58

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

aicardi wrote:
benj1 wrote:
aicardi wrote:

One script that will do all three by throwing it a different arg. Am I following correctly?

yes.

the easy way to test it is just to save it as
'rsz' (or rez, whichever)

then the thunar commands change to this
'/home/anthony/.config/Thunar/scripts/rsz 640 %N'
'/home/anthony/.config/Thunar/scripts/rsz 800 %N'
'/home/anthony/.config/Thunar/scripts/rsz 1024 %N'

it will work exactly the same as your original 3 scripts.

Okay I'm going to mess with this. I can obviously leave what I have setup until I get it.
I am sure I will have some questions. So don't go far. tongue

This is what I am using. Which is what you had for me.

#!/bin/sh                                                                                                   

mkdir -p ./Resized/$1             
for file
    do
   if [ ! -e "$file" ]
       then
       continue
    fi
    name=$( echo $file | cut -f1 -d.)
    convert -geometry $1×$1 -quality 100 $file ./Resized/$1/${name}_$1.jpg
done

This is in the Thunar Action command
/home/anthony/.config/Thunar/scripts/rsz 640 %N

What happens is it creates the Resized folder as well as the 640 folder within. There is no resized image in the folder though. No resized image anywhere.
Now I do see this as a much better way. I just need to get the kinks out.

Anymore input will certainly be appreciated


--
aicardi

Offline

#22 2009-11-11 00:02:48

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

try running it in the terminal, see what error messages it generates


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#23 2009-11-11 01:20:55

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:

try running it in the terminal, see what error messages it generates

I did and it did produce geometry error like it did for you. Which makes no sense as I have always done it that way.
What baffles me more is why one works for me and one does not. Now that I understand your script they should do the exact same thing.
I have ran the tree little scripts I wrote a hundred times today. Again- No logic to this. I will keep at it.


--
aicardi

Offline

#24 2009-11-11 02:04:44

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: [ Tip ] Quick resizing of images in Thunar

aicardi wrote:
benj1 wrote:

try running it in the terminal, see what error messages it generates

I did and it did produce geometry error like it did for you. Which makes no sense as I have always done it that way.
What baffles me more is why one works for me and one does not. Now that I understand your script they should do the exact same thing.
I have ran the tree little scripts I wrote a hundred times today. Again- No logic to this. I will keep at it.

#!/bin/sh                                                                                                                      

mkdir -p ./Resized/$1

for file
    do
    if [ ! -e $file ]
        then
        continue
    fi
    toname="./Resized/"$1"/"$( echo $file | cut -f1 -d.)"_"$1".jpg"
    convert -geometry $1x$1 -quality 100 "${file}" "${toname}"
done

thats it, it was giving very strange, well unhelpful and inconsistent error messages, works now,


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

Be excellent to each other!

#25 2009-11-11 04:20:29

aicardi
#! Member
From: Chicago, IL. USA
Registered: 2009-10-31
Posts: 65
Website

Re: [ Tip ] Quick resizing of images in Thunar

benj1 wrote:
aicardi wrote:
benj1 wrote:

try running it in the terminal, see what error messages it generates

I did and it did produce geometry error like it did for you. Which makes no sense as I have always done it that way.
What baffles me more is why one works for me and one does not. Now that I understand your script they should do the exact same thing.
I have ran the tree little scripts I wrote a hundred times today. Again- No logic to this. I will keep at it.

#!/bin/sh                                                                                                                      

mkdir -p ./Resized/$1

for file
    do
    if [ ! -e $file ]
        then
        continue
    fi
    toname="./Resized/"$1"/"$( echo $file | cut -f1 -d.)"_"$1".jpg"
    convert -geometry $1x$1 -quality 100 "${file}" "${toname}"
done

thats it, it was giving very strange, well unhelpful and inconsistent error messages, works now,

I did  find why we were getting the geometry error.
I was looking close at that because mine worked and yours did not. There was no reason for that.
Look close at the "x" in the lines below. They are different. May not show as well here but they are different.
I simply backed out the one in your script and re typed the lower case "x". No more geometry error.
I did get a renaming of file error when I ran it but it did in fact work. I think some little tweaks to your original script will work.
Again- The result of that script is the same as mine. There should be no reason for *any* error.

If you like I will send you the two files and you can see the differences in the "x". freaky huh
$1x$1   (x from mine)
$1×$1  (x from your first script)
Note: the "x" in your final script here looks correct. Some sort of crazy fluke.

Last edited by aicardi (2009-11-11 04:27:16)


--
aicardi

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo