# draw_timeline_wikipedia.pl, 4 Sep 2007 # License: GPL # JadiJadi@gmail.com # www.FreeKeyboard.net # این برنامه یک فایل را می‌گیرد که حاوی سورس صفحاتی است که تاریخچه یک مدخل ویکپدیای فارسی را نشان می دهند. سپس تعداد ویرایش‌های هر روز را استخراج می‌کند و با استفاده از کتابخانه GD نمودار متناسب را تولید می‌کند. use GD; use List::Util qw(max); $inputFileName = 'Input File Name'; $height=400; $marginbot=10; $margintop=15; $marginleft = 30; $hx = $height-60; $width=800; %data = (); for ($y=2006; $y<=2007; $y++) { for ($i=1; $i<=31; $i++) {$data{"$i 01 $y"}=0; push(@dateList,"$i 01 $y" ); } for ($i=1; $i<=28; $i++) {$data{"$i 02 $y"}=0; push(@dateList,"$i 02 $y" ); } for ($i=1; $i<=31; $i++) {$data{"$i 03 $y"}=0; push(@dateList,"$i 03 $y" ); } for ($i=1; $i<=30; $i++) {$data{"$i 04 $y"}=0; push(@dateList,"$i 04 $y" ); } for ($i=1; $i<=31; $i++) {$data{"$i 05 $y"}=0; push(@dateList,"$i 05 $y" ); } for ($i=1; $i<=30; $i++) {$data{"$i 06 $y"}=0; push(@dateList,"$i 06 $y" ); } for ($i=1; $i<=31; $i++) {$data{"$i 07 $y"}=0; push(@dateList,"$i 07 $y" ); } for ($i=1; $i<=31; $i++) {$data{"$i 08 $y"}=0; push(@dateList,"$i 08 $y" ); } for ($i=1; $i<=30; $i++) {$data{"$i 09 $y"}=0; push(@dateList,"$i 09 $y" ); } for ($i=1; $i<=31; $i++) {$data{"$i 10 $y"}=0; push(@dateList,"$i 10 $y" ); } for ($i=1; $i<=30; $i++) {$data{"$i 11 $y"}=0; push(@dateList,"$i 11 $y" ); } for ($i=1; $i<=31; $i++) {$data{"$i 12 $y"}=0; push(@dateList,"$i 12 $y" ); } } # create a new image $im = new GD::Image($width, $height); # allocate some colors $white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $red = $im->colorAllocate(255,0,0); $blue = $im->colorAllocate(100,100,250); $vlgray = $im->colorAllocate(220,220,220); $lgray = $im->colorAllocate(180,180,180); $gray = $im->colorAllocate(140,140,140); # make the background transparent and interlaced #$im->transparent($white); $im->interlaced('true'); %months = ('ژانویه', '01', 'فوریه', '02', 'مارس', '03', 'آوریل', '04', 'مه', '05', 'ژوئن', '06', 'ژوئیه', '07', 'اوت', '08', 'سپتامبر', '09', 'اکتبر', '10', 'نوامبر', '11', 'دسامبر', '12' ); open(DAT, $inputFileName) || die("Could not open file!"); @lines=; foreach $line (@lines) { $line =~ s/۱/1/g;$line =~ s/۲/2/g;$line =~ s/۳/3/g;$line =~ s/۴/4/g;$line =~ s/۵/5/g; $line =~ s/۶/6/g;$line =~ s/۷/7/g;$line =~ s/۸/8/g;$line =~ s/۹/9/g;$line =~ s/۰/0/g; $line =~ /title=\"(.*?)\"\>(..):(..)، (.+) (.*?) (....)\line($marginleft, $hx, $width ,$hx,$black); #x scale $im->line($marginleft, $hx, $marginleft, $margintop, $black); # y scale for ($i=0; $i<=$mostEdits; $i+=$mostEdits/10) { $im->line($marginleft-2, int($hx-$i*$scale), $marginleft, int($hx-$i*$scale), $black); # y scale $im->string(gdTinyFont,$marginleft-20, int($hx-$i*$scale)-4, int($i), $gray); } $i =1; foreach $date (@dateList) { $edits = $data{$date}; $im->line($marginleft+$i, $hx-1 ,$marginleft+$i, int($hx-$edits*$scale)-1, $blue); if (!($i % 14)) { # we have to print the date $im->stringUp(gdTinyFont,$marginleft+$i-2, $height-$marginbot, $date, $gray); } $i++; } binmode STDOUT; print $im->png;