#!/usr/bin/perl use strict; use CGI ':standard'; use warnings; use CGI::Carp "fatalsToBrowser"; my $do=param('do'); if ($do eq 'showme') { ShowImage(); } elsif ($do eq 'write') { Writeit(); } else { askme(); } sub askme { print header, start_html('Demonstarting Image Magick\'s Annotate function'); print h3('Enter the following fields to use or leave blank to use defaults'), br; print start_form(-method=>"post", -action=>"annotate.cgi", -enctype=>"multipart/form-data"); print 'Enter Text to use: ', br; print 'Find image to use: '; print hidden(-name=>"do", -value=>"write"), p, submit(-value=>" Save "), 'just click "save" and leave blank to use defaults', end_form(), end_html(); exit; } ##end_askme## sub Writeit { my ($file, $ext, $text, $buffer); if (param('image')) { $file=param('image'); if ($file =~ m/^(.+)\.(jpg|jpeg|gif|bmp)$/i ) { $ext=$2; $ext="im_used.$ext"; open (OFILE, "> $ext"); while (my $bytesread = read ($file, $buffer, 1024)) { print OFILE $buffer; } close OFILE; } else { print header, 'Image may be of wrong format'; } } else { $ext='im_before.jpg'; } if (param('text')) { $text=param('text'); } else { $text='Hello! Testing Annotate'; } use Image::Magick; my ($image, $x); $image = Image::Magick->new; $image->Read($ext); warn "$x" if "$x"; $image->Annotate(text=>$text, x=>0, y=>5, fill=>'#FF0000', pointsize=>10); warn "$x" if "$x"; $image->Annotate(text=>$text, x=>15, y=>20, fill=>'blue', pointsize=>60); warn "$x" if "$x"; $image->Annotate(pointsize=>40, fill=>'green', text=>$text); warn "$x" if "$x"; $image->Comment(comment=> 'MAKE IT WORK!!'); warn "$x" if "$x"; $image->Draw(primitive=> 'line', stroke=>'red', points=>'12,12 300,100'); warn "$x" if "$x"; $image->Draw(primitive=> 'text', points=>'40,40 "TEXT ADD"'); warn "$x" if "$x"; $image->Set(quality=>"89"); warn "$x" if "$x"; $image->Write("../im_after.jpg"); warn "$x" if "$x"; no Image::Magick; print header( -refresh=>"2; URL=annotate.cgi?do=showme&text=$text"), h3('Saving Image...'), 'you will be redirected shortly.'; } ##end_sub_Writeit## sub ShowImage { print header(), start_html('Showing Annotate Results'), br 'your text was: "', param('text'), '"'; print h3('This is the result'), ''; print br, 'click here to try another', p, ' click here to use defaults', end_html(); exit; } ##end_sub_ShowImage##