in reply to Re^2: Tk:Photo -data with binary data?
in thread Tk:Photo -data with binary data?

Dunno, the following example should work but it doesn't. It seems that some formats can't read data from strings, for whatever reasons. This is somewhat hinted in the docs:

data => string
Specifies the contents of the image as a string. The string can contain base64 encoded data or binary data. The format of the string must be one of those for which there is an image file format handler that will accept string data. If both the -data and -file options are specified, the -file option takes precedence.
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Photo; use Tk::PNG; my $fdata = pack 'H*', join '', map {chomp;$_} <DATA>; my $mw = new MainWindow(); $mw->Label(-image => $mw->Photo(-format => 'png', -data => $fdata))->p +ack; MainLoop; __DATA__ 89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000 000473424954080808087c0864880000031149444154388d5d934b685c6518869fff9c b9672699c4244c27186348a6dad462e9c6120af5428ba274a1502b144a45501071ab2e 155d195ce842d4950bc18d2e24daaad5452b4a3596c4b69a26c44e636e93c964a69999 73ce7ff95cc496c667f52ebef785efa6b88391936799fbf408c327bece88b5bb9c369d 36d4b848d79cb1ab2b3f9e6cf33fd42d513a7d0e7192146bc7ad754f86b1cc01a36205 17196836ca5e6d63c606c1e71877b1fafb8b764740e9f97388901291d75c22737a78cf 60f1c8de9cb7a7dfc747b8bcacf961aa2217cffc36afab1befdb407fd4987db505a046 4f7d87f2bdac08efe4ef2ebe7cfcd17b38ba3b45dc87283224123ea0700267671a7cfc e179ca53b36f99adf69bade5d7230f4f7962dd31c9e64f1c7b7898bdc524cb5bc2b595 90563324080c4b75433d84fb073b79eed438b942ef0bce98c7003cb1aea0bdf8332363 433ddd1d71166ac2f5d536439d96fd436976f7f9ec2f28c6fa84f99a90e9e9a274f460 9f75f26cace38d6c4c8cbd5765b3877abbd3aa5cb30c77043c7e5f9c819ec4ed49a712 a0adb0d1b44c2e785ca3df733dfd07a4fcf788e7b4c978e9f45d952881d2214fef4b52 ec8edf368b0800314ff144c92712a89804b650ec126db231ab0d8186b94d8525cdf4ba e250069a214caf81b68e870a8e6432cee5aaa2d252dbcbf36288133cd1c64537db6669 d3706151f1cd3c680b5b11fcba04d34b42181aacc057b370bd0668039bb508d09ed366 9dc6e6acde0a080221d2020802e0605bfcd78e0565049a81b078e306b016b391998bad 2e4ee672bda3aab42fbe50b55c287b8416ca0d505631b5e2c106fc59817cdcd29cfa29 8aaa956f81b202e83bf8c998f8c9cf3ac60f3f901e18209f024f413ddc3ed57c0a222b d4db42fdd28c54bef8f2175b6f1c8789b20f90293eb56e5bed69b3f4cf239938d9743e e7c51331b20945260e38836bb5d83cffb3ae9cf9fe0f536fbc84bc7b75c7337595dec3 19fb20c82bf9c181c35d83c5a154ae433963a455addb8db97279edd2d549e003e02f98 901d01b7c8ec7abbc7467ad4467accf7fda26907ce867a71dbc41598b87967fdbffa74 99fc896501e90000000049454e44ae426082

It dies with the error:

couldn't recognize image data at /usr/lib/perl5/Tk/Image.pm line 21, < +DATA> line 25.

If I dump $fdata to a file and then use -file => ..., it works.

Replies are listed 'Best First'.
Re^4: Tk:Photo -data with binary data?
by BrowserUk (Patriarch) on Nov 28, 2006 at 23:42 UTC

    Yes. That's the same results I am getting. See Re^4: Tk:Photo -data with binary data?.

    It seems strange that there would have to be special handling for binary data from a string, when it can handle that same binary data froma file. It should only need to detect the presence of non-base64 characters in the data supplied?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.