Convert all png,jpeg,jpg to jpg and compress them using imagemagick
Clash 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?
command-line imagemagick
add a comment |Â
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?
command-line imagemagick
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
add a comment |Â
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?
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
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
add a comment |Â
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
add a comment |Â
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.
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, 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 at 10:15
add a comment |Â
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.
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 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
add a comment |Â
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.
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, 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 at 10:15
add a comment |Â
up vote
5
down vote
accepted
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 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, 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 at 10:15
add a comment |Â
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.
Replace the line:
BASE=`basename $PHOTO`
With this one:
BASE=`basename $PHOTO | cut -d. -f1`
Then try again.
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, 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 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 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, 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 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
add a comment |Â
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.
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 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
add a comment |Â
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.
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 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
add a comment |Â
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.
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 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, 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 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
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 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
add a comment |Â
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
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
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
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
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
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