ardixon
6/19/2013 - 10:21 PM

PPM_Maker converts any image into PPM P3 Ascii format.

PPM_Maker converts any image into PPM P3 Ascii format.

# created by Austin Dixon 4/12/2013
#
# must have ImageMagick installed on computer before running script
# script converts images to PPM P3 ACSII format and resizes to 60X60 pixels 
 
#! usr/local/bin/perl
use Tkx;
use LWP::Simple;
 
# SETUP
													
# frame objects
my $fa;
my $fc;
# label objects
my $la;
my $lc;
# button objects
my $ba;
my $bc;
 
 
#-------------------------------------------------
# Convert
sub convert {
 
system("convert $url -resize 60x60 file.ppm");
system("convert file.ppm -compress none file.ppm");
 
}
 
#-------------------------------------------------
 
# GUI elements
# main window
my $mw = Tkx::widget->new(".");
$mw->g_wm_title("PPM Maker");
$mw->g_wm_minsize(350, 130);
 
# frame a
$fa = $mw->new_frame(
-relief => 'solid',
-borderwidth => 1,
-background => 'light gray',
);
$fa->g_pack( -side => 'top', -fill => 'both' );
 
$la = $fa->new_label(
-text => 'Choose File to Convert: ',
-bg => 'light gray',
-foreground => 'black',
);
$la->g_pack( -side => 'top', -fill => 'both' );
 
$lb = $fa->new_label(
-bg => 'blue',
-foreground => 'cyan',
-width => 24,
-textvariable => \$url,
);
$lb->g_pack( -side => 'top' );
 
$ba = $fa->new_button(
-text => 'Choose',
-command => sub { $url = Tkx::tk___getOpenFile();},
-height => 1,
-width => 15,
);
$ba->g_pack( -side => 'top', -pady => 5 );
 
 
# frame c
$fc = $mw->new_frame(
-relief => 'solid',
-borderwidth => 1,
-background => 'light gray',
);
$fc->g_pack( -side => 'top', -fill => 'both' );
 
$bc = $fc->new_button(
-text => 'CONVERT!',
-command => \&convert,
-height => 2,
-width => 15,
);
$bc->g_pack( -side => 'bottom', -pady => 10 );
 
 
Tkx::MainLoop();
This script converts any image into PPM P3 Ascii format.
It also resizes the image to 60 by 60 pixels. 
ImageMagick must be installed before running this script. 
(I use this for making images that I can then plug into another script for making Ascii art.)