| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
use FindBin; |
| 5 |
use File::Temp qw(tempfile); |
| 6 |
use Test::More; |
| 7 |
|
| 8 |
use Tk; |
| 9 |
use Tk::Photo; |
| 10 |
|
| 11 |
my @writeopt = ([],[-grayscale],[-progressive],[-quality => 13],[-smooth => 12]); |
| 12 |
|
| 13 |
my $mw = eval { Tk::MainWindow->new() }; |
| 14 |
if (!Tk::Exists($mw)) { |
| 15 |
plan skip_all => "Cannot create MainWindow: $@"; |
| 16 |
CORE::exit(0); |
| 17 |
} |
| 18 |
|
| 19 |
plan tests => 7*@writeopt+6; |
| 20 |
|
| 21 |
eval { require Tk::JPEG }; |
| 22 |
is $@, '', "loading Tk::JPEG"; |
| 23 |
|
| 24 |
my $file = (@ARGV) ? shift : "$FindBin::RealBin/../jpeg/testimg.jpg"; |
| 25 |
|
| 26 |
$mw->geometry('+10+10'); |
| 27 |
|
| 28 |
my $image = eval { $mw->Photo('-format' => 'jpeg', -file => $file) }; |
| 29 |
is $@, '', "loading jpeg photo from file"; |
| 30 |
is $image->width, 227, "width check"; |
| 31 |
is $image->height, 149, "height height"; |
| 32 |
my $l = $mw->Label(-image => $image, -bd => 0, -padx => 0, -pady => 0)->pack; |
| 33 |
$mw->update; |
| 34 |
is $l->width, 227, "width check of label"; |
| 35 |
is $l->height, 149, "height check of label"; |
| 36 |
|
| 37 |
my $image2; |
| 38 |
|
| 39 |
foreach my $opt (@writeopt) |
| 40 |
{ |
| 41 |
my($tmpfh,$tmpfile) = tempfile(SUFFIX => '.jpg', UNLINK => 1) |
| 42 |
or die "Can't create temporary file: $!"; |
| 43 |
eval { $image->write($tmpfile, -format => ['jpeg',@$opt]) }; |
| 44 |
is $@, '', 'writing jpeg'; |
| 45 |
my $ok = (-s $tmpfile) ? 1 : 0; |
| 46 |
ok $ok, "File has non-zero size"; |
| 47 |
|
| 48 |
eval {$image2 = $mw->Photo('-format' => 'jpeg', -file => $tmpfile)}; |
| 49 |
is $@, '', "loading jpeg"; |
| 50 |
is $image2->width, 227, "expected width"; |
| 51 |
is $image2->height, 149, "expected height"; |
| 52 |
|
| 53 |
$l->configure(-image => $image2); |
| 54 |
$mw->update; |
| 55 |
is $l->width, 227, "expected label width"; |
| 56 |
is $l->height, 149, "expected label height"; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
$mw->after(500,[destroy => $mw]); |
| 61 |
MainLoop; |