Convert all png,jpeg,jpg to jpg and compress them using imagemagick
Im almost there with this code:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=`basename $PHOTO`
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE.jpg"
done
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?
command-line imagemagick
add a comment |
Im almost there with this code:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=`basename $PHOTO`
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE.jpg"
done
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?
command-line imagemagick
That's because you have this$BASE.jpg
it should be$BASE%%.*.jpg
– George Udosen
Aug 25 '18 at 14:51
@GeorgeUdosen the answer of Parto worked but its also duplicating the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:53
I know it did just offering alternative syntax!
– George Udosen
Aug 25 '18 at 14:55
@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 '18 at 15:10
@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 '18 at 15:23
add a comment |
Im almost there with this code:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=`basename $PHOTO`
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE.jpg"
done
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?
command-line imagemagick
Im almost there with this code:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=`basename $PHOTO`
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE.jpg"
done
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?
command-line imagemagick
command-line imagemagick
asked Aug 25 '18 at 14:32
cgDevcgDev
547
547
That's because you have this$BASE.jpg
it should be$BASE%%.*.jpg
– George Udosen
Aug 25 '18 at 14:51
@GeorgeUdosen the answer of Parto worked but its also duplicating the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:53
I know it did just offering alternative syntax!
– George Udosen
Aug 25 '18 at 14:55
@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 '18 at 15:10
@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 '18 at 15:23
add a comment |
That's because you have this$BASE.jpg
it should be$BASE%%.*.jpg
– George Udosen
Aug 25 '18 at 14:51
@GeorgeUdosen the answer of Parto worked but its also duplicating the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:53
I know it did just offering alternative syntax!
– George Udosen
Aug 25 '18 at 14:55
@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 '18 at 15:10
@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 '18 at 15:23
That's because you have this
$BASE.jpg
it should be $BASE%%.*.jpg
– George Udosen
Aug 25 '18 at 14:51
That's because you have this
$BASE.jpg
it should be $BASE%%.*.jpg
– George Udosen
Aug 25 '18 at 14:51
@GeorgeUdosen the answer of Parto worked but its also duplicating the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:53
@GeorgeUdosen the answer of Parto worked but its also duplicating the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:53
I know it did just offering alternative syntax!
– George Udosen
Aug 25 '18 at 14:55
I know it did just offering alternative syntax!
– George Udosen
Aug 25 '18 at 14:55
@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 '18 at 15:10
@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 '18 at 15:10
@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 '18 at 15:23
@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 '18 at 15:23
add a comment |
2 Answers
2
active
oldest
votes
Replace the line:
BASE=`basename $PHOTO`
With this one:
BASE=`basename $PHOTO | cut -d. -f1`
Then try again.
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
1
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
Please remember to quote all variables, asBASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, thecut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.
– Paddy Landau
Aug 28 '18 at 10:15
add a comment |
Modify you code into this form:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=$(basename $PHOTO)
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE%.*.jpg"
done
Rather than this $BASE.jpg
use $BASE%.*
then add the extension.
You might want"$BASE%.*"
to use the shortest matching suffix pattern, somy.long.filename.jpg
turns intomy.long.filename.jpg
, notmy.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.
– Peter Cordes
Aug 25 '18 at 18:46
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Please add quotes:BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.
– Paddy Landau
Aug 28 '18 at 10:18
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1068859%2fconvert-all-png-jpeg-jpg-to-jpg-and-compress-them-using-imagemagick%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Replace the line:
BASE=`basename $PHOTO`
With this one:
BASE=`basename $PHOTO | cut -d. -f1`
Then try again.
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
1
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
Please remember to quote all variables, asBASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, thecut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.
– Paddy Landau
Aug 28 '18 at 10:15
add a comment |
Replace the line:
BASE=`basename $PHOTO`
With this one:
BASE=`basename $PHOTO | cut -d. -f1`
Then try again.
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
1
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
Please remember to quote all variables, asBASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, thecut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.
– Paddy Landau
Aug 28 '18 at 10:15
add a comment |
Replace the line:
BASE=`basename $PHOTO`
With this one:
BASE=`basename $PHOTO | cut -d. -f1`
Then try again.
Replace the line:
BASE=`basename $PHOTO`
With this one:
BASE=`basename $PHOTO | cut -d. -f1`
Then try again.
edited Aug 25 '18 at 15:59
George Udosen
20.4k94367
20.4k94367
answered Aug 25 '18 at 14:39
PartoParto
9,3561965104
9,3561965104
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
1
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
Please remember to quote all variables, asBASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, thecut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.
– Paddy Landau
Aug 28 '18 at 10:15
add a comment |
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
1
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
Please remember to quote all variables, asBASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, thecut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.
– Paddy Landau
Aug 28 '18 at 10:15
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:45
1
1
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 '18 at 15:04
Please remember to quote all variables, as
BASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, the cut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.– Paddy Landau
Aug 28 '18 at 10:15
Please remember to quote all variables, as
BASE="$( basename "$PHOTO" | cut -d. -f1 )"
(note two sets of quotation marks). Without them, if any file name contains a space or certain special characters, you run the risk of data corruption. Also, the cut
command won't work if a file name contains two or more dots; this needs to be changed; it can also, in certain cases, cause data being overwritten. The answer by @GeorgeUdosen provides a good option.– Paddy Landau
Aug 28 '18 at 10:15
add a comment |
Modify you code into this form:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=$(basename $PHOTO)
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE%.*.jpg"
done
Rather than this $BASE.jpg
use $BASE%.*
then add the extension.
You might want"$BASE%.*"
to use the shortest matching suffix pattern, somy.long.filename.jpg
turns intomy.long.filename.jpg
, notmy.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.
– Peter Cordes
Aug 25 '18 at 18:46
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Please add quotes:BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.
– Paddy Landau
Aug 28 '18 at 10:18
add a comment |
Modify you code into this form:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=$(basename $PHOTO)
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE%.*.jpg"
done
Rather than this $BASE.jpg
use $BASE%.*
then add the extension.
You might want"$BASE%.*"
to use the shortest matching suffix pattern, somy.long.filename.jpg
turns intomy.long.filename.jpg
, notmy.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.
– Peter Cordes
Aug 25 '18 at 18:46
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Please add quotes:BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.
– Paddy Landau
Aug 28 '18 at 10:18
add a comment |
Modify you code into this form:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=$(basename $PHOTO)
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE%.*.jpg"
done
Rather than this $BASE.jpg
use $BASE%.*
then add the extension.
Modify you code into this form:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.png,jpeg,jpg
do
BASE=$(basename $PHOTO)
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE%.*.jpg"
done
Rather than this $BASE.jpg
use $BASE%.*
then add the extension.
edited Aug 25 '18 at 19:00
answered Aug 25 '18 at 15:59
George UdosenGeorge Udosen
20.4k94367
20.4k94367
You might want"$BASE%.*"
to use the shortest matching suffix pattern, somy.long.filename.jpg
turns intomy.long.filename.jpg
, notmy.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.
– Peter Cordes
Aug 25 '18 at 18:46
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Please add quotes:BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.
– Paddy Landau
Aug 28 '18 at 10:18
add a comment |
You might want"$BASE%.*"
to use the shortest matching suffix pattern, somy.long.filename.jpg
turns intomy.long.filename.jpg
, notmy.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.
– Peter Cordes
Aug 25 '18 at 18:46
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Please add quotes:BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.
– Paddy Landau
Aug 28 '18 at 10:18
You might want
"$BASE%.*"
to use the shortest matching suffix pattern, so my.long.filename.jpg
turns into my.long.filename.jpg
, not my.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.– Peter Cordes
Aug 25 '18 at 18:46
You might want
"$BASE%.*"
to use the shortest matching suffix pattern, so my.long.filename.jpg
turns into my.long.filename.jpg
, not my.jpg
. Also, worth checking that the output doesn't already exist, in case of collisions between different source suffixes.– Peter Cordes
Aug 25 '18 at 18:46
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Also worth checking if the output file is actually smaller than the input, otherwise just copy or link. (Or check if the input jpg quality setting was below some threshold, but just comparing file size after an attempted recompression is easier and always works.)
– Peter Cordes
Aug 25 '18 at 18:47
Please add quotes:
BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.– Paddy Landau
Aug 28 '18 at 10:18
Please add quotes:
BASE="$( basename "$PHOTO" )"
(two sets of quotes), in case the file name contains a space or certain other special characters.– Paddy Landau
Aug 28 '18 at 10:18
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1068859%2fconvert-all-png-jpeg-jpg-to-jpg-and-compress-them-using-imagemagick%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
That's because you have this
$BASE.jpg
it should be$BASE%%.*.jpg
– George Udosen
Aug 25 '18 at 14:51
@GeorgeUdosen the answer of Parto worked but its also duplicating the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 '18 at 14:53
I know it did just offering alternative syntax!
– George Udosen
Aug 25 '18 at 14:55
@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 '18 at 15:10
@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 '18 at 15:23