Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Tk show image from web (inspired app)

by Anonymous Monk
on Nov 17, 2019 at 23:21 UTC ( [id://11108841]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Tk show image from web
in thread Tk show image from web

Maybe somebody can find some inspiration

Very cool, thank you!

#!/usr/bin/perl =head1 DESCRIPTION View random images from the supplied folder (supports . and ~). Every time you close an image a new random image will open, until the program is stopped. Inspired by "Re^2: Tk show image from web" by IB2017 https://www.perlmonks.org/index.pl?node_id=11108799 =cut use strict; use warnings; use autodie; use File::Spec; use MIME::Base64; use Tk; use Tk::Photo; use Tk::JPEG; use Tk::PNG; my $dir = shift || die "Usage: $0 /path/to/images"; die 'Folder not found :-(' unless -d $dir; opendir my $dh, glob $dir; my @img = grep /\.(jpe?g|gif|png|bmp)/i, readdir $dh; closedir $dh; die 'No images found, try again!' unless @img; while () { my $img = $img[rand@img]; my $path = File::Spec->catfile($dir,$img); open my $fh, '<', $path; my $dat = join '', <$fh>; close $fh; $dat = MIME::Base64::encode_base64($dat); print "$path \n"; my $mw = MainWindow->new; my $top = $mw->Frame()->pack(); my $image = $mw->Photo(-data => $dat); my $label = $top->Label(-image => $image)->pack(); MainLoop }

Replies are listed 'Best First'.
Re^4: Tk show image from web (inspired app)
by Anonymous Monk on Dec 17, 2019 at 14:00 UTC
    Dear Monks,

    I like to use this program to surf images in my huge downloads folder, but it has 2 problems:

    The first issue is that memory use grows with each image since it doesn't call the delete method on the $image (as Tk::Image says) but I can't figure out where to call this method without causing a segmentation fault.

    The second issue is that Tk::JPEG fails with "Unsupported JPEG color space" on CMYK images. Do I have to use Image::Info to detect CMYK and Imager to convert to RGB or is there a simpler way?

    Thank you

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-03-28 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found