#! /usr/bin/perl # "$code" is the name of the files that ez-gimpy will output. On a single # run, it will output two files: $code.jpg and $code ($code.jpg is the # the image and $code is the word (in text format) displayed in the image) # At the moment, $code equals a random number between 0 and 1. #$code=rand%100; $fname = $ARGV[0]; # The following variables should be set to the FULL PATHS of the files: # "whitesmall.tif", "dictionary", and "fonts". Full paths are needed # because The Gimp is very dumb in opening files with only relative paths. # Also, the full paths of the output files are set here too. $whitesmall_full_path="/usr/local/ez-gimpy/whitesmall.tif"; $dictionary_full_path="/usr/local/ez-gimpy/dictionary"; $font_file_full_path="/usr/local/ez-gimpy/fonts"; $output_image_full_path="/usr/local/share/apache2/htdocs/opan/$fname.jpg"; # this line opens the dictionary. open(SOURCE, $dictionary_full_path); #This randomizes over the dictionary (picking which word to draw) $wordnumber=rand(561); for($i=0;$i<$wordnumber;$i++) { $tmp=; } $word=$tmp; $wordlength=length($word); chop($word); # Following is the main section. use Gimp; use Gimp::Fu; register "gimpy", "Tunes Gimpy", "EZ-GIMPY", "Luis von Ahn", "biglou\@cs.cmu.edu", "0.0", "/Xtns/Script-Fu/Patterns/ptt_text", "", [], sub { # This opens the Linux random number generator open(RANDOM, "/dev/urandom"); # This opens the fonts file (the one containing which fonts to # use). open(FONTS, $font_file_full_path); # The following picks the dimensions, position, and font of the # word. $size=280+rand(63); $hori=rand(290-$wordlength*$size/11); if($hori<5) { $hori=5; } $vert=10+rand(10); $fontnum=rand(15); for($i=0;$i<$fontnum;$i++) { $family=; $foundry=; $space=; } chop($family); chop($foundry); # The distortions are: # Blends (creates a colorful background) # Noise (adds fine "salt and pepper" type noise) # Waves (makes the image wavey) # Whirl (adds whirl to the image) # Pinch (pinchs the image) # Whitegrid (Adds a white grid) # Grid (Adds a black grid) # Spread (Applies the spread distortion) # Garbage (adds thick "salt and pepper" type noise) # # The variables corresponding to each transformation are set to 0 # if the transformation is not to occur. The transformation occurs # only when its corresponding variable is set to 1. Initially all # of these variables are set to 0. $blends=0; $noise=0; $waves=0; $whirl=0; $pinch=0; $whitegrid=0; $grid=0; $spread=0; $garbage=0; # In the following code, we pick (randomly) which variables are # set to 1 (that is, we pick which transformaitons to apply). $randy=; $randynum=unpack("L",$randy); if($randynum%2==0) { $blends=1; } $randy=; $randynum=unpack("L",$randy); if($randynum%7==0) { $noise=1; } if($randynum%7==1) { $waves=1; } if($randynum%7==2) { $whirl=1; } if($randynum%7==3) { $whitegrid=1; } if($randynum%7==4) { $grid=1; } if($randynum%7==5) { $spread=1; } if($randynum%7==6) { $garbage=1; } # Uncomment the following and set the necessary variables to 1 if # you want to use only a specific set of transformations. #$blends=0; #$noise=0; #$waves=0; #$whirl=0; #$pinch=0; $whitegrid=0; #Has a BUG, crash in every call of whitegrid's #Gimp->plug_in_grid function(found by mk@pvl.at) #$grid=0; #$spread=0; #$garbage=0; # This line loads the file "whitesmall.tif", which contains the # white background on which everything will be drawn. my $image=Gimp->file_tiff_load($whitesmall_full_path, $whitesmall_full_path); my $layer=Gimp->gimp_image_get_active_layer($image); # Code for Blends if($blends==1) { Gimp->perl_fu_random_blends($image, $layer, 1); my $layer=Gimp->gimp_image_flatten($image); Gimp->gimp_brightness_contrast($layer, 120, 80); } # This line actually draws the text. my $layer = Gimp->gimp_text($image, -1, $hori, $vert, $word, -1, 1, $size, 1, $foundry, $family, "medium", "r", "normal", "*", "*", "*"); my $layer=Gimp->gimp_image_flatten($image); $randy=; $randynum=unpack("L",$randy); # Code for Waves if($waves==1) { my $wav=20+rand(25); Gimp->plug_in_waves($image,$layer,$wav/14.0,rand(360),$wav,0,0); } # Code for Garbage if($garbage==1) { Gimp->plug_in_noisify($image,$layer,0, 0.6+rand(0.15), 0.6+rand(0.15), 0.6+rand(0.15), 0.6+rand(0.15)); Gimp->plug_in_gauss_iir($image, $layer, 5, 5, 5); Gimp->plug_in_sharpen($image, $layer, 99); } # Code for Noise if($noise==1) { Gimp->plug_in_noisify($image,$layer,0, 0.6+rand(0.15), 0.6+rand(0.15), 0.6+rand(0.15), 0.6+rand(0.15)); } # Code for Noise if($spread==1) { Gimp->plug_in_spread($image,$layer,3,3); } # Code for Whirl if($whirl==1) { Gimp->plug_in_whirl_pinch($image,$layer,20+rand(30),0,rand(0.6)+0.4); } # Code for grid #$grid=1; if($grid==1) { my $color=Gimp->gimp_palette_get_foreground(); $randy=; $randynum1=unpack("L",$randy); $randy=; $randynum2=unpack("L",$randy); $randy=; $randynum3=unpack("L",$randy); $randy=; $randynum4=unpack("L",$randy); $randy=; $randynum5=unpack("L",$randy); $randy=; $randynum6=unpack("L",$randy); $randy=; $randynum7=unpack("L",$randy); $randy=; $randynum8=unpack("L",$randy); $randy=; $randynum9=unpack("L",$randy); Gimp->plug_in_grid($image,$layer, 1,10+$randynum2%7,$randynum3%4,$color,255, 1,10+$randynum5%7,$randynum6%4,$color,255, 1,10+$randynum8%7,$randynum9%4,$color,255); } # Code for Whitegrid if($whitegrid==1) { $message = $message . " Whitegrid"; warn "Whitegrid1: $message"; my $color=Gimp->gimp_palette_get_background(); warn "Whitegrid2:"; $randy=; $randynum1=unpack("L",$randy); $randy=; $randynum2=unpack("L",$randy); $randy=; $randynum3=unpack("L",$randy); $randy=; $randynum4=unpack("L",$randy); $randy=; $randynum5=unpack("L",$randy); $randy=; $randynum6=unpack("L",$randy); $randy=; $randynum7=unpack("L",$randy); $randy=; $randynum8=unpack("L",$randy); $randy=; $randynum9=unpack("L",$randy); Gimp->plug_in_grid($image,$layer, 1,15+($randynum2) % 7,($randynum3) % 4,$color,255, 2,9+($randynum5) % 7,($randynum6) % 4,$color,255, 1,10+($randynum8) % 7,($randynum9) % 4,$color,255); } #warn "$message"; #`echo $message > $output_text_full_path`; # The following are the finishing touches to the image. $randy=; $randynum=unpack("L",$randy); my $randopacity=$randynum%23; Gimp->gimp_layer_set_opacity($layer, 60+$randopacity); my $layer=Gimp->gimp_image_flatten($image); Gimp->plug_in_c_astretch($image,$layer); #`echo $output_image_full_path > "/usr/local/share/g/filename"`; print { STDOUT } "$word"; #warn "$message"; #`echo $message > $output_text_full_path`; # The following two commands save the file (with name $code). Gimp->file_jpeg_save($image, $layer, $output_image_full_path, $output_image_full_path, 1, 0, 0, 0, "comment", 0, 0, 0, 0); close(SOURCE); close(RANDOM); close(FONTS); return(); }; exit main;