Skip to main content
use code escapes and enforce syntax highlighting
Source Link
HalosGhost
  • 4.9k
  • 10
  • 37
  • 42

I faced the same problem you described. Here's my solution:

#!/bin/bash
files=*.jpg
minimumWidth=640
minimumHeight=640

for f in $files
do
    imageWidth=$(identify -format "%w" "$f")
    imageHeight=$(identify -format "%h" "$f")

    if [ "$imageWidth" -gt "$minimumWidth" ] || [ "$imageHeight" -gt "$minimumHeight" ]; then
        mogrify -resize ''"$minimumWidth"x"$minimumHeight"'' $f
    fi
done
#!/bin/bash
files=*.jpg
minimumWidth=640
minimumHeight=640

for f in $files
do
    imageWidth=$(identify -format "%w" "$f")
    imageHeight=$(identify -format "%h" "$f")

    if [ "$imageWidth" -gt "$minimumWidth" ] || [ "$imageHeight" -gt "$minimumHeight" ]; then
        mogrify -resize ''"$minimumWidth"x"$minimumHeight"'' $f
    fi
done

I tested it on several JPEG images on a virtualized CentOS 6.5 machine. The script only resized and compressed the images whose width or height was larger than 640 pixels. This made it work for images with dimensions like 800 x 600 (landscape, resizing it to 640 x 480) and dimensions like 600 x 800 (portrait, resizing it to 480 x 640).

PS: A note on the '400x400>'400x400 parameter: mogrifymogrify will process the file even if its dimensions are equal or smaller than 400x400, but will resize only if its dimensions are larger than 400x400. That's why files' modification time and size are changed (in my case, mogrifymogrify made these files even larger than they were).

I faced the same problem you described. Here's my solution:

#!/bin/bash
files=*.jpg
minimumWidth=640
minimumHeight=640

for f in $files
do
    imageWidth=$(identify -format "%w" "$f")
    imageHeight=$(identify -format "%h" "$f")

    if [ "$imageWidth" -gt "$minimumWidth" ] || [ "$imageHeight" -gt "$minimumHeight" ]; then
        mogrify -resize ''"$minimumWidth"x"$minimumHeight"'' $f
    fi
done

I tested it on several JPEG images on a virtualized CentOS 6.5 machine. The script only resized and compressed the images whose width or height was larger than 640 pixels. This made it work for images with dimensions like 800 x 600 (landscape, resizing it to 640 x 480) and dimensions like 600 x 800 (portrait, resizing it to 480 x 640).

PS: A note on the '400x400>' parameter: mogrify will process the file even if its dimensions are equal or smaller than 400x400, but will resize only if its dimensions are larger than 400x400. That's why files' modification time and size are changed (in my case, mogrify made these files even larger than they were).

I faced the same problem you described. Here's my solution:

#!/bin/bash
files=*.jpg
minimumWidth=640
minimumHeight=640

for f in $files
do
    imageWidth=$(identify -format "%w" "$f")
    imageHeight=$(identify -format "%h" "$f")

    if [ "$imageWidth" -gt "$minimumWidth" ] || [ "$imageHeight" -gt "$minimumHeight" ]; then
        mogrify -resize ''"$minimumWidth"x"$minimumHeight"'' $f
    fi
done

I tested it on several JPEG images on a virtualized CentOS 6.5 machine. The script only resized and compressed the images whose width or height was larger than 640 pixels. This made it work for images with dimensions like 800 x 600 (landscape, resizing it to 640 x 480) and dimensions like 600 x 800 (portrait, resizing it to 480 x 640).

PS: A note on the 400x400 parameter: mogrify will process the file even if its dimensions are equal or smaller than 400x400, but will resize only if its dimensions are larger than 400x400. That's why files' modification time and size are changed (in my case, mogrify made these files even larger than they were).

Source Link

I faced the same problem you described. Here's my solution:

#!/bin/bash
files=*.jpg
minimumWidth=640
minimumHeight=640

for f in $files
do
    imageWidth=$(identify -format "%w" "$f")
    imageHeight=$(identify -format "%h" "$f")

    if [ "$imageWidth" -gt "$minimumWidth" ] || [ "$imageHeight" -gt "$minimumHeight" ]; then
        mogrify -resize ''"$minimumWidth"x"$minimumHeight"'' $f
    fi
done

I tested it on several JPEG images on a virtualized CentOS 6.5 machine. The script only resized and compressed the images whose width or height was larger than 640 pixels. This made it work for images with dimensions like 800 x 600 (landscape, resizing it to 640 x 480) and dimensions like 600 x 800 (portrait, resizing it to 480 x 640).

PS: A note on the '400x400>' parameter: mogrify will process the file even if its dimensions are equal or smaller than 400x400, but will resize only if its dimensions are larger than 400x400. That's why files' modification time and size are changed (in my case, mogrify made these files even larger than they were).