Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Eu achei uma função mas não sei usar, ela é meio complicada:
public function redimensiona_bmp($filename){
$file = fopen( $filename, "rb" );
$read = fread( $file, 10 );
while( !feof( $file ) && $read != "" ){
$read .= fread( $file, 1024 );
}
$temp = unpack( "H*", $read );
$hex = $temp[1];
$header = substr( $hex, 0, 104 );
$body = str_split( substr( $hex, 108 ), 6 );
if( substr( $header, 0, 4 ) == "424d" ){
$header = substr( $header, 4 );
// Remove some stuff?
$header = substr( $header, 32 );
// Get the width
$width = hexdec( substr( $header, 0, 2 ) );
// Remove some stuff?
$header = substr( $header, 8 );
// Get the height
$height = hexdec( substr( $header, 0, 2 ) );
unset( $header );
}
$x = 0;
$y = 1;
$image = imagecreatetruecolor( $width, $height );
foreach( $body as $rgb ){
$r = hexdec( substr( $rgb, 4, 2 ) );
$g = hexdec( substr( $rgb, 2, 2 ) );
$b = hexdec( substr( $rgb, 0, 2 ) );
$color = imagecolorallocate( $image, $r, $g, $b );
imagesetpixel( $image, $x, $height-$y, $color );
$x++;
if( $x >= $width ){
$x = 0;
$y++;
}
}
return $image; //, me parece que a função retorna essa variável com a imagem bmp, mas usei var_dump nela e não mostrou nada na tela
//daqui para baixo é meu código tentando se adaptar a função acima
$this->img= $image;//variável $image retornada pela função
$x= imagesx($this->img);
$y= imagesy($this->img);
$altura= (int)($y*$this->largura)/$x;
$this->nova= imagecreatetruecolor($this->largura, $altura);
imagecopyresampled($this->nova, $this->img, 0,0,0,0, $this->largura, $altura, $x, $y);
imagejpeg($this->nova, $this->pasta.$this->imagem, 100);
}
redimensiona_bmp('fotos/imagem.bmp');
Alguém tem uma função melhor? ou alguém pode me ensinar como usar essa function?
Função original:
http://br.php.net/manual/en/function.imagecreatefromwbmp.php#83119
Carregando comentários...