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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












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 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 at 14:53










  • I know it did just offering alternative syntax!
    – George Udosen
    Aug 25 at 14:55










  • @GeorgeUdosen oh ok , thanks ;)
    – cgDev
    Aug 25 at 15:10










  • @GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
    – Sergiy Kolodyazhnyy
    Aug 25 at 15:23














up vote
4
down vote

favorite












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 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 at 14:53










  • I know it did just offering alternative syntax!
    – George Udosen
    Aug 25 at 14:55










  • @GeorgeUdosen oh ok , thanks ;)
    – cgDev
    Aug 25 at 15:10










  • @GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
    – Sergiy Kolodyazhnyy
    Aug 25 at 15:23












up vote
4
down vote

favorite









up vote
4
down vote

favorite











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?









share|improve this question











share|improve this question




share|improve this question










asked Aug 25 at 14:32









cgDev

376




376











  • That's because you have this $BASE.jpg it should be $BASE%%.*.jpg
    – George Udosen
    Aug 25 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 at 14:53










  • I know it did just offering alternative syntax!
    – George Udosen
    Aug 25 at 14:55










  • @GeorgeUdosen oh ok , thanks ;)
    – cgDev
    Aug 25 at 15:10










  • @GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
    – Sergiy Kolodyazhnyy
    Aug 25 at 15:23
















  • That's because you have this $BASE.jpg it should be $BASE%%.*.jpg
    – George Udosen
    Aug 25 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 at 14:53










  • I know it did just offering alternative syntax!
    – George Udosen
    Aug 25 at 14:55










  • @GeorgeUdosen oh ok , thanks ;)
    – cgDev
    Aug 25 at 15:10










  • @GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
    – Sergiy Kolodyazhnyy
    Aug 25 at 15:23















That's because you have this $BASE.jpg it should be $BASE%%.*.jpg
– George Udosen
Aug 25 at 14:51




That's because you have this $BASE.jpg it should be $BASE%%.*.jpg
– George Udosen
Aug 25 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 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 at 14:53












I know it did just offering alternative syntax!
– George Udosen
Aug 25 at 14:55




I know it did just offering alternative syntax!
– George Udosen
Aug 25 at 14:55












@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 at 15:10




@GeorgeUdosen oh ok , thanks ;)
– cgDev
Aug 25 at 15:10












@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 at 15:23




@GeorgeUdosen The alternative syntax is good enough as an answer,too. Please post
– Sergiy Kolodyazhnyy
Aug 25 at 15:23










2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted










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 at 14:45







  • 1




    I tryed now and it didn't duplicate the images, strange..
    – cgDev
    Aug 25 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 at 10:15


















up vote
8
down vote













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 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 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 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',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
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






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










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 at 14:45







  • 1




    I tryed now and it didn't duplicate the images, strange..
    – cgDev
    Aug 25 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 at 10:15















up vote
5
down vote



accepted










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 at 14:45







  • 1




    I tryed now and it didn't duplicate the images, strange..
    – cgDev
    Aug 25 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 at 10:15













up vote
5
down vote



accepted







up vote
5
down vote



accepted






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 at 15:59









George Udosen

16.9k93559




16.9k93559










answered Aug 25 at 14:39









Parto

9,0381864100




9,0381864100











  • Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
    – cgDev
    Aug 25 at 14:45







  • 1




    I tryed now and it didn't duplicate the images, strange..
    – cgDev
    Aug 25 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 at 10:15

















  • Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
    – cgDev
    Aug 25 at 14:45







  • 1




    I tryed now and it didn't duplicate the images, strange..
    – cgDev
    Aug 25 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 at 10:15
















Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 at 14:45





Its close, but it duplicates also the images adding "imgOne-0.jpg", "imgTwo-1.jpg", etc...
– cgDev
Aug 25 at 14:45





1




1




I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 at 15:04




I tryed now and it didn't duplicate the images, strange..
– cgDev
Aug 25 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 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 at 10:15













up vote
8
down vote













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 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 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 at 10:18














up vote
8
down vote













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 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 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 at 10:18












up vote
8
down vote










up vote
8
down vote









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 at 19:00

























answered Aug 25 at 15:59









George Udosen

16.9k93559




16.9k93559











  • 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 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 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 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 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 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 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 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 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 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 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 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 at 10:18

















 

draft saved


draft discarded















































 


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













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

What does second last employer means? [closed]

One-line joke