djpeg to convert jpeg images to .gif,.bmp etc

djpeg(Decompress jpeg) command can be used to convert the jpg or jpeg format images into .bmp ,.gif and other formats.

For example let us say we have a jpg file by the name temp.jpg. We can find the size of the file using the command du.

$du temp.jpg 24K temp.jpg $

We can use the command djpeg on this file to convert it to a .gif file.

$djpeg -gif -outfile temp.gif temp.jpg


“-gif” : To specify the output the file to be of type .gif
“-outfilename” : To specify the output file name which is given above as temp.gif

After executing the command we can see the new temp.gif file in the same folder.

$ls temp.jpg temp.gif $du temp.* 288K temp.gif 24K temp.jpg

Thus we can see that the new file “temp.gif” has been created and it is bigger than the .jpg file as it is a decompressed file.

Insted of “-gif” we can pass the option “-bmp” to convert the image to .bmp format.

We can also remove the color from the image and make it a grayscale image from the .jpg image by passing the option “-grayscale”

$djpeg -bmp -grayscale -outfile temp.bmp temp.jpg

We can also scale images,make them smaller, using the option -scale, where the value of scale can be any number between 1 and 16, which is the scaling factor.

$ djpeg -gif -scale 2 -outfile temp2.gif temp.jpg

The file created above will be scaled by a factor 2/8, where 8 is the default DCT size.

$ du temp* 288K temp.gif 164K temp2.gif 24K temp.jpg

We can see above that temp2.gif is of smaller size than temp.gif as it has been scaled.

Tags: ,
Copyright 2017. All rights reserved.

Posted June 3, 2013 by Tux Think in category "Linux