LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   downsample all images in a folder and all subfolders (https://www.linuxquestions.org/questions/linux-newbie-8/downsample-all-images-in-a-folder-and-all-subfolders-4175591334/)

anon091 10-13-2016 10:38 AM

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.

szboardstretcher 10-13-2016 10:39 AM

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

anon091 10-13-2016 10:56 AM

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.

ondoho 10-13-2016 02:26 PM

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.


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