How to convert all the images in a directory to jpg?
up vote
2
down vote
favorite
I have so many different images in a directory with sequential names 1 2 3 4 ...
I was wondering if it was possible to convert all of them to jpg
and resize them all to 900x900 without preserving aspect ratio.
What I tried for the first part is:
$ mogrify -format jpg -- *
But when I do this memory usage increases so quickly and then the process in killed.
What I tried for resizing is:
$ mogrify -resize 900x900 -- *
mogrify: insufficient image data in file `109.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
As I've said the names of the files are sequential numbers. I also have the following:
$ file * | grep -Po "^d*: *K[^:,]*(?=,)" | sort | uniq
ASCII text
GIF image data
JPEG image data
PNG image data
So What is the problem? How can I fix it?
format images resize convert mogrify
add a comment |Â
up vote
2
down vote
favorite
I have so many different images in a directory with sequential names 1 2 3 4 ...
I was wondering if it was possible to convert all of them to jpg
and resize them all to 900x900 without preserving aspect ratio.
What I tried for the first part is:
$ mogrify -format jpg -- *
But when I do this memory usage increases so quickly and then the process in killed.
What I tried for resizing is:
$ mogrify -resize 900x900 -- *
mogrify: insufficient image data in file `109.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
As I've said the names of the files are sequential numbers. I also have the following:
$ file * | grep -Po "^d*: *K[^:,]*(?=,)" | sort | uniq
ASCII text
GIF image data
JPEG image data
PNG image data
So What is the problem? How can I fix it?
format images resize convert mogrify
Do you want to keep or remove the original images after processing?
â Byte Commander
Feb 5 at 10:59
@Byte I want to remove them.
â yukashima huksay
Feb 5 at 11:02
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have so many different images in a directory with sequential names 1 2 3 4 ...
I was wondering if it was possible to convert all of them to jpg
and resize them all to 900x900 without preserving aspect ratio.
What I tried for the first part is:
$ mogrify -format jpg -- *
But when I do this memory usage increases so quickly and then the process in killed.
What I tried for resizing is:
$ mogrify -resize 900x900 -- *
mogrify: insufficient image data in file `109.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
As I've said the names of the files are sequential numbers. I also have the following:
$ file * | grep -Po "^d*: *K[^:,]*(?=,)" | sort | uniq
ASCII text
GIF image data
JPEG image data
PNG image data
So What is the problem? How can I fix it?
format images resize convert mogrify
I have so many different images in a directory with sequential names 1 2 3 4 ...
I was wondering if it was possible to convert all of them to jpg
and resize them all to 900x900 without preserving aspect ratio.
What I tried for the first part is:
$ mogrify -format jpg -- *
But when I do this memory usage increases so quickly and then the process in killed.
What I tried for resizing is:
$ mogrify -resize 900x900 -- *
mogrify: insufficient image data in file `109.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
As I've said the names of the files are sequential numbers. I also have the following:
$ file * | grep -Po "^d*: *K[^:,]*(?=,)" | sort | uniq
ASCII text
GIF image data
JPEG image data
PNG image data
So What is the problem? How can I fix it?
format images resize convert mogrify
format images resize convert mogrify
asked Feb 5 at 10:21
yukashima huksay
272216
272216
Do you want to keep or remove the original images after processing?
â Byte Commander
Feb 5 at 10:59
@Byte I want to remove them.
â yukashima huksay
Feb 5 at 11:02
add a comment |Â
Do you want to keep or remove the original images after processing?
â Byte Commander
Feb 5 at 10:59
@Byte I want to remove them.
â yukashima huksay
Feb 5 at 11:02
Do you want to keep or remove the original images after processing?
â Byte Commander
Feb 5 at 10:59
Do you want to keep or remove the original images after processing?
â Byte Commander
Feb 5 at 10:59
@Byte I want to remove them.
â yukashima huksay
Feb 5 at 11:02
@Byte I want to remove them.
â yukashima huksay
Feb 5 at 11:02
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
I'd recommend using the convert
tool from ImageMagick:
convert input.png -resize 900x900 output.jpg
The -resize
option should be pretty obvious and the output file format is automatically determined using its filename extension.
To run this on all files in the current directory, try this:
for inputfile in ./* ; do
outputfile="$inputfile%.*.jpg"
convert "$inputfile" -resize 900x900 "$outputfile" &&
[[ -e "$outputfile" && "$inputfile" != "$outputfile" ]] && rm "$inputfile"
done
This will take all files fromt he current directory (no matter the file type), and for each input file create the respective output file name by stripping the old extension and adding ".jpg" instead. Then it uses convert
as described above to resize and convert the image, which creates a new file and leaves the original as it is. If that was successful (&&
), check if the output file exists and if the input file name is different from the output file name (e.g. if one of the original files already was a jpg). Now if these conditions are met, we assume we can delete the input file.
why should this work ifmogrify -format jpg -- *
doesn't
â yukashima huksay
Feb 8 at 9:18
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
1
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I thinkconvert
is better as you want to rename the files (extension) when converting to jpg, I assume. Alsoconvert
should recognize the format based on the content (magic number) if no extension is given.
â Byte Commander
Feb 8 at 9:31
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
I'd recommend using the convert
tool from ImageMagick:
convert input.png -resize 900x900 output.jpg
The -resize
option should be pretty obvious and the output file format is automatically determined using its filename extension.
To run this on all files in the current directory, try this:
for inputfile in ./* ; do
outputfile="$inputfile%.*.jpg"
convert "$inputfile" -resize 900x900 "$outputfile" &&
[[ -e "$outputfile" && "$inputfile" != "$outputfile" ]] && rm "$inputfile"
done
This will take all files fromt he current directory (no matter the file type), and for each input file create the respective output file name by stripping the old extension and adding ".jpg" instead. Then it uses convert
as described above to resize and convert the image, which creates a new file and leaves the original as it is. If that was successful (&&
), check if the output file exists and if the input file name is different from the output file name (e.g. if one of the original files already was a jpg). Now if these conditions are met, we assume we can delete the input file.
why should this work ifmogrify -format jpg -- *
doesn't
â yukashima huksay
Feb 8 at 9:18
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
1
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I thinkconvert
is better as you want to rename the files (extension) when converting to jpg, I assume. Alsoconvert
should recognize the format based on the content (magic number) if no extension is given.
â Byte Commander
Feb 8 at 9:31
add a comment |Â
up vote
4
down vote
accepted
I'd recommend using the convert
tool from ImageMagick:
convert input.png -resize 900x900 output.jpg
The -resize
option should be pretty obvious and the output file format is automatically determined using its filename extension.
To run this on all files in the current directory, try this:
for inputfile in ./* ; do
outputfile="$inputfile%.*.jpg"
convert "$inputfile" -resize 900x900 "$outputfile" &&
[[ -e "$outputfile" && "$inputfile" != "$outputfile" ]] && rm "$inputfile"
done
This will take all files fromt he current directory (no matter the file type), and for each input file create the respective output file name by stripping the old extension and adding ".jpg" instead. Then it uses convert
as described above to resize and convert the image, which creates a new file and leaves the original as it is. If that was successful (&&
), check if the output file exists and if the input file name is different from the output file name (e.g. if one of the original files already was a jpg). Now if these conditions are met, we assume we can delete the input file.
why should this work ifmogrify -format jpg -- *
doesn't
â yukashima huksay
Feb 8 at 9:18
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
1
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I thinkconvert
is better as you want to rename the files (extension) when converting to jpg, I assume. Alsoconvert
should recognize the format based on the content (magic number) if no extension is given.
â Byte Commander
Feb 8 at 9:31
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
I'd recommend using the convert
tool from ImageMagick:
convert input.png -resize 900x900 output.jpg
The -resize
option should be pretty obvious and the output file format is automatically determined using its filename extension.
To run this on all files in the current directory, try this:
for inputfile in ./* ; do
outputfile="$inputfile%.*.jpg"
convert "$inputfile" -resize 900x900 "$outputfile" &&
[[ -e "$outputfile" && "$inputfile" != "$outputfile" ]] && rm "$inputfile"
done
This will take all files fromt he current directory (no matter the file type), and for each input file create the respective output file name by stripping the old extension and adding ".jpg" instead. Then it uses convert
as described above to resize and convert the image, which creates a new file and leaves the original as it is. If that was successful (&&
), check if the output file exists and if the input file name is different from the output file name (e.g. if one of the original files already was a jpg). Now if these conditions are met, we assume we can delete the input file.
I'd recommend using the convert
tool from ImageMagick:
convert input.png -resize 900x900 output.jpg
The -resize
option should be pretty obvious and the output file format is automatically determined using its filename extension.
To run this on all files in the current directory, try this:
for inputfile in ./* ; do
outputfile="$inputfile%.*.jpg"
convert "$inputfile" -resize 900x900 "$outputfile" &&
[[ -e "$outputfile" && "$inputfile" != "$outputfile" ]] && rm "$inputfile"
done
This will take all files fromt he current directory (no matter the file type), and for each input file create the respective output file name by stripping the old extension and adding ".jpg" instead. Then it uses convert
as described above to resize and convert the image, which creates a new file and leaves the original as it is. If that was successful (&&
), check if the output file exists and if the input file name is different from the output file name (e.g. if one of the original files already was a jpg). Now if these conditions are met, we assume we can delete the input file.
answered Feb 5 at 11:18
Byte Commander
59.9k26159269
59.9k26159269
why should this work ifmogrify -format jpg -- *
doesn't
â yukashima huksay
Feb 8 at 9:18
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
1
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I thinkconvert
is better as you want to rename the files (extension) when converting to jpg, I assume. Alsoconvert
should recognize the format based on the content (magic number) if no extension is given.
â Byte Commander
Feb 8 at 9:31
add a comment |Â
why should this work ifmogrify -format jpg -- *
doesn't
â yukashima huksay
Feb 8 at 9:18
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
1
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I thinkconvert
is better as you want to rename the files (extension) when converting to jpg, I assume. Alsoconvert
should recognize the format based on the content (magic number) if no extension is given.
â Byte Commander
Feb 8 at 9:31
why should this work if
mogrify -format jpg -- *
doesn'tâ yukashima huksay
Feb 8 at 9:18
why should this work if
mogrify -format jpg -- *
doesn'tâ yukashima huksay
Feb 8 at 9:18
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
I think the problem is that the files does not have extensions
â yukashima huksay
Feb 8 at 9:21
1
1
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I think
convert
is better as you want to rename the files (extension) when converting to jpg, I assume. Also convert
should recognize the format based on the content (magic number) if no extension is given.â Byte Commander
Feb 8 at 9:31
You said memory usage grew too huge, so I replaced your single call with all files at once with a loop processing all images separately. Also I think
convert
is better as you want to rename the files (extension) when converting to jpg, I assume. Also convert
should recognize the format based on the content (magic number) if no extension is given.â Byte Commander
Feb 8 at 9:31
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2f1003218%2fhow-to-convert-all-the-images-in-a-directory-to-jpg%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
Do you want to keep or remove the original images after processing?
â Byte Commander
Feb 5 at 10:59
@Byte I want to remove them.
â yukashima huksay
Feb 5 at 11:02