How to convert an image to a 24-bit BMP in commandline?

11,811

According to an ImageMagick forum post, using -type truecolor may be the correct way to force the image to 24 bit:

convert "$1" -type truecolor "$1.bmp"
Share:
11,811

Related videos on Youtube

unfa
Author by

unfa

Updated on September 18, 2022

Comments

  • unfa
    unfa over 1 year

    I'm writing a wrapper Bash script for ARSS to make it easier to use. The program converts images to sounds and vice-versa but it only accepts 24-bit BMP images, which I was only able to produce using GIMP so far.

    I'm looking for a way to convert any given image to a suitable BMP file so ARSS can process it. I tried ImageMagic's convert, but I wan't able to get the 24-bt color depth.

    Here's my script:

    #!/bin/bash
    
    # where is ARSS binary?
    ARSS="/unfa/Applications/ARSS/arss-0.2.3-linux-binary/arss"
    
    convert "$1" -depth 24 "$1.bmp"
    
    $ARSS --quiet "$1.bmp" "$1.wav" --sample-rate 48000 --format-param 32 --sine --min-freq 20 --max-freq 20000 --pps 250
    

    Here's the output:

    $ ./warss.sh 01.png
    The Analysis & Resynthesis Sound Spectrograph 0.2.3
    Input file : 01.png.bmp
    Output file : 01.png.wav
    Wrong BMP format, BMP images must be in 24-bit colour
    

    As you can see I tried using convert "$1" -depth 24 "$1.bmp" to get a 24-bit BMP image, but that doesn't work as I expected.

    For reference, I get a proper file while exporting with GIMP:

    enter image description here

    And ARSS processes such a BMP file fine.

    I cannot use that from the commandline however, and using GIMP's GUI every time defies the purpose of what I'm trying to achieve. I saw there's a way to use GIMP in headless mode by feeding it commands, but I don't know if I even need that.

    Maybe there's just something simple I don't know?