Convert all png,jpeg,jpg to jpg and compress them using imagemagick










4















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?










share|improve this question






















  • 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















4















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?










share|improve this question






















  • 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













4












4








4








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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










2 Answers
2






active

oldest

votes


















5














Replace the line:



BASE=`basename $PHOTO`


With this one:



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


Then try again.






share|improve this answer

























  • 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, 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



















8














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.






share|improve this answer

























  • 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











  • 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










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
);



);













draft saved

draft discarded


















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









5














Replace the line:



BASE=`basename $PHOTO`


With this one:



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


Then try again.






share|improve this answer

























  • 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, 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
















5














Replace the line:



BASE=`basename $PHOTO`


With this one:



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


Then try again.






share|improve this answer

























  • 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, 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














5












5








5







Replace the line:



BASE=`basename $PHOTO`


With this one:



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


Then try again.






share|improve this answer















Replace the line:



BASE=`basename $PHOTO`


With this one:



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


Then try again.







share|improve this answer














share|improve this answer



share|improve this answer








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, 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


















  • 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, 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

















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














8














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.






share|improve this answer

























  • 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











  • 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















8














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.






share|improve this answer

























  • 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











  • 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













8












8








8







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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, 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











  • 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











  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)