Page 1 of 1

Modify images based on date range?

Posted: 2016-11-16T07:55:54-07:00
by benchmarkjoshw
Hello, I'm a systems administrator for a contracting company and we've started noticing that our file server is getting way too full way too quickly, and I've determined it's due to the sheer number of images we have saved on the server (we have consultants out on the field that send in photos they take of sites that we save onto the server). Since we'd rather not keep buying hard drives we're looking into batch processing these images to reduce their size (because ~250 images per day at ~8 MB per image adds up pretty quickly). For this, I've found that ImageMagick seems like the best option since it is pretty quick and the command line makes it easy to process subdirectories without having to actually go to each individual folder.

My plan is to use ImageMagick to process the images we already have, then set up a monthly script that forces ImageMagick to process images that were submitted during that month (i.e. all October images would be processed on the 31st, etc.), and therein lies my concern. Is there an option within ImageMagick to modify images in a given date range?

Thanks!

Re: Modify images based on date range?

Posted: 2016-11-16T08:03:46-07:00
by snibgo
benchmarkjoshw wrote:Is there an option within ImageMagick to modify images in a given date range?
No. IM can extract dates from various metadata fields, but can't use that to decide whether to process files. I'd do that with a shell script.

Re: Modify images based on date range?

Posted: 2016-11-16T10:29:49-07:00
by fmw42
Unix systems have a cron command that will allow you to schedule the launch of a shell script to do the processing. I do not know about Windows servers.

Re: Modify images based on date range?

Posted: 2016-11-16T10:48:57-07:00
by snibgo
The Windows equivalent to "cron" is "schtasks".

Re: Modify images based on date range?

Posted: 2016-11-17T12:09:20-07:00
by benchmarkjoshw
Alright, well with what little Powershell knowledge I have I've cobbled together a script to supposedly do what I want, but I'm having a bit of issue with it in that when I run it it doesn't actually do anything to the photos in my directory. Would it be possible to get more experienced eyes on it to see where it's getting messed up? I understand if this is a question best left to other forums, but since it only seems to be the ImageMagick part specifically I figure I might as well try here first.

Code: Select all

$path = "C:\Users\Me\Desktop\TestPhotos"

# Modify files older than the limit.
Get-ChildItem -Path $path -Recurse -Include .jpg | Where-Object {$_.LastWriteTime -gt (Get-Date) -and $_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Foreach {magick mogrify $path -resize 50%> *.jpg}

Re: Modify images based on date range?

Posted: 2016-11-17T12:25:48-07:00
by snibgo
benchmarkjoshw wrote:mogrify $path -resize 50%> *.jpg
$path is "C:\Users\Me\Desktop\TestPhotos", without quotes, right? Then this isn't a valid mogrify command.

Re: Modify images based on date range?

Posted: 2016-11-17T13:15:49-07:00
by benchmarkjoshw
snibgo wrote:
benchmarkjoshw wrote:mogrify $path -resize 50%> *.jpg
$path is "C:\Users\Me\Desktop\TestPhotos", without quotes, right? Then this isn't a valid mogrify command.
That is the case, and I have tried pasting the actual C:\Users\Me\Desktop\TestPhotos in place of $path for all parts of the script and it still doesn't want to take. Is there some magic bullet cmdlet that I'm just completely missing?

Re: Modify images based on date range?

Posted: 2016-11-17T13:33:55-07:00
by snibgo
I can't help you with cmdlets. But this ...

Code: Select all

mogrify C:\Users\Me\Desktop\TestPhotos -resize 50%> *.jpg
... isn't a valid mogrify command.

For mogrify syntax, type "mogrify" at the command line, or see http://www.imagemagick.org/script/mogrify.php

Re: Modify images based on date range?

Posted: 2016-11-17T16:14:14-07:00
by fmw42
For mogrify, you need to cd to the folder you want. Also create a new directory and use -path to specify where the output directory is located. Also use -format to specify the desired output format. See the link that snibgo has shown.

Code: Select all

cd to input directory
mogrify -path path2/outputdirectory -format jpg -resize 50%> *.jpg