zoh
Новичок
Преобразование tga to jpg
Всем привет!
Помогите с кодом.
В иотге выводиться мягко говоря не то что нужно
Вот
Всем привет!
Помогите с кодом.
PHP:
function imagecreatefromtga ( $filename, $return_array = 0 )
{
$handle = fopen ( $filename, 'rb' );
$data = fread ( $handle, filesize( $filename ) );
fclose ( $handle );
$pointer = 18;
$x = 0;
$y = 0;
$w = base_convert ( bin2hex ( strrev ( substr ( $data, 12, 2 ) ) ), 16, 10 );
$h = base_convert ( bin2hex ( strrev ( substr ( $data, 14, 2 ) ) ), 16, 10 );
$img = imagecreatetruecolor( $w, $h );
while ( $pointer < strlen ( $data ) )
{
imagesetpixel ( $img, $x, $y, base_convert ( bin2hex ( strrev ( substr ( $data, $pointer, 3 ) ) ), 16, 10 ) );
$x++;
if ($x == $w)
{
$y++;
$x=0;
}
$pointer += 3;
}
if ( $return_array )
return array ( $img, $w, $h );
else
return $img;
}
$resource_image = imagecreatefromtga ( "source_image.tga" );
// Declare the content-type as a JPEG image.
header ( 'Content-type: image/jpeg' );
// Convert the image to JPEG for smaller file size and compatability
imagejpeg ( $resource_image, NULL, 100 );
imagedestroy ( $resource_image );
Вот