Convert all non-JPG images to JPGs












4














What command can I use to convert all images in a folder which are not JPGs (PNG and BMP primarily) to JPG? I'd also like the conversion quality to be 100%. And I'd like the converted images to replace the originals.










share|improve this question






















  • What have you tried? Have you looked into the convert utility that comes with ImageMagick, for example?
    – DopeGhoti
    Nov 7 '14 at 21:01










  • Install Gimp from your distro repo, and use the Command Line processor in Batch Mode
    – eyoung100
    Nov 7 '14 at 21:04










  • @DopeGhoti Will this work? mogrify -format jpg *.png How to also get it to convert BMPs to JPGs with the same command?
    – user8547
    Nov 7 '14 at 21:05










  • @user8547: no, it won't. You need to iterate over all filenames, you cant just supply them all to mogrify.
    – Bananguin
    Nov 7 '14 at 21:11










  • @Bananguin - apparently, ImageMagick devs don't share your opinion.
    – don_crissti
    Nov 7 '14 at 23:03
















4














What command can I use to convert all images in a folder which are not JPGs (PNG and BMP primarily) to JPG? I'd also like the conversion quality to be 100%. And I'd like the converted images to replace the originals.










share|improve this question






















  • What have you tried? Have you looked into the convert utility that comes with ImageMagick, for example?
    – DopeGhoti
    Nov 7 '14 at 21:01










  • Install Gimp from your distro repo, and use the Command Line processor in Batch Mode
    – eyoung100
    Nov 7 '14 at 21:04










  • @DopeGhoti Will this work? mogrify -format jpg *.png How to also get it to convert BMPs to JPGs with the same command?
    – user8547
    Nov 7 '14 at 21:05










  • @user8547: no, it won't. You need to iterate over all filenames, you cant just supply them all to mogrify.
    – Bananguin
    Nov 7 '14 at 21:11










  • @Bananguin - apparently, ImageMagick devs don't share your opinion.
    – don_crissti
    Nov 7 '14 at 23:03














4












4








4


1





What command can I use to convert all images in a folder which are not JPGs (PNG and BMP primarily) to JPG? I'd also like the conversion quality to be 100%. And I'd like the converted images to replace the originals.










share|improve this question













What command can I use to convert all images in a folder which are not JPGs (PNG and BMP primarily) to JPG? I'd also like the conversion quality to be 100%. And I'd like the converted images to replace the originals.







command conversion images






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 '14 at 20:55









user8547user8547

62651435




62651435












  • What have you tried? Have you looked into the convert utility that comes with ImageMagick, for example?
    – DopeGhoti
    Nov 7 '14 at 21:01










  • Install Gimp from your distro repo, and use the Command Line processor in Batch Mode
    – eyoung100
    Nov 7 '14 at 21:04










  • @DopeGhoti Will this work? mogrify -format jpg *.png How to also get it to convert BMPs to JPGs with the same command?
    – user8547
    Nov 7 '14 at 21:05










  • @user8547: no, it won't. You need to iterate over all filenames, you cant just supply them all to mogrify.
    – Bananguin
    Nov 7 '14 at 21:11










  • @Bananguin - apparently, ImageMagick devs don't share your opinion.
    – don_crissti
    Nov 7 '14 at 23:03


















  • What have you tried? Have you looked into the convert utility that comes with ImageMagick, for example?
    – DopeGhoti
    Nov 7 '14 at 21:01










  • Install Gimp from your distro repo, and use the Command Line processor in Batch Mode
    – eyoung100
    Nov 7 '14 at 21:04










  • @DopeGhoti Will this work? mogrify -format jpg *.png How to also get it to convert BMPs to JPGs with the same command?
    – user8547
    Nov 7 '14 at 21:05










  • @user8547: no, it won't. You need to iterate over all filenames, you cant just supply them all to mogrify.
    – Bananguin
    Nov 7 '14 at 21:11










  • @Bananguin - apparently, ImageMagick devs don't share your opinion.
    – don_crissti
    Nov 7 '14 at 23:03
















What have you tried? Have you looked into the convert utility that comes with ImageMagick, for example?
– DopeGhoti
Nov 7 '14 at 21:01




What have you tried? Have you looked into the convert utility that comes with ImageMagick, for example?
– DopeGhoti
Nov 7 '14 at 21:01












Install Gimp from your distro repo, and use the Command Line processor in Batch Mode
– eyoung100
Nov 7 '14 at 21:04




Install Gimp from your distro repo, and use the Command Line processor in Batch Mode
– eyoung100
Nov 7 '14 at 21:04












@DopeGhoti Will this work? mogrify -format jpg *.png How to also get it to convert BMPs to JPGs with the same command?
– user8547
Nov 7 '14 at 21:05




@DopeGhoti Will this work? mogrify -format jpg *.png How to also get it to convert BMPs to JPGs with the same command?
– user8547
Nov 7 '14 at 21:05












@user8547: no, it won't. You need to iterate over all filenames, you cant just supply them all to mogrify.
– Bananguin
Nov 7 '14 at 21:11




@user8547: no, it won't. You need to iterate over all filenames, you cant just supply them all to mogrify.
– Bananguin
Nov 7 '14 at 21:11












@Bananguin - apparently, ImageMagick devs don't share your opinion.
– don_crissti
Nov 7 '14 at 23:03




@Bananguin - apparently, ImageMagick devs don't share your opinion.
– don_crissti
Nov 7 '14 at 23:03










3 Answers
3






active

oldest

votes


















3














Assuming there are only images in that folder, you can



ls | grep -v jpg$


to get all filenames that do not end with jpg, which I assume are all the images you want to convert. Then you can use the tool convert from ImageMagick like this



ls | grep -v jpg$ | while IFS= read -r FILENAME
do
convert "${FILENAME}" "${FILENAME%.*}.jpg"
done


The convert command expands to convert <file name as printed by ls> <file name without extention>.jpg. The extention jpg will tell convert to convert to jpg format.






share|improve this answer























  • Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
    – user8547
    Nov 7 '14 at 21:18












  • Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
    – eyoung100
    Nov 7 '14 at 21:25










  • @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
    – user8547
    Nov 7 '14 at 21:36








  • 1




    More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
    – Gilles
    Nov 8 '14 at 0:46








  • 1




    @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
    – Bananguin
    Nov 8 '14 at 14:30





















3














To convert all .png and .bmp in the current directory and then remove the original files:



mogrify -format jpg -quality 100 ./*.{png,bmp}
rm ./*.{png,bmp}


To convert all files except .jpg, if your shell supports extended globbing, e.g. bash:



shopt extglob
mogrify -format jpg -quality 100 ./*.!(jpg)
rm ./*.!(jpg)


or zsh:



setopt extended_glob
mogrify -format jpg -quality 100 ./^*.jpg
rm ./^*.jpg


Recursive:



find . -type f ! -name '*.jpg' -exec 
mogrify -format jpg -quality 100 {} + -exec rm {} +





share|improve this answer





























    0














    I've found a further solution using the XNView CLI program nConvert. Here's an installation tutorial for nConvert for Linux.



    The following nConvert command will convert any image formats to jpg, and the rm command will delete all bmp and png files:



    nconvert -out jpeg -o output-##.jpg *.* && rm ./*.{png,bmp}





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f166720%2fconvert-all-non-jpg-images-to-jpgs%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      Assuming there are only images in that folder, you can



      ls | grep -v jpg$


      to get all filenames that do not end with jpg, which I assume are all the images you want to convert. Then you can use the tool convert from ImageMagick like this



      ls | grep -v jpg$ | while IFS= read -r FILENAME
      do
      convert "${FILENAME}" "${FILENAME%.*}.jpg"
      done


      The convert command expands to convert <file name as printed by ls> <file name without extention>.jpg. The extention jpg will tell convert to convert to jpg format.






      share|improve this answer























      • Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
        – user8547
        Nov 7 '14 at 21:18












      • Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
        – eyoung100
        Nov 7 '14 at 21:25










      • @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
        – user8547
        Nov 7 '14 at 21:36








      • 1




        More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
        – Gilles
        Nov 8 '14 at 0:46








      • 1




        @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
        – Bananguin
        Nov 8 '14 at 14:30


















      3














      Assuming there are only images in that folder, you can



      ls | grep -v jpg$


      to get all filenames that do not end with jpg, which I assume are all the images you want to convert. Then you can use the tool convert from ImageMagick like this



      ls | grep -v jpg$ | while IFS= read -r FILENAME
      do
      convert "${FILENAME}" "${FILENAME%.*}.jpg"
      done


      The convert command expands to convert <file name as printed by ls> <file name without extention>.jpg. The extention jpg will tell convert to convert to jpg format.






      share|improve this answer























      • Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
        – user8547
        Nov 7 '14 at 21:18












      • Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
        – eyoung100
        Nov 7 '14 at 21:25










      • @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
        – user8547
        Nov 7 '14 at 21:36








      • 1




        More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
        – Gilles
        Nov 8 '14 at 0:46








      • 1




        @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
        – Bananguin
        Nov 8 '14 at 14:30
















      3












      3








      3






      Assuming there are only images in that folder, you can



      ls | grep -v jpg$


      to get all filenames that do not end with jpg, which I assume are all the images you want to convert. Then you can use the tool convert from ImageMagick like this



      ls | grep -v jpg$ | while IFS= read -r FILENAME
      do
      convert "${FILENAME}" "${FILENAME%.*}.jpg"
      done


      The convert command expands to convert <file name as printed by ls> <file name without extention>.jpg. The extention jpg will tell convert to convert to jpg format.






      share|improve this answer














      Assuming there are only images in that folder, you can



      ls | grep -v jpg$


      to get all filenames that do not end with jpg, which I assume are all the images you want to convert. Then you can use the tool convert from ImageMagick like this



      ls | grep -v jpg$ | while IFS= read -r FILENAME
      do
      convert "${FILENAME}" "${FILENAME%.*}.jpg"
      done


      The convert command expands to convert <file name as printed by ls> <file name without extention>.jpg. The extention jpg will tell convert to convert to jpg format.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 8 '14 at 0:45









      Gilles

      530k12810621590




      530k12810621590










      answered Nov 7 '14 at 21:10









      BananguinBananguin

      5,2551338




      5,2551338












      • Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
        – user8547
        Nov 7 '14 at 21:18












      • Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
        – eyoung100
        Nov 7 '14 at 21:25










      • @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
        – user8547
        Nov 7 '14 at 21:36








      • 1




        More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
        – Gilles
        Nov 8 '14 at 0:46








      • 1




        @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
        – Bananguin
        Nov 8 '14 at 14:30




















      • Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
        – user8547
        Nov 7 '14 at 21:18












      • Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
        – eyoung100
        Nov 7 '14 at 21:25










      • @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
        – user8547
        Nov 7 '14 at 21:36








      • 1




        More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
        – Gilles
        Nov 8 '14 at 0:46








      • 1




        @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
        – Bananguin
        Nov 8 '14 at 14:30


















      Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
      – user8547
      Nov 7 '14 at 21:18






      Can the extension PNG and BMP replace "FILENAME"? I want the command to automatically find all non-JPG images in a folder of images. I don't want to have to manually add the path or the filename of the non-JPG images.
      – user8547
      Nov 7 '14 at 21:18














      Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
      – eyoung100
      Nov 7 '14 at 21:25




      Replace jpg$ w/ png$ for pngs and bmp$ The ls command is the input buffer
      – eyoung100
      Nov 7 '14 at 21:25












      @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
      – user8547
      Nov 7 '14 at 21:36






      @eyoung100 Like this: "ls | grep -v png$ bmp$ | while read FILENAME" ??
      – user8547
      Nov 7 '14 at 21:36






      1




      1




      More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
      – Gilles
      Nov 8 '14 at 0:46






      More robust: for x in *; do case $x in *.[Jj][Pp][Gg]) :;; *) convert -- "$x" "${x%.*}.jpg";; esac; done
      – Gilles
      Nov 8 '14 at 0:46






      1




      1




      @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
      – Bananguin
      Nov 8 '14 at 14:30






      @user8547: yes, that should work. I don't think convert will modify in place, but you can add a line right after the convert line rm ${FILENAME}, which will delete the original file.
      – Bananguin
      Nov 8 '14 at 14:30















      3














      To convert all .png and .bmp in the current directory and then remove the original files:



      mogrify -format jpg -quality 100 ./*.{png,bmp}
      rm ./*.{png,bmp}


      To convert all files except .jpg, if your shell supports extended globbing, e.g. bash:



      shopt extglob
      mogrify -format jpg -quality 100 ./*.!(jpg)
      rm ./*.!(jpg)


      or zsh:



      setopt extended_glob
      mogrify -format jpg -quality 100 ./^*.jpg
      rm ./^*.jpg


      Recursive:



      find . -type f ! -name '*.jpg' -exec 
      mogrify -format jpg -quality 100 {} + -exec rm {} +





      share|improve this answer


























        3














        To convert all .png and .bmp in the current directory and then remove the original files:



        mogrify -format jpg -quality 100 ./*.{png,bmp}
        rm ./*.{png,bmp}


        To convert all files except .jpg, if your shell supports extended globbing, e.g. bash:



        shopt extglob
        mogrify -format jpg -quality 100 ./*.!(jpg)
        rm ./*.!(jpg)


        or zsh:



        setopt extended_glob
        mogrify -format jpg -quality 100 ./^*.jpg
        rm ./^*.jpg


        Recursive:



        find . -type f ! -name '*.jpg' -exec 
        mogrify -format jpg -quality 100 {} + -exec rm {} +





        share|improve this answer
























          3












          3








          3






          To convert all .png and .bmp in the current directory and then remove the original files:



          mogrify -format jpg -quality 100 ./*.{png,bmp}
          rm ./*.{png,bmp}


          To convert all files except .jpg, if your shell supports extended globbing, e.g. bash:



          shopt extglob
          mogrify -format jpg -quality 100 ./*.!(jpg)
          rm ./*.!(jpg)


          or zsh:



          setopt extended_glob
          mogrify -format jpg -quality 100 ./^*.jpg
          rm ./^*.jpg


          Recursive:



          find . -type f ! -name '*.jpg' -exec 
          mogrify -format jpg -quality 100 {} + -exec rm {} +





          share|improve this answer












          To convert all .png and .bmp in the current directory and then remove the original files:



          mogrify -format jpg -quality 100 ./*.{png,bmp}
          rm ./*.{png,bmp}


          To convert all files except .jpg, if your shell supports extended globbing, e.g. bash:



          shopt extglob
          mogrify -format jpg -quality 100 ./*.!(jpg)
          rm ./*.!(jpg)


          or zsh:



          setopt extended_glob
          mogrify -format jpg -quality 100 ./^*.jpg
          rm ./^*.jpg


          Recursive:



          find . -type f ! -name '*.jpg' -exec 
          mogrify -format jpg -quality 100 {} + -exec rm {} +






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 20 '15 at 22:48









          don_crisstidon_crissti

          50.1k15132162




          50.1k15132162























              0














              I've found a further solution using the XNView CLI program nConvert. Here's an installation tutorial for nConvert for Linux.



              The following nConvert command will convert any image formats to jpg, and the rm command will delete all bmp and png files:



              nconvert -out jpeg -o output-##.jpg *.* && rm ./*.{png,bmp}





              share|improve this answer




























                0














                I've found a further solution using the XNView CLI program nConvert. Here's an installation tutorial for nConvert for Linux.



                The following nConvert command will convert any image formats to jpg, and the rm command will delete all bmp and png files:



                nconvert -out jpeg -o output-##.jpg *.* && rm ./*.{png,bmp}





                share|improve this answer


























                  0












                  0








                  0






                  I've found a further solution using the XNView CLI program nConvert. Here's an installation tutorial for nConvert for Linux.



                  The following nConvert command will convert any image formats to jpg, and the rm command will delete all bmp and png files:



                  nconvert -out jpeg -o output-##.jpg *.* && rm ./*.{png,bmp}





                  share|improve this answer














                  I've found a further solution using the XNView CLI program nConvert. Here's an installation tutorial for nConvert for Linux.



                  The following nConvert command will convert any image formats to jpg, and the rm command will delete all bmp and png files:



                  nconvert -out jpeg -o output-##.jpg *.* && rm ./*.{png,bmp}






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 31 '18 at 8:30

























                  answered Dec 31 '18 at 8:17









                  user8547user8547

                  62651435




                  62651435






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f166720%2fconvert-all-non-jpg-images-to-jpgs%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Morgemoulin

                      Scott Moir

                      Souastre