Domanda

Sto lavorando a un progetto che prevede di parlare direttamente con le stampanti zebra. Attualmente sto cercando di convertire le immagini in formato GRF usando qualcosa chiamato "Ztools". Ztools sembra essere antico e non sempre converti correttamente il grafico.

Ho iniziato a scavare informazioni sul formato del file PCX da cui si sta convertendo e ora mi trovo in byte terra. Questo è il mio riferimento in questo momento: Riferimento tecnico PCX

Quindi, ho un file PCX di base che ho salvato da Photoshop che è 2x2 e sembrerebbe così:

10
01

Qui è dove sono bloccato, tuttavia. Non ho mai lavorato con byte e sto tentando di leggere il file PCX con PHP usando Fopen ("File", "RB"); e fread. Tuttavia, sembra che non importa quello che faccio, ricevo un sacco di zeri. Qualcuno sa cosa devo fare per convertire i byte in equivalenti numerici?

Questo è il mio debole tentativo:

<?php
$file = "test.pcx";

// Open the file for binary reading (b flag)
$handle = fopen($file, "rb");

while (!feof($handle)) {
    $contents = fread($handle, 1);
    $contents = $contents >> 8;
    echo $contents >> 8;
    $content .= $contents;
}


fclose($handle);
È stato utile?

Soluzione

Sono stato in grado di ottenere le informazioni sull'intestazione con precisione con questo:

<?php
$file = "test.pcx";

function intToBits($int) {
    $return = "00000000";
    if ($int <= 255 && $int >= 0) {
        $check = 128;
        $x = 0;
        while ($int > 0) {
            if ($int > $check) {
                $return[$x] = "1";
            }
            $int -= $check;
            $check /= 2;
            $x++;
        }
    }
    return $return;
}

// Open the file for binary reading (b flag)
$handle = fopen($file, "rb");
$PCX_MAP = array();
$PCX_MAP['Manufacturer'][0] = 1; // Manufacturer
$PCX_MAP['Version'] = 1; // Version Info
$PCX_MAP['Encoding'] = 1; // Encoding
$PCX_MAP['BitsPerPixel'] = 1; // BitsPerPixel
$PCX_MAP['Xmin'] = 2; // Window Xmin
$PCX_MAP['Ymin'] = 2; // Window Ymin
$PCX_MAP['Xmax'] = 2; // Window Xmax
$PCX_MAP['Ymax'] = 2; // Window Ymax
$PCX_MAP['HDpi'] = 2; // HDpi (Resolution)
$PCX_MAP['VDpi'] = 2; // VDpi (Resolution)
$PCX_MAP['colormap'] = 48; // Colormap
$PCX_MAP['Reserved'] = 1; // Reserved = 0
$PCX_MAP['NumberColorPlanes'] = 1; // Number of color planes
$PCX_MAP['BytesPerLine'] = 2; // Bytes Per Line
$PCX_MAP['PalleteInfo'] = 2; // Palette Info
$PCX_MAP['HorizontalScreenSize'] = 2; // H Screen Size
$PCX_MAP['VerticalScreenSize'] = 2; // V Screen Size
$PCX_MAP['Filler'] = 54; // Filler

$length = reset($PCX_MAP);
while (!feof($handle)) {
    if ($length !== false) {
        $contents = fread($handle, $length);
        $contents = ord($contents);
        echo key($PCX_MAP) . " : {$contents}\n";
        $content .= $contents;
        $length = next($PCX_MAP);
    }
    else {
        // Get the rest 1 By 1
        $contents = fread($handle, 1);
        $contents = ord($contents);
        $contents = intToBits($contents);
        echo $contents ."\n";
    }
}


fclose($handle);
/*
$data = file_get_contents($file);

for($i = 0; $i < strlen($data); ++$i) {
    $char = ord($data[$i]);
    echo "Byte $i: $char\n";
}*/

Tuttavia, sto ancora tentando di analizzare i dati dell'immagine.

Questo attualmente restituisce questo:

Manufacturer : 10
Version : 5
Encoding : 1
BitsPerPixel : 1
Xmin : 0
Ymin : 0
Xmax : 3
Ymax : 1
HDpi : 200
VDpi : 200
colormap : 15
Reserved : 0
NumberColorPlanes : 1
BytesPerLine : 2
PalleteInfo : 1
HorizontalScreenSize : 0
VerticalScreenSize : 0
Filler : 0
10000000
11000000
11111110
00000000
11000000
11111110
00000000

Le informazioni sull'intestazione sono corrette, ma non sono sicuro dei dati dopo il riempimento.

Il grafico eseguito in questa istanza è un 4 x 2 - 0 significa bianco, 1 significa nero

0101
1010

Altri suggerimenti

Prova questo:

while (!feof($handle)) {
    $contents = fread($handle, 1);
    $contents = $contents && 0xFF;
    echo $contents;
    $content .= $contents;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top