#1
  1. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Berlin
    Posts
    7
    Rep Power
    0

    0D Bytes added to dynamic graphics


    I use a Perl-Script to generate simple monochrome bmp graphics. It works fine on the webpage which is hosted by my provider.
    Now I try the same on my WINDOWS homeserver:
    Windows XP, Apache/1.3.41, ActivePerl 5.016001
    I ask for: <img src="/cgi-bin/graftest.pl">
    I write the exact number of resulting Bytes with:
    print ("Content-type: image/bmp\n\n");
    ... printf("%s", chr(daten[$i]) ); ...
    The problem is, if I must write a "0A" anywhere a additional "0D" is added just before "0A".
    I presume, it has something to do with Windows.
    Is there a solution?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    Yes this has to do with Windows. Under Unix, the new line is composed of one character ('\n' or asc-13, or 0D), whereas, under windows, it is composed of two characters (acs-10+asc-13, or '\r\n').

    You probably need to avoid using '\n' in you output, and use direct ASCII translation of the needed input.
  4. #3
  5. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Berlin
    Posts
    7
    Rep Power
    0
    My problem are "0A" Bytes inside the pictures. In the moment I write "0E" in place of "0A" and have an additional pixel. That works.
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    http://perldoc.perl.org/functions/binmode.html
    Set your stream to binary mode, before outputting any \n (or anything at all preferably).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Berlin
    Posts
    7
    Rep Power
    0
    Thanks! Now it works fine.

    print ("Content-type: image/bmp\n\n");
    binmode STDOUT;
    .......
    printf("%s", chr(daten[$i]) );
    .......

IMN logo majestic logo threadwatch logo seochat tools logo