How to convert gif image to Hex using PHP code

Posted on 2009-05-02
Last Modified: 2012-05-06
Hi, I need to convert gif or jpg image to OTA format and from OTA to  Hex code to send the picture sms using php code. Please help me to get the complete code.
Question by:Pinnacle411
    LVL 20

    Expert Comment

    Seeing the format described e.g. in, I'd first convert to an uncompressed b/w bitmap (hopefully with a width a multiple of 8). Then it's just a matter of outputing the simple header and then the bytes one by one.
    LVL 16

    Expert Comment


    Author Comment

    I have tried all the links you give me, but I am not very good in other languages, Can someone  please  give me the complete php code.
    LVL 20

    Accepted Solution

    In the following code that uses the GD library, write an output(x) routine according to your needs: It may output x as binary octet or as two hex digits, according to whether you want binary or hex OTA data.
    $im = imagecreatefromgif($imgname);
    $width = imagesx($im); // must be < 256 (and >0)
    $height = imagesy($im); // must be < 256 (and >0)
    $byteac = 1;
    for ($y=0; $y<$height; ++$y) {
      for ($x=0; $x<$width; ++%x) {
        $c = imagecolorat($im, $x, $y);
        $byteac += $byteac;
        if ($c > 0) { // or whatever color(s) shall become black
        if ($byteac >= 256) {
          output($byteac - 256);
          $byteac = 1;
    while ($byteac < 256) {
      $byteac += $byteac;
    if ($byteac > 256) {

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now