Page 1 of 1

Efficient batch converting

Posted: 2019-05-02T16:06:16-07:00
by naruto
Please kindly help me. I have been googling but couldn't find a really good script. Basically, I am trying to run:
1. imagemagick convert to 1170px over a folder, including subfolder but preserve modified date
2. but doesn't want to process/analyze every image, especially those that are smaller than or equal 1170px
3. skip processed images
4. run script every one hour.

I think for number 2, I google that I would need exiftool but doesn't have experience using it

Here is what I have so far:
crontab -e

Code: Select all

0 * * * * bash sharingan.sh >/dev/null 2>&1
sharingan.sh:

Code: Select all

#!/usr/bin/env bash

find Images -mmin -60 -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' \)|

while read file
do convert -resize 1170 "$file" "$file".tmp
   touch -r "$file" "$file".tmp
   cp -f -p "$file".tmp "$file"
   rm "$file".tmp
done
I still can't preserve the modification time. What do I do wrong?

Re: Efficient batch converting

Posted: 2019-05-02T19:29:04-07:00
by fmw42
Imagemagick will only resize if larger than some dimension if using the > character. See https://imagemagick.org/script/command- ... p#geometry. If you are asking about total pixels, then you will need to get the WxH separately and then test on that.

I do not know if Imagemagick can preserve the modification date, since it is modifying the image or creating new ones. I do not know much about this, but you could check out -define png:include-chunk=value at https://imagemagick.org/script/command- ... php#define

You can process a whole folder of image using mogrify. But it will not traverse directories. So you are better off looping over your images from each/all directories that you want.

Re: Efficient batch converting

Posted: 2019-05-03T00:15:31-07:00
by bratpit
Try something like this in your loop:

//get mtime and add to variable
mtime=$(stat -c %y "$file")
//process file
convert "$file"
//after that change mtime
touch -d "$mtime" "$file"