davies has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use Tk; use Tk::JPEG; use GD; my $file = $ARGV[0]; my $mw = MainWindow->new(); my $ww = $mw->screenwidth; my $wh = $mw->screenheight; my $imgd = GD::Image->newFromJpeg($file); my ($iw, $ih) = $imgd->getBounds(); my $imtk; if ($iw > $ww or $ih > $wh) { my $wratio = $ww / $iw; my $ratio = $wh / $ih; $ratio = $wratio if $wratio < $ratio; $imgd->copyResampled($imgd, 0, 0, 0, 0, $iw * $ratio, $ih * $ratio +, $iw, $ih); $imtk = $mw->Photo(-data => $imgd->jpeg(), -format => 'jpeg'); } else { $imtk = $mw->Photo(-file => $file, -format => 'jpeg'); } $mw->Label(-image => $imtk)->pack(-expand => 1, -fill => 'both'); $mw->update; MainLoop;
This code works when used on a file smaller than the screen. On a larger file, it fails with the error
couldn't recognize image data at C:/Strawberry/perl/site/lib/Tk/Image. +pm line 21.
Note that this is a reference to the Tk::Image module, not my code. Putting in print statements identifies the failing line as line 20 of my code, i.e. the line before the } else {. I cannot find anything in the Tk or GD docs to indicate what I'm doing wrong.
Regards,
John Davies
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk not recognising GD image
by Discipulus (Canon) on May 07, 2022 at 21:00 UTC | |
by davies (Monsignor) on May 07, 2022 at 21:31 UTC | |
by syphilis (Archbishop) on May 08, 2022 at 01:17 UTC | |
by Discipulus (Canon) on May 09, 2022 at 08:52 UTC | |
by davies (Monsignor) on May 09, 2022 at 09:09 UTC | |
|