LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-03-2006, 01:29 AM   #1
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Rep: Reputation: 30
How to do this: move image1, resize image1, move image2, resize image2, etc


Hello, I want to copy a bunch of photos from a CD (upon insertion) and then using ImageMagick, resize them all.

The tricky part is that I will be inserting CD's with around 100-200 large (3-5mb each) jpg files, and want to have it so that it copies and resizes them one at a time so that I don't fill up my hard drive with the entire contents of the CD. I only have a 1GB hard drive (Linux Picture Frame). I know how to move all the jpg's and then resize all of them, but that would mean I had to have several hundred MB's of free space on the drive.

Basically I'm looking for this function: copy image1.jpg to hdd, resize, copy image2.jpg to hdd, resize, copy image3.jpg to hdd, resize, etc

Does anyone know how I can do this? Also, how would I have this automatically done upon inserting the CD into the computer?
-Thanks
 
Old 10-03-2006, 02:29 PM   #2
mrkirkland
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE + Debian
Posts: 22

Rep: Reputation: 15
You could use a shell script and image magic.

Here's a quick script.
It assumes all the images end .jpg - edit as the variables at the top to your taste, and the .jpg.

Code:
#/bin/bash

PATH_TO_CD=/media/cdrom
DESTINATION=~/photos
PIXEL_SIZE=800

find $PATH_TO_CD -name "*.jpg" > ~/list.txt;
while read i ;
do
FILE=`basename "$i"`;
echo "Converting $i" ;
convert -resize $PIXEL_SIZE "$i" "$DESTINATION/$FILE" ;
done < ~/list.txt

echo "--------- FINISHED ---------"
 
Old 10-03-2006, 02:36 PM   #3
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
> Basically I'm looking for this function: copy image1.jpg to hdd, resize, copy image2.jpg to hdd, resize, copy image3.jpg to hdd, resize, etc

What happens to the images after they're resized? Are they dropped on the floor? Stored to the disk? If so, don't you have to have loads of space anyways, or is the trick that by resizing (scaling down a lot) the space requirements gets vastly decreased?

Anyways, what you want is probably a for-loop; type this into bash:
Code:
user@host:/mnt/CD-mount-point/directory-with-images$ \
> for fp in *; do
>   cp $fp /home/user/photos/$fp;
>   however-you-resize /home/user/photos/$fp;
> done
Which should do what you want: copy the files over and resize them one by one. I haven't used imagemagick for resizing from the command-line; if it can't do that, you may want to look into the pildriver.

hth --Jonas

Last edited by jonaskoelker; 10-03-2006 at 03:20 PM.
 
Old 10-03-2006, 03:36 PM   #4
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
Basically, I save on the space because instead of copying over 500 or so MB of pictures, I just copy one over, resize it and save it to the digital picture frame's photos folder, then i have it do the next image. The images will end up being around 50-100kb each, instead of 3-5mb each. And since I only have a 1gb drive, space is of the essence. I could easily copy them all over, then resize them all, but once I start filling up the drive, there won't be space to copy over the entire cd.

I'll try those scripts out and let you guys know what happens.
-Thanks for the help so far.
 
Old 10-04-2006, 01:18 AM   #5
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
OK guys I'm getting rocked so far. I tried the two below scripts but with no luck. I must be doing something wrong. Please help.

Script 1:

PATH_TO_CD=/pics/source
DESTINATION=~/pics/destination
PIXEL_SIZE=1024

find $PATH_TO_CD -name "*.jpg" > ~/list.txt;
while read i ;
do
FILE=`basename "$i"`;
echo "Converting $i" ;
/opt/imagemagick/bin/convert -monitor -scale "$PIXEL_SIZE" "$i" "$DESTINATION/$FILE" ;
done < ~/list.txt
echo "--------- FINISHED ---------"

###########
Script 2:

for fp in /pics/source; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768
/anew/new/$fp;
done
 
Old 10-04-2006, 03:06 AM   #6
mrkirkland
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE + Debian
Posts: 22

Rep: Reputation: 15
Can you give more debugging info, i.e. what does happen? error messages etc.



Anyway, I think you need to write the destination in the resize part for Script 2:

Code:
for fp in /pics/source; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp
done

(If you're images filenames don't have any spaces in them then you don't need script 1 anyway)
 
Old 10-04-2006, 10:52 AM   #7
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
OK,i tried the following script:

for fp in /pics/source; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp
done


and here was the error:

cp: omitting directory '/pics/source'
mogrify: unable to open image '/pics/destination//pics/source': No such file or directory



I'm not sure how the two slashes got in there.
-Thanks
 
Old 10-04-2006, 12:28 PM   #8
mrkirkland
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE + Debian
Posts: 22

Rep: Reputation: 15
Sorry I didn't check jonaskoelker's script first, perhaps it's not meant for bash?

You must change /pics/source to the path to your CD
e.g. /media/hdd (type mount if you don't now and it should be listed in the output from that)
and /pics/destination for the destination directory.

Also it seems you need to add the * wildcard with bash, other wise it just takes it as a single string not a directory listing

Code:
#!/bin/bash
for fp in /pics/source/*; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp
done
What happened with my first script? if so did you also edit the path variables at the top?
 
Old 10-04-2006, 03:47 PM   #9
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
OK, when I run this script:

for fp in /pics/source/*; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp
done


I get this error:

cp: cannot create regular file '/pics/destination//pics/sources/c005.jpg': No such file or directory.
mogrify: unable to open image '/pics/destination//pics/source/c005.jpg': No such file or directory


I am not sure how or why it's looking for the images in that non existing, double slash directory.

When I ran your first script:

PATH_TO_CD=/pics/source
DESTINATION=~/pics/destination
PIXEL_SIZE=800

find $PATH_TO_CD -name "*.jpg" > ~/list.txt;
while read i ;
do
FILE=`basename "$i"`;
echo "Converting $i" ;
/opt/imagemagick/bin/convert -resize $PIXEL_SIZE "$i" "$DESTINATION/$FILE" ;
done < ~/list.txt

echo "--------- FINISHED ---------"



----The error reads:
Converting /pics/source/c002.jpg
./resize2.sh: line 16: 516 Killed /opt/imagemagick/bin/convert -resize $PIXEL_SIZE "$I" "$DESTINATION/$FILE"



---resize2.sh is the file where i have the script in. Also, all of these errors just keep on going on and on as it tries to convert each picture.

-Thank you for your help.
 
Old 10-04-2006, 04:00 PM   #10
mrkirkland
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE + Debian
Posts: 22

Rep: Reputation: 15
for script 2
did you include
Code:
#!/bin/bash
as the first line of your script?


otherwise, script 1 another revision!

Code:
cd /pics/source/
for fp in *; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp
done
 
Old 10-04-2006, 05:11 PM   #11
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
OK, here's the script i run (in it's entirity):

#!/bin/bash
cd /pics/source
for fp in *; do
cp $fp /pics/destination/$fp;
/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp
done



Still didn't work...here is the error:

/home/dsl/resize2.sh: line 6: 806 Killed /opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp

....it continues on each line like so...
/home/dsl/resize2.sh: line 6: 808 Killed /opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp

each error line has a different number before Killed.
I have no idea why this is not working...all logic tells me it should work.
-Thanks
 
Old 10-04-2006, 05:22 PM   #12
mrkirkland
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE + Debian
Posts: 22

Rep: Reputation: 15
You're very close.
It seems that either script is not expanding the variables for the convert or mogrify commands, perhaps try encasing those commands in back ticks:

Code:
#!/bin/bash
cd /pics/source
for fp in *; do
cp $fp /pics/destination/$fp;
`/opt/imagemagick/bin/mogrify -quality 75 -resize 1024x768 /pics/destination/$fp`
done
It works either way for me. Not sure why it wouldn't expand the vars...
 
Old 10-04-2006, 06:12 PM   #13
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
Man oh Man, I just can't get this working...there must be some sort of bug or something..... Here's what happened.....

I ran your newest script with the ` marks and got: "Line 5: Load: command not found" error. So i took out the backticks again, and it seemed to start loading the image (i put in the monitor tag so i could watch the process), it loaded about 20% of the image and then gave me the Killed error like earlier.

Do you have any idea why it would give that error?

PS. if i just try to do one image by itself and manually type in the command, I now seem to be getting a result that just says Killed, but no further details...something other than the script must be wrong.
-Thanks
 
Old 10-05-2006, 04:14 AM   #14
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
> I ran your newest script with the ` marks and got
When you put a command in backsticks it gets replace with the output of the command. For example:

Code:
cat `ls -1t | head -n1`
turns into
Code:
cat <the name of the newest file>
# ls -t: sort by time; head -n1: take only the first one.
So as bash says "Line 5: Load: command not found", it means the output of imagemagick is not "(...) Killed (...)".

And you're right, something is very wrong if your processes just get killed. Try watching top and see if any of them consume much memory. How much memory does your box have? Could the processes be running out of some other resource? (disk space).

The reason (I think) it says "806 Killed ... $fp" (that is, it doesn't expand $fp) is because the error message comes from bash, which just quotes the line literally (where else *could* it come from?). Not that I can draw any useful conclusions from that, but try running it with bash -x and/or twiddling your ulimit (if you have any). See if there's anything in limits.conf (/etc/security/limits.conf on my box, but LocateIYF).

I would guess that the numbers before Killed are process IDs. Try running the script and noting the last such number. Then run
Code:
$ bash -c 'echo $$'
A couple of times. The first number output by that should be slightly larger (1 or 2, maybe 3) than the last number before Killed. The next numbers should each be slightly larger than the preceeding one (and the Killed numbers should also be slightly increasing in the same way). If so, they're PIDs (not that I can draw any useful conclusions from that right now).

Last edited by jonaskoelker; 10-06-2006 at 03:34 AM.
 
Old 10-05-2006, 01:26 PM   #15
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
OK, i got it working finally.....It was not in fact an error with any of the scripts...but rather, it was some sort of memory error.

I posted on the ImageMagick site and it was recommend that I add: -limit memory 2 -limit map 4 right after the convert or Mogrify commands, and bingo...it worked nicely.

Thank you for all your help..you're scripts will/have come in very very handy.
-Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't move or resize windows WoodLark Slackware 11 04-04-2013 04:37 PM
Resize lvm and move /boot? tgm4883 Fedora 1 08-22-2006 07:46 PM
Cannot Resize, Move my active window in KDE 3.2? DigitalKid2004 Linux - Newbie 0 09-20-2004 12:19 PM
Cannot resize/move firefox window 000jits General 3 09-08-2004 07:39 AM
resize or move /boot partition breenbaron Linux - General 3 04-07-2004 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration