To może tak:
<?php
$jpgImageFile = 'Myjpg.jpg';
$newFileName = 'MyBmp';
$imageSource = imagecreatefromjpeg($jpgImageFile);
imagebmp($imageSource,$newFileName.".bmp");
function imagebmp(&$im, $filename = "")
{
if (!$im) return false;
$w = imagesx($im);
$h = imagesy($im);
$result = '';
if (!imageistruecolor($im)) {
$tmp = imagecreatetruecolor($w, $h);
imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h);
imagedestroy($im);
$im = & $tmp;
}
$biBPLine = $w * 3;
$biStride = ($biBPLine + 3) & ~3;
$biSizeImage = $biStride * $h;
$bfOffBits = 54;
$bfSize = $bfOffBits + $biSizeImage;
$result .= substr('BM', 0
, 2
); $result .= pack ('VvvV', $bfSize, 0
, 0
, $bfOffBits); $result .= pack ('VVVvvVVVVVV', 40
, $w, $h, 1
, 24
, 0
, $biSizeImage, 0
, 0
, 0
, 0
);
$numpad = $biStride - $biBPLine;
for ($y = $h - 1; $y >= 0; --$y) {
for ($x = 0; $x < $w; ++$x) {
$col = imagecolorat ($im, $x, $y);
}
for ($i = 0; $i < $numpad; ++$i)
$result .= pack ('C', 0
); }
if($filename==""){
}
else
{
$file = fopen($filename, "wb"); }
return true;
}
?>
albo:
<?php
function imagebmp(&$im, $filename = "")
{
if (!$im) return false;
$w = imagesx($im);
$h = imagesy($im);
$result = '';
if (!imageistruecolor($im)) {
$tmp = imagecreatetruecolor($w, $h);
imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h);
imagedestroy($im);
$im = & $tmp;
}
$biBPLine = $w * 2;
$biStride = ($biBPLine + 3) & ~3;
$biSizeImage = $biStride * $h;
$bfOffBits = 66;
$bfSize = $bfOffBits + $biSizeImage;
$result .= substr('BM', 0
, 2
); $result .= pack ('VvvV', $bfSize, 0
, 0
, $bfOffBits); $result .= pack ('VVVvvVVVVVV', 40
, $w, '-'.$h, 1
, 16
, 3
, $biSizeImage, 0
, 0
, 0
, 0
); $numpad = $biStride - $biBPLine;
//for ($y = $h - 1; $y >= 0; --$y) {
$result .= pack('VVV',63488
,2016
,31
); for ($y = 0; $y < $h; ++$y) {
for ($x = 0; $x < $w; ++$x) {
$rgb = imagecolorat($im, $x, $y);
$r24 = ($rgb >> 16) & 0xFF;
$g24 = ($rgb >> 8) & 0xFF;
$b24 = $rgb & 0xFF;
$col = ((($r24 >> 3) << 11) | (($g24 >> 2) << 5) | ($b24 >> 3));
$result .= pack('v',$col); }
for ($i = 0; $i < $numpad; ++$i)
$result .= pack ('C', 0
); }
if($filename==""){
}
else
{
header( "Content-type: image/bmp" ); imagedestroy( $result );
}
return true;
}
?>