How to do this: move image1, resize image1, move image2, resize image2, etc
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
> 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.
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.
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?
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.
#!/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
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...
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
> 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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.