LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2016, 10:38 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
downsample all images in a folder and all subfolders


I have thousands of jpgs in a folder called pictures, with subfolders under that for each year, then under that subfolders of each month, then under each month a folder per day.

Is there a command I can run that will downsample all .jpg under pictures and all its subfolders to say 300dpi if it's higher than 300 now.

I'm running out of space with no room for expansion so need to downsample or resize to a max height or something to make each jpg a bit smaller for a collective big gain in free space.
 
Old 10-13-2016, 10:39 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
You want to convert them "in place" then? Without outputting to a new directory?

Throw some test images in a test directory, and test this test before running it on a bajillion files. If it doesn't do what you want, it could wreck your files.

Code:
# install imagemagick
yum install imagemagick

# make a for loop that changes the density to 300dpi
for img in $(find /test/ -type f -name "*.jpg"); do convert -units PixelsPerInch $img -density 300 $img; done
Test/verify your DPI settings on your images with:
Code:
identify -verbose image.jpg

Last edited by szboardstretcher; 10-13-2016 at 10:51 AM.
 
Old 10-13-2016, 10:56 AM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks. Yeah, I could just do it in place once I test it out with a few, that'd be fine due to the space pinch. Thanks for the command.
 
Old 10-13-2016, 02:26 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
addition:
imagemagick's 'mogrify' command has exactly the same options as 'convert', but replaces and overwrites all input files instead of writing to a seperate output file.
 
  


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
How to create a shorcut to a folder and its subfolders..? javier_ns Linux - Newbie 3 05-15-2013 05:51 PM
Scripts to list folder contents and copy images from folder and subfolders brunces Linux - Newbie 6 11-03-2011 01:23 PM
Compress .gz my folder with all contens inside, subfolders,images.... ASTRAPI Linux - Newbie 4 10-05-2010 08:06 PM
Nautilus, set view for folder + subfolders kellemes Linux - Newbie 4 02-11-2010 11:20 AM
changeing permissions for a folder + subfolders and files ? YBA^[x] Slackware 7 08-06-2004 04:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:30 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