Konvertieren Sie unter Linux eine Reihe von BMP-Dateien in JPEG

32986
JoelFan

Jemand hat mir ein paar BMP-Dateien geschickt und ich brauche sie in JPEG. Ich könnte sie mit GIMP nacheinander konvertieren, aber ich würde es lieber auf einmal tun. Ich habe Ubuntu.

30

5 Antworten auf die Frage

42
hyperslug

Sie können das Mogrify-Werkzeug von ImageMagick verwenden

mogrify -format jpg * .bmp 
Beachten Sie, dass diese Antwort auch für Windows funktioniert, da ImageMagick auch für Windows heruntergeladen werden kann. Gnoupi vor 14 Jahren 1
Es ist "sudo apt install imagemagick" auf Ubuntu und Sie können die Qualität einstellen, indem Sie "-Qualität 100" hinzufügen mpen vor 6 Jahren 0
15
nik

Sie haben wahrscheinlich ImageMagick auf Ubuntu installiert.
Das kann tun ,

convert filename.bmp filename.jpg 

aktualisieren:

Das mogrify(beantwortet von hyperslugund angesprochen von cjm) ist auch eine gute Option.

Verwenden Sie das Programm mogrify, um die Größe eines Bildes zu ändern, die Unschärfe zu ändern, zuzuschneiden, zu entflecken, dither zu zeichnen, zu zeichnen, umzukehren, zu verbinden, neu zu probieren und vieles mehr.
Dieses Tool ähnelt der Konvertierung, mit der Ausnahme, dass die ursprüngliche Bilddatei
mit den -formatgewünschten Änderungen überschrieben wird (es sei denn, Sie ändern das Dateisuffix mit der Option).

Der mogrify-Befehl von ImageMagick ist dafür besser als convert, da er problemlos mit Platzhaltern verwendet werden kann. Siehe die Antwort von hyperslug. cjm vor 14 Jahren 1
6
anonymous

Let me do a little change to salmonmoose answer:

for i in `ls *.bmp`; do convert $i $i.jpg; done 

The above works but generates files named "bmp.jpg". You can get .jpg files with this command:

for i in *.bmp; do convert $ $jpg; done 

See man bash for details of the for command. The $ part means the string "$" without the "bmp" substring at the end.

There are other operations to transform the string in "$". "$i" is a shorthand for "$". The ls *.bmp part in salmonmoose answer means "execute ls *.bmp, then the for i part assigns each string separated by spaces to i". The same is achieved by *.bmp because it matches all file names in the directory.

There is a drawback with for - if the files in your directory have spaces in the name, for example "wedding picture 1.bmp", it will be assigned 3 times to the i var, performing these commands:

convert wedding wedding.jpg convert picture picture.jpg convert 1.bmp 1.bmp.jpg 

In my answer also the match "$" fails.

But there is a solution - you can use the find command instead. See man find for details. You should type something like the following (please check the syntax with the man page before trying it):

find -name *.bmp -type f -exec convert '{}' '{}'.jpg \; 

(I am not very sure of the name part, and I have some doubt in the -exec part, see man find first)

If you want to join all the images in one .jpg file, you can concatenate them with other filter, as the one mentioned in the first answer.

1
salmonmoose
for i in `ls *.bmp`; do convert $i $i.jpg; done 

Ja, dies erzeugt eine Reihe von Dateien mit dem Namen Dateiname.bmp.jpg, erledigt aber die Aufgabe.

0
Matias

Das können Sie mit Hilfe von ImageMagick erreichen. In diesem Link sind Beispiele