this is my code, its suppose to be a viewer/manipulator.
im havent started w/ the manipulation part.
to try this..
copy these codes:
#!/usr/bin/perl -w
use Tk;
use Tk::Canvas;
use Tk::Label;
use Image::Magick;
sub load_thumb;
sub load_image;
sub thumb_select;
sub go_select_thumb;
# LOAD THUMB VARIABLES #
my $x;
my ( $thumb_x, $thumb_y );
my $thumb_height;
my $thumb_width;
my $thumb_blob;
my $thumb_photo;
my $canvas_region;
my $IM;
my $thumb_selected;
my @thumb_filename;
# LOAD THUMB VARIABLES #
my $mw = Tk::MainWindow->new();
$mw->geometry("1024x700+0+0");
my $filepath = "pictures/*";
my $canvas00 = $mw->Canvas(-width=>100,-height=>600,-background=>"whit
+e");
$canvas00->place(-x=>5,-y=>5);
$canvas00->bind('current','<1>',\&go_select_thumb);
my $button00 = $mw->Button(-text=>"REFRESH",-command=>\&load_thumbs);
$button00->place(-x=>5,-y=>610);
my $canvas01 = $mw->Canvas(-width=>800,-height=>600,-background=>"whit
+e");
$canvas01->place(-x=>110,-y=>5);
# LOAD IMAGE VARIABLES #
my $OI;
# LOAD IMAGE VARIABLES #
Tk::MainLoop();
sub load_thumbs {
$IM = Image::Magick->new();
$IM->Read($filepath);
$canvas_region = "0 0 100 " . ($#{$IM}+1) * 100;
$canvas00->configure(-scrollregion=>$canvas_region);
$canvas00->delete('all');
for($x=0;$x <= $#{$IM};$x++){
#Proportional Resizing
( $thumb_x, $thumb_y ) = $IM->[$x]->Get('width','height');
$thumb_filename[$x] = $IM->[$x]->Get('filename');
$thumb_height = 90;
$thumb_width = $thumb_height * $thumb_x / $thumb_y;
$IM->[$x]->Thumbnail(height=>$thumb_height,width=>$thumb_width
+);
$thumb_blob = $IM->[$x]->ImageToBlob(magick=>'xpm');
$thumb_photo = $canvas00->Photo(-data=>$thumb_blob);
$canvas00->createImage(50,($x * 100)+45,-image=>$thumb_photo,-
+tags=>"thumb" . $x);
}
#remove from memory
undef $x; undef $thumb_x; undef $thumb_y; undef $thumb_height; und
+ef $thumb_width; undef $canvas_region;
}
sub thumb_select {
my @sel = $canvas00->gettags('current');
print $sel[0] . "\n";
my $index = int(substr($sel[0],5,length($sel[0])-5));
$thumb_selected = $thumb_filename[$index];
print $thumb_selected;
}
sub load_image {
$canvas01->delete("originalphoto");
$OI = Image::Magick->new();
$OI->Read($thumb_selected);
my $TOI = $OI;
$TOI->Thumbnail(height=>$TOI->Get('height')*.4,width=>$TOI->Get('w
+idth')*.4);
my $TOI_blob = $TOI->ImageToBlob(magick=>'xpm');
my $TOI_photo = $canvas01->Photo(-data=>$TOI_blob,-format=>'xpm');
undef $TOI_blob;
$canvas01->createImage($canvas01->cget('width')/2,$canvas01->cget(
+'height')/2,-image=>$TOI_photo,-tags=>"originalphoto");
print "load_image\n";
}
sub go_select_thumb {
thumb_select;
load_image;
}
create a folder named "pictures" place some 2000x2000 pics there. start the program.. click the refresh button. click on a picture. you will see that my code loads the picture, but it takes a lot of time hehe..
|