Command-Line ImageMagick – Convert and Compress PNG, JPEG, JPG to JPG

command lineimagemagick

Im almost there with this code:

for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.{png,jpeg,jpg}
       BASE=`basename $PHOTO`
    convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE.jpg"

But the output files are appearing with their old file extension with a ".jpg" appended in the end, example: imageA.png.jpg .

How can solve this?

Best Answer

Replace the line:

BASE=`basename $PHOTO`

With this one:

BASE=`basename $PHOTO | cut -d. -f1`

Then try again.

Related Question