Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:59:31+00:00 2026-05-30T11:59:31+00:00

I’m working on a project that involves talking directly with Zebra printers. Currently, I

  • 0

I’m working on a project that involves talking directly with Zebra printers. Currently, I am trying to convert images to the GRF format using something called “ztools”. ZTools appears to be ancient and doesn’t always convert the graphic correctly.

I’ve began digging up information on the PCX file format it is converting from and now find myself in byte land. This is my reference at this time: PCX Technical Reference

So, I have a basic PCX file I saved from photoshop that is 2×2 and would look like this:

10
01

This is where I am stuck, however. I’ve never worked with bytes and am attempting to read the pcx file with PHP using fopen(“file”, “rb”); and fread. However, it seems no matter what I do, I get a bunch of zeros. Anyone know what I need to do to convert the bytes to there numeric equivalents?

This is my weak attempt:

<?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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:59:33+00:00Added an answer on May 30, 2026 at 11:59 am

    I was able to get the header information accurately with this:

    <?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";
    }*/
    

    However, I am still attempting to parse the image data.

    This currently returns this:

    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
    

    The header information is correct, but I’m not sure about the data after filler.

    The graphic ran in this instance is a 4 x 2 – 0 means white, 1 means black

    0101
    1010
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.