Here is what I have so far. It causes an gd-jpeg: JPEG library reports unrecoverable error: and crashes perl. Any ideas?
#!/usr/bin/perl -w use strict; use GD; use File::Slurp; my $width = 102; my $height = 123; my $truecolor; my $x; my $y; my $image = GD::Image->new([$width,$height],$truecolor); my $dbz1 = $image->colorAllocate(0,0,0); #-30 my $dbz2 = $image->colorAllocate(204,255,255); #-28 my $dbz3 = $image->colorAllocate(204,153,204); #-25 my $dbz4 = $image->colorAllocate(153,102,153); #-20 my $dbz5 = $image->colorAllocate(102,51,102); #-15 my $dbz6 = $image->colorAllocate(204,204,153); #-10 my $dbz7 = $image->colorAllocate(153,153,102); #-5 my $dbz8 = $image->colorAllocate(102,102,51); #0 my $dbz9 = $image->colorAllocate(102,255,255); #5 my $dbz10 = $image->colorAllocate(51,153,255); #10 my $dbz11 = $image->colorAllocate(0,0,255); #15 my $dbz12 = $image->colorAllocate(0,255,0); #20 my $dbz13 = $image->colorAllocate(0,204,0); #25 my $dbz14 = $image->colorAllocate(0,153,0); #30 my $dbz15 = $image->colorAllocate(255,255,0); #35 my $dbz16 = $image->colorAllocate(255,204,0); #40 my $dbz17 = $image->colorAllocate(255,104,0); #45 my $dbz18 = $image->colorAllocate(255,0,0); #50 my $dbz19 = $image->colorAllocate(204,51,0); #55 my $dbz20 = $image->colorAllocate(153,0,0); #60 my $dbz21 = $image->colorAllocate(255,0,255); #65 my $dbz22 = $image->colorAllocate(153,51,204); #70 my $dbz23 = $image->colorAllocate(255,255,255); #75 my $dbz24 = $image->colorAllocate(255,255,255); #80 print "$dbz1\n"; my @data = read_file('test_image.txt'); print "@data\n"; for($y=1;$y <= $height;$y++){ for($x=1;$x <= $width;$x++){ my $pixel = $x*$y-1; print "Pixel Value: $data[$pixel]\n"; if ($data[$pixel] == 0){ $image->setPixel($x,$y,$dbz1); } if ($data[$pixel] > 0 and $data[$pixel] <= 10){ $image->setPixel($x,$y,$dbz5); } if ($data[$pixel] > 10 and $data[$pixel] <= 20){ $image->setPixel($x,$y,$dbz10); } if ($data[$pixel] > 20 and $data[$pixel] <= 30){ $image->setPixel($x,$y,$dbz15); } } } my $jpeg = $image->jpeg(); open JPEG,'>','test_image.jpg' || die; print JPEG $jpeg; #~ my $gif = $image->gif(); #~ open GIF,'>','test_image2.gif' || die; #~ print GIF $gif; exit;

In reply to Re^2: Using text data in GD(or other) by deadpickle
in thread Using text data in GD(or other) by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.