Modify images based on date range?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
benchmarkjoshw
Posts: 3
Joined: 2016-11-16T07:51:13-07:00
Authentication code: 1151

Modify images based on date range?

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Modify images based on date range?

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Modify images based on date range?

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Modify images based on date range?

Post by snibgo »

The Windows equivalent to "cron" is "schtasks".
snibgo's IM pages: im.snibgo.com
benchmarkjoshw
Posts: 3
Joined: 2016-11-16T07:51:13-07:00
Authentication code: 1151

Re: Modify images based on date range?

Post 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}
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Modify images based on date range?

Post 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.
snibgo's IM pages: im.snibgo.com
benchmarkjoshw
Posts: 3
Joined: 2016-11-16T07:51:13-07:00
Authentication code: 1151

Re: Modify images based on date range?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Modify images based on date range?

Post 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
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Modify images based on date range?

Post 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
Post Reply