in reply to jpg to bmp in Windows
If you have GD this will work for 24-bit color jpgs:
#! perl -slw use strict; use GD; my $img = GD::Image->newFromJpeg( $ARGV[ 0 ], 1 ) or die "$ARGV[ 0 ] : $!"; my( $width, $height ) = $img->getBounds(); ( my $bmpFile = $ARGV[ 0 ] ) =~ s[.jpg$][.bmp]i; open BMP, '>:raw', $bmpFile or die "$bmpFile : $!"; binmode BMP; printf BMP '%s', pack 'A2ISSI', 'BM', $width * $height +54, 0, 0, 54; printf BMP '%s', pack 'IiiSSIIiiII', 40, $width, $height, 1, 24, 0, $width * $height, 11811, 11811, 0, +0; for my $y ( reverse 0 .. $height-1 ) { for my $x ( 0 .. $width-1 ) { printf BMP '%s', pack 'CCC', reverse $img->rgb( $img->getPixel +( $x, $y ) ); } } close BMP;
Other color depths take a little more effort and it could be sped up quite easily.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: jpg to bmp in Windows
by jettero (Monsignor) on Jun 05, 2007 at 13:33 UTC | |
by BrowserUk (Patriarch) on Jun 05, 2007 at 15:25 UTC | |
|
Re^2: jpg to bmp in Windows
by Anonymous Monk on Sep 02, 2008 at 14:28 UTC | |
by BrowserUk (Patriarch) on Sep 02, 2008 at 16:09 UTC |