Process File only if Dimension Change

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
PoOoOoZ
Posts: 2
Joined: 2016-10-17T11:02:29-07:00
Authentication code: 1151

Process File only if Dimension Change

Post by PoOoOoZ »

Hello, i have found the command i need, but i need an option more.

for file in *.jpg; do convert $file -resize 1000x1000\> $file; done

I want it not process with file who is not resized, with this command it process with it even if the dimension don't change (but file size change)...

If i do this everyday in the same folder, the file who will not be redimensionned will lost quality day after day...

Thank you very much.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Process File only if Dimension Change

Post by snibgo »

PoOoOoZ wrote:Hello, i have found the command i need, but i need an option more.
Do that option in the script, outside the convert, and probably outside the "for" loop.

For example, don't do this every day in the same folder. Organise your process so you do the resize only once per file.
snibgo's IM pages: im.snibgo.com
PoOoOoZ
Posts: 2
Joined: 2016-10-17T11:02:29-07:00
Authentication code: 1151

Re: Process File only if Dimension Change

Post by PoOoOoZ »

I was looking for a thing like this :

for files in *.jpg
do
echo $files
filesizecurrent=$(wc -c <"$files")
echo $filesizecurrent
if [ $filesizecurrent -ge 100000 ]
then
echo "BIG FILE"
convert $file -resize 1000x1000\> $file
continue
fi
echo "LITTLE FILE"
done
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Process File only if Dimension Change

Post by GeeMack »

PoOoOoZ wrote:I was looking for a thing like this :
You can use ImageMagick to obtain the dimensions of an image with a command like this...

Code: Select all

convert -ping image.jpg -format "%[w]x%[h]" info:
Use something like that inside a "for" loop, maybe once to get the "%[w]" width and another time to get the "%[h]" height, to set the value of some variables. Then calculate the area using those variables, and do the "-resize" if the area exceeds a certain threshold.

To get any more detailed help you need to let us know what version of ImageMagick you're using, and what platform or shell, you're running this from.
Post Reply