Re: Odd Request: Image 2 HEX
| From: | Richard Lynch | Date: | Wed, 10 Jul 2002 23:09:33 +0000 |
| Subject: | Re: Odd Request: Image 2 HEX | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-107053@lists.php.net to get a copy of this message | ||
>I'm using a Zebra label printer in an application I have and in order to
>display an image on the label, according to the ZPL II printer language,
>any image must be converted to HEX code. Does anyone hvae a code snippet or
>know of a free utility that will take a graphic image (BMP, GIF, JPG,
>etc...) and convert it to HEX values?
Something not unlike this may work...
<?php
$image = 'sample.bmp';
$file = fopen($image, 'r') or die("Could not open $image");
while ($file && !feof($file)){
$chunk = fread($file, 1000000); # You can affect performance altering
this number. YMMV.
# This loop will be dog-slow, almost for sure...
# You could snag two or three bytes and shift/add them,
# but at 4 bytes, you violate the 7fffffff limit of dechex...
# You could maybe write a better dechex that would accept multiple bytes
# and use substr... Maybe.
for ($byte = 0; $byte < strlen($chunk); $byte++)){
echo dechex(ord($chunk[$byte]));
}
}
?>
--
Like Music? http://l-i-e.com/artists.htm