#!/usr/bin/perl -w use CGI qw/:standard/; # load standard CGI routines use GD; # load GD library # create GD image object (width,height) $image = new GD::Image(900,500); # allocate some colors $white = $image->colorAllocate(255,255,255); $black = $image->colorAllocate(0,0,0); $blue = $image->colorAllocate(0,0,255); $red = $image->colorAllocate(255,0,0); # make the background transparent $image->transparent($white); # Put a black frame around the picture $image->rectangle(10,10,890,490,$black); # Create a paintbrush so we can draw a thicker red line $mybrush = new GD::Image(4,4); $brushred = $mybrush->colorAllocate(255,0,0); # remember, first color is background so this will be a solid rectangle $mybrush->rectangle(1,1,2,2,$brushred); # use $mybrush in setBrush for $image which makes this the color gdBrushed $image->setBrush($mybrush); # draw the red rectangle $image->rectangle(20,20,880,480,gdBrushed); # draw lines with alternating color; note each line is one pixel thick $image->line(50,50,850,50,$blue); $image->line(50,51,850,51,$red); $image->line(50,52,850,52,$black); $image->line(50,53,850,53,$blue); $image->line(50,54,850,54,$red); $image->line(50,55,850,55,$black); $image->line(50,56,850,56,$blue); $image->line(50,57,850,57,$red); $image->line(50,58,850,58,$black); $image->line(50,59,850,59,$blue); $image->line(50,60,850,60,$red); $image->line(50,61,850,61,$black); #draw a polygon $mypoly = new GD::Polygon; $mypoly->addPt(400,100); $mypoly->addPt(500,173); $mypoly->addPt(300,173); #draw the polygon $image->polygon($mypoly,$black); #and a blue filled polygon $mypoly = new GD::Polygon; $mypoly->addPt(400,246); $mypoly->addPt(500,173); $mypoly->addPt(300,173); $mypoly->addPt(200,150); #draw the polygon $image->filledPolygon($mypoly,$blue); #and a red filled polygon $mypoly = new GD::Polygon; $mypoly->addPt(400,247); $mypoly->addPt(500,320); $mypoly->addPt(300,320); #draw the polygon $image->filledPolygon($mypoly,$red); #and a polygon $mypoly = new GD::Polygon; $mypoly->addPt(400,393); $mypoly->addPt(500,320); $mypoly->addPt(300,320); #draw the polygon $image->polygon($mypoly,$black); # draw an arc and a circle $image->arc(600,220,30,30,0,360,$black) ; $image->arc(600,320,110,160,180,0,$black) ; #text normal $image->string(gdGiantFont,200,200,"GD",$blue); #text sideways $image->stringUp(gdMediumBoldFont,598,400,"COLOR",$red); # save image as a PNG file $pngimage=$image->png; #open a file for writing; note the address used here $base = "/var/www/html/images/students_06/username/"; #$base=""; $image_file = $base."snoopy_beagle.gif"; open (PNGOutfile, ">$image_file") or die "Unable to open $image_file: $!"; # make sure we are writing to a binary stream binmode PNGOutfile; #write file print PNGOutfile $pngimage; close PNGOutfile; # create the CGI object and send image $q = new CGI; print $q->header('text/html'), $q->start_html, $q->h1('image test'), #note path here is different from path to save file; this is because the way #the server is set up, bioed.bu.edu starts at /usr/local/apache2/www #this will be different on different systems $q-> img({-src=>'https://bioed.bu.edu/images/students_06/username/snoopy_beagle.gif'}), $q->end_html;