Convert .JPG or .PNG to .ICO using terminal and back

Is there a command I can use to convert a .jpg or .png or other to extension to a .ico? If possible also to resize it to be a favicon size?

I'd also like to turn it from .ico to .jpg or .png.

3 Answers

The most useful program (suite) to manipulate image is Imagemagick (sudo apt install imagemagick) and for this task you will need the convert binary.

You will need to use something like:

convert -resize x16 -gravity center -crop 16x16+0+0 input.png -flatten -colors 256 -background transparent output/favicon.ico
2

This is the best command to do that from console:

convert <your-image-here> -define icon:auto-resize=256,64,48,32,16 favicon.ico

Hope you like it!

1

Use this zsh function:

png2ico () { local i="${1}" o="${2:-${1:r}.ico}" s="${png2ico_size:-256}" convert -resize x${s} -gravity center -crop ${s}x${s}+0+0 "$i" -flatten -colors 256 -background transparent "$o"
}

Like so:

png2ico input.png
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like