0
16bit bmp로 변환하는 코드가 있습니다. 나는 8 비트 bmp 파일을 얻기 위해 무엇을 바꾸거나 추가해야하는지 알아 내려고했지만 여전히 아무것도하지 못했습니다. 난 단지 그 변경 $의 bfOffBitsJPEG를 8bit로 변환합니다. BMP
<?php
//convert jpeg to 16 bit bmp
$jpgImageFile = 'TEST.jpg';
$newFileName = 'NEW_BMP';
$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 * 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;
$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
{
$file = fopen($filename, "wb");
fwrite($file, $result);
fclose($file);
}
return true;
}
?>
질문해야 상상할 수 :이 8 비트에 대한처럼 보이는 방법?
http://php.net/manual/en/function.imagetruecolortopalette.php –
감사 @MarcB하지만이 기능을 사용 GD 라이브러리 등 PNG 및 GIF입니다 :
내 코드 imagick 호출 이것은 잘못된 방식입니다. – MrFreeman555
예, 그리고? gd 라이브러리를 사용하고 있습니다. 'imagecreatefromjpeg'는 어디에서 온 것 같습니까? 이미지를 GD에로드하면 더 이상 gif/jpg/png가 아닙니다. 그것은 GD 이미지입니다. –