Convert all non-JPG images to JPGs
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
|
show 1 more comment
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
What have you tried? Have you looked into theconvert
utility that comes withImageMagick
, 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 tomogrify
.
– Bananguin
Nov 7 '14 at 21:11
@Bananguin - apparently,ImageMagick
devs don't share your opinion.
– don_crissti
Nov 7 '14 at 23:03
|
show 1 more comment
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
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
command conversion images
asked Nov 7 '14 at 20:55
user8547user8547
62651435
62651435
What have you tried? Have you looked into theconvert
utility that comes withImageMagick
, 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 tomogrify
.
– Bananguin
Nov 7 '14 at 21:11
@Bananguin - apparently,ImageMagick
devs don't share your opinion.
– don_crissti
Nov 7 '14 at 23:03
|
show 1 more comment
What have you tried? Have you looked into theconvert
utility that comes withImageMagick
, 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 tomogrify
.
– 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
|
show 1 more comment
3 Answers
3
active
oldest
votes
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.
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$ Thels
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 theconvert
linerm ${FILENAME}
, which will delete the original file.
– Bananguin
Nov 8 '14 at 14:30
|
show 9 more comments
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 {} +
add a comment |
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}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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$ Thels
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 theconvert
linerm ${FILENAME}
, which will delete the original file.
– Bananguin
Nov 8 '14 at 14:30
|
show 9 more comments
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.
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$ Thels
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 theconvert
linerm ${FILENAME}
, which will delete the original file.
– Bananguin
Nov 8 '14 at 14:30
|
show 9 more comments
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.
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.
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$ Thels
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 theconvert
linerm ${FILENAME}
, which will delete the original file.
– Bananguin
Nov 8 '14 at 14:30
|
show 9 more comments
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$ Thels
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 theconvert
linerm ${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
|
show 9 more comments
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 {} +
add a comment |
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 {} +
add a comment |
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 {} +
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 {} +
answered May 20 '15 at 22:48
don_crisstidon_crissti
50.1k15132162
50.1k15132162
add a comment |
add a comment |
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}
add a comment |
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}
add a comment |
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}
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}
edited Dec 31 '18 at 8:30
answered Dec 31 '18 at 8:17
user8547user8547
62651435
62651435
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What have you tried? Have you looked into the
convert
utility that comes withImageMagick
, 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